PHP code example of armezit / lunarphp-purchase-limit
1. Go to this page and download the library: Download armezit/lunarphp-purchase-limit 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/ */
armezit / lunarphp-purchase-limit example snippets
use Lunar\Facades\CartSession;
use Lunar\Exceptions\Carts\CartException;
use Armezit\Lunar\PurchaseLimit\Exceptions\PurchaseLimitException;
use Armezit\Lunar\PurchaseLimit\Exceptions\CustomerQuantityLimitException;
try {
$order = CartSession::current()
->getManager()
->createOrder();
// catch any CartException
} catch (CartException $e) {
...
// catch any kind of purchase limit violation
} catch (PurchaseLimitException $e) {
...
// catch specific kind of purchase limit violation
} catch (CustomerQuantityLimitException $e) {
// customer quantity limit exceeded
}
return [
/*
* List of rules to check during CartModifier::calculated() hook
*/
'cart_rules' => [
ProductLimit::class,
CustomerLimit::class,
CustomerProductLimit::class,
],
/*
* List of rules to check during CartLineModifier::calculated() hook
*/
'cart_line_rules' => [
ProductVariantLimit::class,
CustomerProductVariantLimit::class,
],
/*
* Automatically register purchase-limit`s cart/cart-line modifiers during PurchaseLimitServiceProvider boot
* Set it to false, if you want to manually register cart/cart-line modifiers
*/
'register_cart_modifiers' => true,
/*
* Automatically register purchase-limit admin hub slots
* Set it to false, if you want to manually register them
*/
'register_hub_slots' => true,
/*
* The name (handle) of hub slot which you want to display product purchase limit component
*/
'product_purchase_limit_slot' => 'product.all',
'database' => [
'purchase_limits_table' => 'purchase_limits',
],
];