Add InPost Pay integration to admin templates
- Created a new template for the cart rule form with custom label, switch, and choice widgets. - Implemented the InPost Pay block in the order details template for displaying delivery method, APM, and VAT invoice request. - Added legacy support for the order details template to maintain compatibility with older PrestaShop versions.
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace izi\prestashop\Cart\Exception;
|
||||
|
||||
final class ProductAlreadyInCartException extends \RuntimeException
|
||||
{
|
||||
/**
|
||||
* @var array cart product
|
||||
*/
|
||||
private $product;
|
||||
|
||||
public function __construct(array $product, string $message = '', int $code = 0, \Throwable $previous = null)
|
||||
{
|
||||
parent::__construct($message, $code, $previous);
|
||||
$this->product = $product;
|
||||
}
|
||||
|
||||
public function getProduct(): array
|
||||
{
|
||||
return $this->product;
|
||||
}
|
||||
}
|
||||
40
modules/inpostizi/src/Cart/Util/ProductHelper.php
Normal file
40
modules/inpostizi/src/Cart/Util/ProductHelper.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace izi\prestashop\Cart\Util;
|
||||
|
||||
final class ProductHelper
|
||||
{
|
||||
public static function findProductInCart(\Cart $cart, int $productId, int $combinationId, int $customizationId = 0): ?array
|
||||
{
|
||||
foreach ($cart->getProducts() as $product) {
|
||||
if (self::isSameProduct($product, $productId, $combinationId, $customizationId)) {
|
||||
return $product;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function isInCart(\Cart $cart, int $productId, int $combinationId, int $customizationId = 0): bool
|
||||
{
|
||||
return null !== self::findProductInCart($cart, $productId, $combinationId, $customizationId);
|
||||
}
|
||||
|
||||
public static function getCartQuantity(\Cart $cart, int $productId, int $combinationId, int $customizationId = 0): int
|
||||
{
|
||||
if (null === $product = self::findProductInCart($cart, $productId, $combinationId, $customizationId)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (int) $product['cart_quantity'];
|
||||
}
|
||||
|
||||
private static function isSameProduct(array $cartProduct, int $productId, int $combinationId, int $customizationId): bool
|
||||
{
|
||||
return $productId === (int) $cartProduct['id_product']
|
||||
&& $combinationId === (int) $cartProduct['id_product_attribute']
|
||||
&& $customizationId === (int) $cartProduct['id_customization'];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user