123 lines
4.6 KiB
PHP
123 lines
4.6 KiB
PHP
<?php
|
|
/**
|
|
* 2022 ECSoft
|
|
*
|
|
* NOTICE OF LICENSE
|
|
*
|
|
* This source file is subject to the Academic Free License (AFL 3.0)
|
|
* that is bundled with this package in the file LICENSE.txt.
|
|
* It is also available through the world-wide-web at this URL:
|
|
* http://opensource.org/licenses/afl-3.0.php
|
|
* If you did not receive a copy of the license and are unable to
|
|
* obtain it through the world-wide-web, please send an email
|
|
* to dev.ecsoft@gmail.com so we can send you a copy immediately.
|
|
*
|
|
* @author ECSoft <dev.ecsoft@gmail.com>
|
|
* @copyright 2022 ECSoft
|
|
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
|
* International Registered Trademark & Property of ECSoft
|
|
*/
|
|
|
|
class EcsGtmProDataLayerProduct
|
|
{
|
|
public $name;
|
|
public $id;
|
|
public $reference;
|
|
public $price;
|
|
public $price_tax_exc;
|
|
public $brand;
|
|
public $category;
|
|
public $item_category;
|
|
public $item_category2;
|
|
public $item_category3;
|
|
public $item_category4;
|
|
public $variant;
|
|
public $list;
|
|
public $position;
|
|
public $quantity;
|
|
|
|
public function __construct($module, $product, $list = null)
|
|
{
|
|
$product = $product instanceof Product ? $product : (object)$product;
|
|
$variant = null;
|
|
|
|
if (empty($product->id)) {
|
|
$product->id = !empty($product->id_product) ? $product->id_product : 0;
|
|
if (!$product->id) {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
$id_product_attribute = !empty($product->id_product_attribute) ? $product->id_product_attribute : EcsGtmProTools::getProductAttributeId($product);
|
|
if ($id_product_attribute) {
|
|
$variant = new Combination($id_product_attribute);
|
|
if (!Validate::isLoadedObject($variant)) {
|
|
$variant = null;
|
|
$id_product_attribute = 0;
|
|
}
|
|
}
|
|
|
|
$this->id = (string) EcsGtmProProduct::getInstance()->getProductId($product, $variant);
|
|
|
|
|
|
if (!empty($variant->reference)) {
|
|
$this->reference = (string) $variant->reference;
|
|
} else {
|
|
$this->reference = (string) $product->reference;
|
|
}
|
|
|
|
$this->name = EcsGtmProProduct::getInstance()->getProductName($product);
|
|
$this->link = EcsGtmProProduct::getInstance()->getProductName($product, "link_rewrite");
|
|
|
|
if ($id_product_attribute) {
|
|
$this->variant = EcsGtmProTools::cleanString(EcsGtmProTools::getAttributeShortName($id_product_attribute, $module->dlManager->getDataLanguage()));
|
|
}
|
|
|
|
$this->price = (string) round((float) Product::getPriceStatic($product->id, true, $id_product_attribute), _ECSGTMPRO_PRICE_DECIMAL_);
|
|
$this->price_tax_exc = (string) round((float) Product::getPriceStatic($product->id, false, $id_product_attribute), _ECSGTMPRO_PRICE_DECIMAL_);
|
|
|
|
if ($module->gtmConfig->dataConfig->wholesale_price) {
|
|
$wholesale_price = $product->wholesale_price;
|
|
if ($variant && $variant->wholesale_price > 0) {
|
|
$wholesale_price = $variant->wholesale_price;
|
|
}
|
|
$this->wholesale_price = (string)round((float)$wholesale_price, _ECSGTMPRO_PRICE_DECIMAL_);
|
|
}
|
|
|
|
$this->list = !empty($list['name']) ? $list['name'] : null;
|
|
$this->position = !empty($list['index']) ? $list['index'] : null;
|
|
|
|
if (!empty($list['name'])) {
|
|
$this->category = $list['name'];
|
|
} else {
|
|
$this->category = $module->dlManager->getCategoryName($product->id_category_default);
|
|
}
|
|
|
|
$category = new Category($product->id_category_default);
|
|
$this->item_category = $module->dlManager->getCategoryNameHierarchy($category, 1);
|
|
$this->item_category2 = $module->dlManager->getCategoryNameHierarchy($category, 2);
|
|
$this->item_category3 = $module->dlManager->getCategoryNameHierarchy($category, 3);
|
|
$this->item_category4 = $module->dlManager->getCategoryNameHierarchy($category, 4);
|
|
|
|
if ($product->id_manufacturer) {
|
|
$manufacturer_name = EcsGtmProTools::cleanString(Manufacturer::getNameById((int)$product->id_manufacturer));
|
|
$this->brand = $manufacturer_name;
|
|
}
|
|
|
|
if (!empty($product->product_quantity)) {
|
|
$this->quantity = (int) $product->product_quantity;
|
|
} elseif (!empty($product->cart_quantity)) {
|
|
$this->quantity = (int) $product->cart_quantity;
|
|
} elseif (!empty($product->quantity)) {
|
|
$this->quantity = (int) $product->quantity;
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function removeNull()
|
|
{
|
|
EcsGtmProTools::removeNull($this);
|
|
}
|
|
}
|