diff --git a/src/Hook/Hooks.php b/src/Hook/Hooks.php index 35dcb84..916e6c2 100644 --- a/src/Hook/Hooks.php +++ b/src/Hook/Hooks.php @@ -18,4 +18,9 @@ class Hooks /** @var string */ public const TC_DISPLAY_BEFORE_GTM_HEAD_SNIPPET = 'tcDisplayBeforeGtmHeadSnippet'; + + /** + * @var string + */ + public const TC_DISPLAY_AFTER_FRONTEND_ASSETS = 'tcDisplayAfterFrontendAssets'; } diff --git a/src/Model/Product.php b/src/Model/Product.php index 517eee6..0261554 100644 --- a/src/Model/Product.php +++ b/src/Model/Product.php @@ -28,6 +28,9 @@ class Product /** @var string */ private $variant; + /** @var int */ + private $variantId; + /** @var int */ private $minimalQuantity; @@ -156,6 +159,18 @@ public function setMinimalQuantity(int $minimalQuantity): self return $this; } + public function getVariantId(): int + { + return $this->variantId; + } + + public function setVariantId(int $variantId): self + { + $this->variantId = $variantId; + + return $this; + } + public function toArray(): array { return [ @@ -165,6 +180,7 @@ public function toArray(): array 'brand' => $this->getBrand(), 'category' => $this->getCategory(), 'variant' => $this->getVariant(), + 'variant_id' => $this->getVariantId(), 'stock_quantity' => $this->getStockQuantity(), 'minimal_quantity' => $this->getMinimalQuantity(), ]; @@ -188,6 +204,10 @@ public static function fromArray($array): self $array['attributes'] = ''; } + if (false === isset($array['id_product_attribute']) || false === is_int($array['id_product_attribute'])) { + $array['id_product_attribute'] = 0; + } + if (true === \is_array($array['attributes'])) { $attributes = array_map(static function ($attribute) { return Tools::strtolower(trim( @@ -211,6 +231,7 @@ public static function fromArray($array): self ->setBrand($manufacturer->name ?? '') ->setCategory($category->name ?? '') ->setVariant($variant) + ->setVariantId($array['id_product_attribute']) ->setStockQuantity($array['quantity']) ->setMinimalQuantity($array['minimal_quantity']); } diff --git a/views/templates/hooks/add_to_cart/display_before_body_closing_tag.tpl b/views/templates/hooks/add_to_cart/display_before_body_closing_tag.tpl index 2a62fea..02bcbcb 100644 --- a/views/templates/hooks/add_to_cart/display_before_body_closing_tag.tpl +++ b/views/templates/hooks/add_to_cart/display_before_body_closing_tag.tpl @@ -15,6 +15,7 @@ brand: product['manufacturer_name'], category: product['category'], variant: attributes.join('___'), + variant_id: product['id_product_attribute'], stock_quantity: parseInt(product['stock_quantity']), minimal_quantity: parseInt(product['minimal_quantity']), cart_quantity: parseInt(product['cart_quantity']), diff --git a/views/templates/hooks/frontend_assets/display_header.tpl b/views/templates/hooks/frontend_assets/display_header.tpl index bc204c8..f56ae86 100644 --- a/views/templates/hooks/frontend_assets/display_header.tpl +++ b/views/templates/hooks/frontend_assets/display_header.tpl @@ -1,3 +1,4 @@ +{literal} +{/literal} +{hook h='tcDisplayAfterFrontendAssets'} \ No newline at end of file