PHP code example of justbetter / laravel-magento-prices

1. Go to this page and download the library: Download justbetter/laravel-magento-prices library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

justbetter / laravel-magento-prices example snippets




    protected function schedule(Schedule $schedule): void
    {
        $schedule->command(\JustBetter\MagentoPrices\Commands\ProcessPricesCommand::class)->everyMinute();

        $schedule->command(\JustBetter\MagentoPrices\Commands\Retrieval\RetrieveAllPricesCommand::class)->daily();
        $schedule->command(\JustBetter\MagentoPrices\Commands\Retrieval\RetrieveAllPricesCommand::class, ['from' => 'now -2 hours'])->hourly(); // Retrieve updated
    }





namespace App\Integrations\MagentoPrices;

use JustBetter\MagentoPrices\Data\PriceData;
use JustBetter\MagentoPrices\Repository\Repository;

class MyPriceRepository extends Repository
{
  public function retrieve(string $sku): ?PriceData
    {
        return PriceData::of([
            'sku' => $sku,
            'base_prices' => [
                [
                    'store_id' => 0,
                    'price' => 10,
                ],
                [
                    'store_id' => 2,
                    'price' => 19,
                ],
            ],
            'tier_prices' => [
                [
                    'website_id' => 0,
                    'customer_group' => 'group_1',
                    'price_type' => 'fixed',
                    'quantity' => 1,
                    'price' => 8,
                ],
                [
                    'website_id' => 0,
                    'customer_group' => '4040',
                    'price_type' => 'group_2',
                    'quantity' => 1,
                    'price' => 7,
                ],
            ],
            'special_prices' => [
                [
                    'store_id' => 0,
                    'price' => 5,
                    'price_from' => now()->subWeek()->toDateString(),
                    'price_to' => now()->addWeek()->toDateString(),
                ],
            ],
        ]);
    }
}



namespace App\Integrations\MagentoPrices;

use JustBetter\MagentoPrices\Repositories\Repository;
use Illuminate\Support\Carbon;
use Illuminate\Support\Collection;

class MyPriceRepository extends Repository
{
    public function skus(?Carbon $from = null): ?Collection
    {
        return collect(['sku_1', 'sku_2']);
    }
}

class BaseRepository
{
    // How many prices may be retrieved at once when the process job runs
    protected int $retrieveLimit = 250;

    // How many prices may be updated at once when the process job runs
    protected int $updateLimit = 250;

    // How many times an update to Magento may fail before it stops trying
    protected int $failLimit = 3;
}



return [
    'repository' => \App\Integrations\MagentoPrices\MyPriceRepository::class,
];