1. Go to this page and download the library: Download shopper/pricelist 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/ */
shopper / pricelist example snippets
use Shopper\Facades\Shopper;
use Shopper\PriceList\PriceListAddon;
public function register(): void
{
Shopper::addons([
new PriceListAddon,
]);
}
Shopper::addons([
new CustomerGroupsAddon,
new PriceListAddon,
]);
namespace App\Pricing;
use App\Models\User;
use Shopper\Core\Pricing\PricingContext;
use Shopper\PriceList\Contracts\ApplicabilityRule;
final class B2BCompanyRule implements ApplicabilityRule
{
/** @var array<int, int|null> */
private array $companies = [];
public function key(): string
{
return 'b2b_company';
}
public function label(): string
{
return __('Companies');
}
public function passes(array $values, PricingContext $context): bool
{
if ($context->customerId === null) {
return false;
}
$company = $this->companies[$context->customerId] ??= User::query()
->whereKey($context->customerId)
->value('company_id');
return in_array($company, array_map(intval(...), $values), true);
}
}
Shopper::addons([
(new PriceListAddon)->rules([B2BCompanyRule::class]),
]);