/classes/Product.php
PHP | 5036 lines | 3563 code | 609 blank | 864 comment | 473 complexity | 84d708637d2f5db0d20dceb03059be96 MD5 | raw file
Possible License(s): LGPL-2.1, LGPL-3.0
Large files files are truncated, but you can click here to view the full file
- <?php
- /*
- * 2007-2012 PrestaShop
- *
- * NOTICE OF LICENSE
- *
- * This source file is subject to the Open Software License (OSL 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/osl-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 license@prestashop.com so we can send you a copy immediately.
- *
- * DISCLAIMER
- *
- * Do not edit or add to this file if you wish to upgrade PrestaShop to newer
- * versions in the future. If you wish to customize PrestaShop for your
- * needs please refer to http://www.prestashop.com for more information.
- *
- * @author PrestaShop SA <contact@prestashop.com>
- * @copyright 2007-2012 PrestaShop SA
- * @version Release: $Revision: 7506 $
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
- * International Registered Trademark & Property of PrestaShop SA
- */
- /**
- * @deprecated 1.5.0.1
- */
- define('_CUSTOMIZE_FILE_', 0);
- /**
- * @deprecated 1.5.0.1
- */
- define('_CUSTOMIZE_TEXTFIELD_', 1);
- class ProductCore extends ObjectModel
- {
- /** @var string Tax name */
- public $tax_name;
- /** @var string Tax rate */
- public $tax_rate;
- /** @var integer Manufacturer id */
- public $id_manufacturer;
- /** @var integer Supplier id */
- public $id_supplier;
- /** @var integer default Category id */
- public $id_category_default;
- /** @var integer default Shop id */
- public $id_shop_default;
- /** @var string Manufacturer name */
- public $manufacturer_name;
- /** @var string Supplier name */
- public $supplier_name;
- /** @var string Name */
- public $name;
- /** @var string Long description */
- public $description;
- /** @var string Short description */
- public $description_short;
- /** @var integer Quantity available */
- public $quantity = 0;
- /** @var integer Minimal quantity for add to cart */
- public $minimal_quantity = 1;
- /** @var string available_now */
- public $available_now;
- /** @var string available_later */
- public $available_later;
- /** @var float Price in euros */
- public $price = 0;
- /** @var float Additional shipping cost */
- public $additional_shipping_cost = 0;
- /** @var float Wholesale Price in euros */
- public $wholesale_price = 0;
- /** @var boolean on_sale */
- public $on_sale = false;
- /** @var boolean online_only */
- public $online_only = false;
- /** @var string unity */
- public $unity = null;
- /** @var float price for product's unity */
- public $unit_price;
- /** @var float price for product's unity ratio */
- public $unit_price_ratio = 0;
- /** @var float Ecotax */
- public $ecotax = 0;
- /** @var string Reference */
- public $reference;
- /** @var string Supplier Reference */
- public $supplier_reference;
- /** @var string Location */
- public $location;
- /** @var string Width in default width unit */
- public $width = 0;
- /** @var string Height in default height unit */
- public $height = 0;
- /** @var string Depth in default depth unit */
- public $depth = 0;
- /** @var string Weight in default weight unit */
- public $weight = 0;
- /** @var string Ean-13 barcode */
- public $ean13;
- /** @var string Upc barcode */
- public $upc;
- /** @var string Friendly URL */
- public $link_rewrite;
- /** @var string Meta tag description */
- public $meta_description;
- /** @var string Meta tag keywords */
- public $meta_keywords;
- /** @var string Meta tag title */
- public $meta_title;
- /** @var boolean Product statuts */
- public $quantity_discount = 0;
- /** @var boolean Product customization */
- public $customizable;
- /** @var boolean Product is new */
- public $new = null;
- /** @var integer Number of uploadable files (concerning customizable products) */
- public $uploadable_files;
- /** @var int Number of text fields */
- public $text_fields;
- /** @var boolean Product statuts */
- public $active = true;
- /** @var boolean Product available for order */
- public $available_for_order = true;
- /** @var string Object available order date */
- public $available_date = '0000-00-00';
- /** @var enum Product condition (new, used, refurbished) */
- public $condition;
- /** @var boolean Show price of Product */
- public $show_price = true;
- /** @var boolean is the product indexed in the search index? */
- public $indexed = 0;
- /** @var string ENUM('both', 'catalog', 'search', 'none') front office visibility */
- public $visibility;
- /** @var string Object creation date */
- public $date_add;
- /** @var string Object last modification date */
- public $date_upd;
- /*** @var array Tags */
- public $tags;
- public $id_tax_rules_group = 1;
- /**
- * We keep this variable for retrocompatibility for themes
- * @deprecated 1.5.0
- */
- public $id_color_default = 0;
- /**
- * @since 1.5.0
- * @var boolean Tells if the product uses the advanced stock management
- */
- public $advanced_stock_management = 0;
- public $out_of_stock;
- public $depends_on_stock;
- public $isFullyLoaded = false;
- public $cache_is_pack;
- public $cache_has_attachments;
- public $is_virtual;
- public $cache_default_attribute;
- /**
- * @var string If product is populated, this property contain the rewrite link of the default category
- */
- public $category;
- public static $_taxCalculationMethod = PS_TAX_EXC;
- protected static $_prices = array();
- protected static $_pricesLevel2 = array();
- protected static $_incat = array();
- protected static $_cart_quantity = array();
- protected static $_tax_rules_group = array();
- protected static $_cacheFeatures = array();
- protected static $_frontFeaturesCache = array();
- protected static $producPropertiesCache = array();
- /** @var array cache stock data in getStock() method */
- protected static $cacheStock = array();
- public static $definition = array(
- 'table' => 'product',
- 'primary' => 'id_product',
- 'multilang' => true,
- 'multilang_shop' => true,
- 'fields' => array(
- // Classic fields
- 'id_shop_default' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
- 'id_manufacturer' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
- 'id_supplier' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
- 'reference' => array('type' => self::TYPE_STRING, 'validate' => 'isReference', 'size' => 32),
- 'supplier_reference' => array('type' => self::TYPE_STRING, 'validate' => 'isReference', 'size' => 32),
- 'location' => array('type' => self::TYPE_STRING, 'validate' => 'isReference', 'size' => 64),
- 'width' => array('type' => self::TYPE_FLOAT, 'validate' => 'isUnsignedFloat'),
- 'height' => array('type' => self::TYPE_FLOAT, 'validate' => 'isUnsignedFloat'),
- 'depth' => array('type' => self::TYPE_FLOAT, 'validate' => 'isUnsignedFloat'),
- 'weight' => array('type' => self::TYPE_FLOAT, 'validate' => 'isUnsignedFloat'),
- 'quantity_discount' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
- 'ean13' => array('type' => self::TYPE_STRING, 'validate' => 'isEan13', 'size' => 13),
- 'upc' => array('type' => self::TYPE_STRING, 'validate' => 'isUpc', 'size' => 12),
- 'cache_is_pack' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
- 'cache_has_attachments' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
- 'is_virtual' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
- /* Shop fields */
- 'id_category_default' => array('type' => self::TYPE_INT, 'shop' => true, 'validate' => 'isUnsignedId'),
- 'id_tax_rules_group' => array('type' => self::TYPE_INT, 'shop' => true, 'validate' => 'isUnsignedId'),
- 'on_sale' => array('type' => self::TYPE_BOOL, 'shop' => true, 'validate' => 'isBool'),
- 'online_only' => array('type' => self::TYPE_BOOL, 'shop' => true, 'validate' => 'isBool'),
- 'ecotax' => array('type' => self::TYPE_FLOAT, 'shop' => true, 'validate' => 'isPrice'),
- 'minimal_quantity' => array('type' => self::TYPE_INT, 'shop' => true, 'validate' => 'isUnsignedInt'),
- 'price' => array('type' => self::TYPE_FLOAT, 'shop' => true, 'validate' => 'isPrice', 'required' => true),
- 'wholesale_price' => array('type' => self::TYPE_FLOAT, 'shop' => true, 'validate' => 'isPrice'),
- 'unity' => array('type' => self::TYPE_STRING, 'shop' => true, 'validate' => 'isString'),
- 'unit_price_ratio' => array('type' => self::TYPE_FLOAT, 'shop' => true),
- 'additional_shipping_cost' => array('type' => self::TYPE_FLOAT, 'shop' => true, 'validate' => 'isPrice'),
- 'customizable' => array('type' => self::TYPE_INT, 'shop' => true, 'validate' => 'isUnsignedInt'),
- 'text_fields' => array('type' => self::TYPE_INT, 'shop' => true, 'validate' => 'isUnsignedInt'),
- 'uploadable_files' => array('type' => self::TYPE_INT, 'shop' => true, 'validate' => 'isUnsignedInt'),
- 'active' => array('type' => self::TYPE_BOOL, 'shop' => true, 'validate' => 'isBool'),
- 'available_for_order' => array('type' => self::TYPE_BOOL, 'shop' => true, 'validate' => 'isBool'),
- 'available_date' => array('type' => self::TYPE_DATE, 'shop' => true, 'validate' => 'isDateFormat'),
- 'condition' => array('type' => self::TYPE_STRING, 'shop' => true, 'validate' => 'isGenericName', 'values' => array('new', 'used', 'refurbished'), 'default' => 'new'),
- 'show_price' => array('type' => self::TYPE_BOOL, 'shop' => true, 'validate' => 'isBool'),
- 'indexed' => array('type' => self::TYPE_BOOL, 'shop' => true, 'validate' => 'isBool'),
- 'visibility' => array('type' => self::TYPE_STRING, 'shop' => true, 'validate' => 'isProductVisibility', 'values' => array('both', 'catalog', 'search', 'none'), 'default' => 'both'),
- 'cache_default_attribute' => array('type' => self::TYPE_INT, 'shop' => true),
- 'advanced_stock_management' => array('type' => self::TYPE_BOOL, 'shop' => true, 'validate' => 'isBool'),
- 'date_add' => array('type' => self::TYPE_DATE, 'shop' => true, 'validate' => 'isDateFormat'),
- 'date_upd' => array('type' => self::TYPE_DATE, 'shop' => true, 'validate' => 'isDateFormat'),
- /* Lang fields */
- 'meta_description' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'size' => 255),
- 'meta_keywords' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'size' => 255),
- 'meta_title' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'size' => 128),
- 'link_rewrite' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isLinkRewrite', 'required' => true, 'size' => 128),
- 'name' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isCatalogName', 'required' => true, 'size' => 128),
- 'description' => array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isString'),
- 'description_short' => array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isString'),
- 'available_now' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'size' => 255),
- 'available_later' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'IsGenericName', 'size' => 255),
- ),
- 'associations' => array(
- 'manufacturer' => array('type' => self::HAS_ONE),
- 'supplier' => array('type' => self::HAS_ONE),
- 'default_category' => array('type' => self::HAS_ONE, 'field' => 'id_category_default', 'object' => 'Category'),
- 'tax_rules_group' => array('type' => self::HAS_ONE),
- 'categories' => array('type' => self::HAS_MANY, 'field' => 'id_category', 'object' => 'Category', 'association' => 'category_product'),
- 'stock_availables' => array('type' => self::HAS_MANY, 'field' => 'id_stock_available', 'object' => 'StockAvailable', 'association' => 'stock_availables'),
- ),
- );
- protected $webserviceParameters = array(
- 'objectMethods' => array(
- 'add' => 'addWs',
- 'update' => 'updateWs'
- ),
- 'objectNodeNames' => 'products',
- 'fields' => array(
- 'id_manufacturer' => array(
- 'xlink_resource' => 'manufacturers'
- ),
- 'id_supplier' => array(
- 'xlink_resource' => 'suppliers'
- ),
- 'id_category_default' => array(
- 'xlink_resource' => 'categories'
- ),
- 'new' => array(),
- 'cache_default_attribute' => array(),
- 'id_default_image' => array(
- 'getter' => 'getCoverWs',
- 'setter' => 'setCoverWs',
- 'xlink_resource' => array(
- 'resourceName' => 'images',
- 'subResourceName' => 'products'
- )
- ),
- 'id_default_combination' => array(
- 'getter' => 'getWsDefaultCombination',
- 'setter' => 'setWsDefaultCombination',
- 'xlink_resource' => array(
- 'resourceName' => 'combinations'
- )
- ),
- 'id_tax_rules_group' => array(
- 'xlink_resource' => array(
- 'resourceName' => 'tax_rules_group'
- )
- ),
- 'position_in_category' => array(
- 'getter' => 'getWsPositionInCategory',
- 'setter' => false
- ),
- 'manufacturer_name' => array(
- 'getter' => 'getWsManufacturerName',
- 'setter' => false
- ),
- 'quantity' => array(
- 'getter' => false,
- 'setter' => false
- ),
- ),
- 'associations' => array(
- 'categories' => array(
- 'resource' => 'category',
- 'fields' => array(
- 'id' => array('required' => true),
- )
- ),
- 'images' => array(
- 'resource' => 'image',
- 'fields' => array('id' => array())
- ),
- 'combinations' => array(
- 'resource' => 'combinations',
- 'fields' => array(
- 'id' => array('required' => true),
- )
- ),
- 'product_option_values' => array(
- 'resource' => 'product_options_values',
- 'fields' => array(
- 'id' => array('required' => true),
- )
- ),
- 'product_features' => array(
- 'resource' => 'product_feature',
- 'fields' => array(
- 'id' => array('required' => true),
- 'id_feature_value' => array(
- 'required' => true,
- 'xlink_resource' => 'product_feature_values'
- ),
- )
- ),
- 'tags' => array('resource' => 'tag',
- 'fields' => array(
- 'id' => array('required' => true),
- )),
- 'stock_availables' => array('resource' => 'stock_available',
- 'fields' => array(
- 'id' => array('required' => true),
- 'id_product_attribute' => array('required' => true),
- ),
- 'setter' => false
- ),
- ),
- );
- const CUSTOMIZE_FILE = 0;
- const CUSTOMIZE_TEXTFIELD = 1;
- /**
- * Note: prefix is "PTYPE" because TYPE_ is used in ObjectModel (definition)
- */
- const PTYPE_SIMPLE = 0;
- const PTYPE_PACK = 1;
- const PTYPE_VIRTUAL = 2;
- public function __construct($id_product = null, $full = false, $id_lang = null, $id_shop = null, Context $context = null)
- {
- parent::__construct($id_product, $id_lang, $id_shop);
- if (!$context)
- $context = Context::getContext();
- if ($full && $this->id)
- {
- $this->isFullyLoaded = $full;
- $this->tax_name = 'deprecated'; // The applicable tax may be BOTH the product one AND the state one (moreover this variable is some deadcode)
- $this->manufacturer_name = Manufacturer::getNameById((int)$this->id_manufacturer);
- $this->supplier_name = Supplier::getNameById((int)$this->id_supplier);
- $address = null;
- if (is_object($context->cart) && $context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')} != null)
- $address = $context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')};
- $this->tax_rate = $this->getTaxesRate(new Address($address));
- $this->new = $this->isNew();
- $this->price = Product::getPriceStatic((int)$this->id, false, null, 6, null, false, true, 1, false, null, null, null, $this->specificPrice);
- $this->unit_price = ($this->unit_price_ratio != 0 ? $this->price / $this->unit_price_ratio : 0);
- if ($this->id)
- $this->tags = Tag::getProductTags((int)$this->id);
- $this->loadStockData();
- }
- if ($this->id_category_default)
- $this->category = Category::getLinkRewrite((int)$this->id_category_default, (int)$id_lang);
- }
- /**
- * @see ObjectModel::getFieldsShop()
- * @return array
- */
- public function getFieldsShop()
- {
- $fields = parent::getFieldsShop();
- if (is_null($this->update_fields) || (!empty($this->update_fields['price']) && !empty($this->update_fields['unit_price'])))
- $fields['unit_price_ratio'] = (float)$this->unit_price > 0 ? $this->price / $this->unit_price : 0;
- return $fields;
- }
- public function add($autodate = true, $null_values = false)
- {
- if (!parent::add($autodate, $null_values))
- return false;
-
- if ($this->getType() == Product::PTYPE_VIRTUAL)
- StockAvailable::setProductOutOfStock((int)$this->id, 1);
- else
- StockAvailable::setProductOutOfStock((int)$this->id, 2);
- $this->setGroupReduction();
- Hook::exec('actionProductSave', array('id_product' => $this->id));
- return true;
- }
- public function update($null_values = false)
- {
- $return = parent::update($null_values);
- $this->setGroupReduction();
- Hook::exec('actionProductSave', array('id_product' => $this->id));
- return $return;
- }
- public static function initPricesComputation($id_customer = null)
- {
- if ($id_customer)
- {
- $customer = new Customer((int)$id_customer);
- if (!Validate::isLoadedObject($customer))
- die(Tools::displayError());
- self::$_taxCalculationMethod = Group::getPriceDisplayMethod((int)$customer->id_default_group);
- }
- else
- self::$_taxCalculationMethod = Group::getPriceDisplayMethod(Group::getCurrent()->id);
- }
- public static function getTaxCalculationMethod($id_customer = null)
- {
- if ($id_customer)
- Product::initPricesComputation((int)$id_customer);
- return (int)self::$_taxCalculationMethod;
- }
- /**
- * Move a product inside its category
- * @param boolean $way Up (1) or Down (0)
- * @param integer $position
- * return boolean Update result
- */
- public function updatePosition($way, $position)
- {
- if (!$res = Db::getInstance()->executeS('
- SELECT cp.`id_product`, cp.`position`, cp.`id_category`
- FROM `'._DB_PREFIX_.'category_product` cp
- WHERE cp.`id_category` = '.(int)Tools::getValue('id_category', 1).'
- ORDER BY cp.`position` ASC'
- ))
- return false;
- foreach ($res as $product)
- if ((int)$product['id_product'] == (int)$this->id)
- $moved_product = $product;
- if (!isset($moved_product) || !isset($position))
- return false;
- // < and > statements rather than BETWEEN operator
- // since BETWEEN is treated differently according to databases
- return (Db::getInstance()->execute('
- UPDATE `'._DB_PREFIX_.'category_product`
- SET `position`= `position` '.($way ? '- 1' : '+ 1').'
- WHERE `position`
- '.($way
- ? '> '.(int)$moved_product['position'].' AND `position` <= '.(int)$position
- : '< '.(int)$moved_product['position'].' AND `position` >= '.(int)$position).'
- AND `id_category`='.(int)$moved_product['id_category'])
- && Db::getInstance()->execute('
- UPDATE `'._DB_PREFIX_.'category_product`
- SET `position` = '.(int)$position.'
- WHERE `id_product` = '.(int)$moved_product['id_product'].'
- AND `id_category`='.(int)$moved_product['id_category']));
- }
- /*
- * Reorder product position in category $id_category.
- * Call it after deleting a product from a category.
- *
- * @param int $id_category
- */
- public static function cleanPositions($id_category)
- {
- $return = true;
- $result = Db::getInstance()->executeS('
- SELECT `id_product`
- FROM `'._DB_PREFIX_.'category_product`
- WHERE `id_category` = '.(int)$id_category.'
- ORDER BY `position`
- ');
- $total = count($result);
- for ($i = 0; $i < $total; $i++)
- $return &= Db::getInstance()->update('category_product', array(
- 'position' => $i,
- ), '`id_category` = '.(int)$id_category.' AND `id_product` = '.(int)$result[$i]['id_product']);
- return $return;
- }
- /**
- * Get the default attribute for a product
- *
- * @return int Attributes list
- */
- public static function getDefaultAttribute($id_product, $minimum_quantity = 0)
- {
- if (!Combination::isFeatureActive())
- return 0;
- $sql = 'SELECT pa.id_product_attribute
- FROM '._DB_PREFIX_.'product_attribute pa
- '.Shop::addSqlAssociation('product_attribute', 'pa').'
- '.($minimum_quantity > 0 ? Product::sqlStock('pa', 'pa') : '').
- ' WHERE product_attribute_shop.default_on = 1 '
- .($minimum_quantity > 0 ? ' AND IFNULL(stock.quantity, 0) >= '.(int)$minimum_quantity : '').
- ' AND pa.id_product = '.(int)$id_product;
- $result = Db::getInstance()->getValue($sql);
- if (!$result)
- {
- $sql = 'SELECT pa.id_product_attribute
- FROM '._DB_PREFIX_.'product_attribute pa
- '.Shop::addSqlAssociation('product_attribute', 'pa').'
- '.($minimum_quantity > 0 ? Product::sqlStock('pa', 'pa') : '').
- ' WHERE pa.id_product = '.(int)$id_product
- .($minimum_quantity > 0 ? ' AND IFNULL(stock.quantity, 0) >= '.(int)$minimum_quantity : '');
- $result = Db::getInstance()->getValue($sql);
- }
- if (!$result)
- {
- $sql = 'SELECT pa.id_product_attribute
- FROM '._DB_PREFIX_.'product_attribute pa
- '.Shop::addSqlAssociation('product_attribute', 'pa').'
- WHERE product_attribute_shop.`default_on` = 1
- AND pa.id_product = '.(int)$id_product;
- $result = Db::getInstance()->getValue($sql);
- }
- if (!$result)
- {
- $sql = 'SELECT pa.id_product_attribute
- FROM '._DB_PREFIX_.'product_attribute pa
- '.Shop::addSqlAssociation('product_attribute', 'pa').'
- WHERE pa.id_product = '.(int)$id_product;
- $result = Db::getInstance()->getValue($sql);
- }
- return $result;
- }
- public static function updateDefaultAttribute($id_product)
- {
- Db::getInstance()->update('product_shop', array(
- 'cache_default_attribute' => (int)Product::getDefaultAttribute($id_product),
- ), 'id_product = '.(int)$id_product);
- }
- public static function updateIsVirtual($id_product)
- {
- Db::getInstance()->update('product', array(
- 'is_virtual' => (int)$id_product,
- ), 'id_product = '.(int)$id_product);
- }
- /**
- * @see ObjectModel::validateFieldsLang()
- */
- public function validateFieldsLang($die = true, $error_return = false)
- {
- $limit = (int)Configuration::get('PS_PRODUCT_SHORT_DESC_LIMIT');
- if ($limit <= 0)
- $limit = 800;
- $this->def['fields']['description_short']['size'] = $limit;
- return parent::validateFieldsLang($die, $error_return);
- }
- public function delete()
- {
- /*
- * @since 1.5.0
- * It is NOT possible to delete a product if there are currently:
- * - physical stock for this product
- * - supply order(s) for this product
- */
- if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && $this->advanced_stock_management)
- {
- $stock_manager = StockManagerFactory::getManager();
- $physical_quantity = $stock_manager->getProductPhysicalQuantities($this->id, 0);
- $real_quantity = $stock_manager->getProductRealQuantities($this->id, 0);
- if ($physical_quantity > 0)
- return false;
- if ($real_quantity > $physical_quantity)
- return false;
- }
- $result = parent::delete();
- // Removes the product from StockAvailable, for the current shop
- StockAvailable::removeProductFromStockAvailable($this->id);
- $result &= ($this->deleteProductAttributes() && $this->deleteImages() && $this->deleteSceneProducts());
- // If there are still entries in product_shop, don't remove completly the product
- if ($this->hasMultishopEntries())
- return true;
-
- Product::cleanPositions($this->id);
-
- Hook::exec('actionProductDelete', array('product' => $this));
- if (!$result ||
- !GroupReduction::deleteProductReduction($this->id) ||
- !$this->deleteCategories(true) ||
- !$this->deleteProductFeatures() ||
- !$this->deleteTags() ||
- !$this->deleteCartProducts() ||
- !$this->deleteAttributesImpacts() ||
- !$this->deleteAttachments() ||
- !$this->deleteCustomization() ||
- !SpecificPrice::deleteByProductId((int)$this->id) ||
- !$this->deletePack() ||
- !$this->deleteProductSale() ||
- !$this->deleteSearchIndexes() ||
- !$this->deleteAccessories() ||
- !$this->deleteFromAccessories() ||
- !$this->deleteFromSupplier() ||
- !$this->deleteDownload() ||
- !$this->deleteFromCartRules())
- return false;
- return true;
- }
- public function deleteSelection($products)
- {
- $return = 1;
- if (is_array($products) && ($count = count($products)))
- {
- // Deleting products can be quite long on a cheap server. Let's say 1.5 seconds by product (I've seen it!).
- if (intval(ini_get('max_execution_time')) < round($count * 1.5))
- ini_set('max_execution_time', round($count * 1.5));
-
- foreach ($products as $id_product)
- {
- $product = new Product((int)$id_product);
- $return &= $product->delete();
- }
- }
- return $return;
- }
- public function deleteFromCartRules()
- {
- CartRule::cleanProductRuleIntegrity('products', $this->id);
- return true;
- }
-
- public function deleteFromSupplier()
- {
- return Db::getInstance()->delete('product_supplier', 'id_product = '.(int)$this->id);
- }
- /**
- * addToCategories add this product to the category/ies if not exists.
- *
- * @param mixed $categories id_category or array of id_category
- * @return boolean true if succeed
- */
- public function addToCategories($categories = array())
- {
- if (empty($categories))
- return false;
- if (!is_array($categories))
- $categories = array($categories);
- if (!count($categories))
- return false;
- $categories = array_map('intval', $categories);
- $current_categories = $this->getCategories();
- $current_categories = array_map('intval', $current_categories);
- // for new categ, put product at last position
- $res_categ_new_pos = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
- SELECT id_category, MAX(position)+1 newPos
- FROM `'._DB_PREFIX_.'category_product`
- WHERE `id_category` IN('.implode(',', $categories).')
- GROUP BY id_category');
- foreach ($res_categ_new_pos as $array)
- $new_categories[(int)$array['id_category']] = (int)$array['newPos'];
- $new_categ_pos = array();
- foreach ($categories as $id_category)
- $new_categ_pos[$id_category] = isset($new_categories[$id_category]) ? $new_categories[$id_category] : 0;
- $product_cats = array();
- foreach ($categories as $new_id_categ)
- if (!in_array($new_id_categ, $current_categories))
- $product_cats[] = array(
- 'id_category' => (int)$new_id_categ,
- 'id_product' => (int)$this->id,
- 'position' => (int)$new_categ_pos[$new_id_categ],
- );
- Db::getInstance()->insert('category_product', $product_cats);
- return true;
- }
- /**
- * Update categories to index product into
- *
- * @param string $productCategories Categories list to index product into
- * @param boolean $keeping_current_pos (deprecated, no more used)
- * @return array Update/insertion result
- */
- public function updateCategories($categories, $keeping_current_pos = false)
- {
- if (empty($categories))
- return false;
- $result = Db::getInstance()->executeS('
- SELECT c.`id_category`
- FROM `'._DB_PREFIX_.'category_product` cp
- LEFT JOIN `'._DB_PREFIX_.'category` c ON (c.`id_category` = cp.`id_category`)
- '.Shop::addSqlAssociation('category', 'c', true).'
- WHERE cp.`id_category` NOT IN ('.implode(',', array_map('intval', $categories)).')
- AND cp.id_product = '.$this->id
- );
- foreach ($result as $categ_to_delete)
- $this->deleteCategory($categ_to_delete['id_category']);
- // if none are found, it's an error
- if (!is_array($result))
- return false;
- if (!$this->addToCategories($categories))
- return false;
- SpecificPriceRule::applyAllRules(array((int)$this->id));
- return true;
- }
- /**
- * deleteCategory delete this product from the category $id_category
- *
- * @param mixed $id_category
- * @param mixed $clean_positions
- * @return boolean
- */
- public function deleteCategory($id_category, $clean_positions = true)
- {
- $result = Db::getInstance()->executeS(
- 'SELECT `id_category`
- FROM `'._DB_PREFIX_.'category_product`
- WHERE `id_product` = '.(int)$this->id.'
- AND id_category = '.(int)$id_category.''
- );
- $return = Db::getInstance()->delete('category_product', 'id_product = '.(int)$this->id.' AND id_category = '.(int)$id_category);
- if ($clean_positions === true)
- foreach ($result as $row)
- $this->cleanPositions((int)$row['id_category']);
- SpecificPriceRule::applyAllRules(array((int)$this->id));
- return $return;
- }
- /**
- * Delete all association to category where product is indexed
- *
- * @param boolean $clean_positions clean category positions after deletion
- * @return array Deletion result
- */
- public function deleteCategories($clean_positions = false)
- {
- $return = Db::getInstance()->delete('category_product', 'id_product = '.(int)$this->id);
- if ($clean_positions === true)
- {
- $result = Db::getInstance()->executeS(
- 'SELECT `id_category`
- FROM `'._DB_PREFIX_.'category_product`
- WHERE `id_product` = '.(int)$this->id
- );
- foreach ($result as $row)
- $this->cleanPositions((int)$row['id_category']);
- }
- return $return;
- }
- /**
- * Delete products tags entries
- *
- * @return array Deletion result
- */
- public function deleteTags()
- {
- return Db::getInstance()->delete('product_tag', 'id_product = '.(int)$this->id)
- && Db::getInstance()->delete('tag', 'id_tag NOT IN (SELECT id_tag FROM '._DB_PREFIX_.'product_tag)');
- }
- /**
- * Delete product from cart
- *
- * @return array Deletion result
- */
- public function deleteCartProducts()
- {
- return Db::getInstance()->delete('cart_product', 'id_product = '.(int)$this->id);
- }
- /**
- * Delete product images from database
- *
- * @return bool success
- */
- public function deleteImages()
- {
- $result = Db::getInstance()->executeS('
- SELECT `id_image`
- FROM `'._DB_PREFIX_.'image`
- WHERE `id_product` = '.(int)$this->id
- );
- $status = true;
- if ($result)
- foreach ($result as $row)
- {
- $image = new Image($row['id_image']);
- $status &= $image->delete();
- }
- return $status;
- }
- /**
- * @deprecated 1.5.0 Use Combination::getPrice()
- */
- public static function getProductAttributePrice($id_product_attribute)
- {
- return Combination::getPrice($id_product_attribute);
- }
- /**
- * Get all available products
- *
- * @param integer $id_lang Language id
- * @param integer $start Start number
- * @param integer $limit Number of products to return
- * @param string $order_by Field for ordering
- * @param string $order_way Way for ordering (ASC or DESC)
- * @return array Products details
- */
- public static function getProducts($id_lang, $start, $limit, $order_by, $order_way, $id_category = false,
- $only_active = false, Context $context = null)
- {
- if (!$context)
- $context = Context::getContext();
- $front = true;
- if (!in_array($context->controller->controller_type, array('front', 'modulefront')))
- $front = false;
- if (!Validate::isOrderBy($order_by) || !Validate::isOrderWay($order_way))
- die (Tools::displayError());
- if ($order_by == 'id_product' || $order_by == 'price' || $order_by == 'date_add' || $order_by == 'date_upd')
- $order_by_prefix = 'p';
- else if ($order_by == 'name')
- $order_by_prefix = 'pl';
- else if ($order_by == 'position')
- $order_by_prefix = 'c';
- if (strpos($order_by, '.') > 0)
- {
- $order_by = explode('.', $order_by);
- $order_by_prefix = $order_by[0];
- $order_by = $order_by[1];
- }
- $sql = 'SELECT p.*, product_shop.*, pl.* , t.`rate` AS tax_rate, m.`name` AS manufacturer_name, s.`name` AS supplier_name
- FROM `'._DB_PREFIX_.'product` p
- '.Shop::addSqlAssociation('product', 'p').'
- LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` '.Shop::addSqlRestrictionOnLang('pl').')
- LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON (product_shop.`id_tax_rules_group` = tr.`id_tax_rules_group`
- AND tr.`id_country` = '.(int)Context::getContext()->country->id.'
- AND tr.`id_state` = 0)
- LEFT JOIN `'._DB_PREFIX_.'tax` t ON (t.`id_tax` = tr.`id_tax`)
- LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON (m.`id_manufacturer` = p.`id_manufacturer`)
- LEFT JOIN `'._DB_PREFIX_.'supplier` s ON (s.`id_supplier` = p.`id_supplier`)'.
- ($id_category ? 'LEFT JOIN `'._DB_PREFIX_.'category_product` c ON (c.`id_product` = p.`id_product`)' : '').'
- WHERE pl.`id_lang` = '.(int)$id_lang.
- ($id_category ? ' AND c.`id_category` = '.(int)$id_category : '').
- ($front ? ' AND product_shop.`visibility` IN ("both", "catalog")' : '').
- ($only_active ? ' AND product_shop.`active` = 1' : '').'
- ORDER BY '.(isset($order_by_prefix) ? pSQL($order_by_prefix).'.' : '').'`'.pSQL($order_by).'` '.pSQL($order_way).
- ($limit > 0 ? ' LIMIT '.(int)$start.','.(int)$limit : '');
- $rq = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
- if ($order_by == 'price')
- Tools::orderbyPrice($rq, $order_way);
- return ($rq);
- }
- public static function getSimpleProducts($id_lang, Context $context = null)
- {
- if (!$context)
- $context = Context::getContext();
- $front = true;
- if (!in_array($context->controller->controller_type, array('front', 'modulefront')))
- $front = false;
- $sql = 'SELECT p.`id_product`, pl.`name`
- FROM `'._DB_PREFIX_.'product` p
- '.Shop::addSqlAssociation('product', 'p').'
- LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` '.Shop::addSqlRestrictionOnLang('pl').')
- WHERE pl.`id_lang` = '.(int)$id_lang.'
- '.($front ? ' AND product_shop.`visibility` IN ("both", "catalog")' : '').'
- ORDER BY pl.`name`';
- return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
- }
- public function isNew()
- {
- $result = Db::getInstance()->executeS('
- SELECT p.id_product
- FROM `'._DB_PREFIX_.'product` p
- '.Shop::addSqlAssociation('product', 'p').'
- WHERE p.id_product = '.(int)$this->id.'
- AND DATEDIFF(
- product_shop.`date_add`,
- DATE_SUB(
- NOW(),
- INTERVAL '.(Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20).' DAY
- )
- ) > 0
- ');
- return count($result) > 0;
- }
- public function productAttributeExists($attributes_list, $current_product_attribute = false, Context $context = null, $all_shops = false, $return_id = false)
- {
- if (!Combination::isFeatureActive())
- return false;
- if ($context === null)
- $context = Context::getContext();
- $result = Db::getInstance()->executeS(
- 'SELECT pac.`id_attribute`, pac.`id_product_attribute`
- FROM `'._DB_PREFIX_.'product_attribute` pa
- JOIN `'._DB_PREFIX_.'product_attribute_shop` pas ON (pas.id_product_attribute = pa.id_product_attribute)
- LEFT JOIN `'._DB_PREFIX_.'product_attribute_combination` pac ON (pac.`id_product_attribute` = pa.`id_product_attribute`)
- WHERE 1 '.(!$all_shops ? ' AND pas.id_shop ='.(int)$context->shop->id : '').' AND pa.`id_product` = '.(int)$this->id.
- ($all_shops ? ' GROUP BY pac.id_attribute, pac.id_product_attribute ' : '')
- );
- /* If something's wrong */
- if (!$result || empty($result))
- return false;
- /* Product attributes simulation */
- $product_attributes = array();
- foreach ($result as $product_attribute)
- $product_attributes[$product_attribute['id_product_attribute']][] = $product_attribute['id_attribute'];
- /* Checking product's attribute existence */
- foreach ($product_attributes as $key => $product_attribute)
- if (count($product_attribute) == count($attributes_list))
- {
- $diff = false;
- for ($i = 0; $diff == false && isset($product_attribute[$i]); $i++)
- if (!in_array($product_attribute[$i], $attributes_list) || $key == $current_product_attribute)
- $diff = true;
- if (!$diff)
- {
- if ($return_id)
- return $key;
- return true;
- }
- }
- return false;
- }
- /**
- * addProductAttribute is deprecated
- *
- * The quantity params now set StockAvailable for the current shop with the specified quantity
- * The supplier_reference params now set the supplier reference of the default supplier of the product if possible
- *
- * @see StockManager if you want to manage real stock
- * @see StockAvailable if you want to manage available quantities for sale on your shop(s)
- * @see ProductSupplier for manage supplier reference(s)
- *
- * @deprecated since 1.5.0
- */
- public function addProductAttribute($price, $weight, $unit_impact, $ecotax, $quantity, $id_images, $reference,
- $id_supplier = null, $ean13, $default, $location = null, $upc = null, $minimal_quantity = 1)
- {
- Tools::displayAsDeprecated();
- $id_product_attribute = $this->addAttribute(
- $price, $weight, $unit_impact, $ecotax, $id_images,
- $reference, $ean13, $default, $location, $upc, $minimal_quantity
- );
- if (!$id_product_attribute)
- return false;
- StockAvailable::setQuantity($this->id, $id_product_attribute, $quantity);
- //Try to set the default supplier reference
- $this->addSupplierReference($id_supplier, $id_product_attribute);
- return $id_product_attribute;
- }
-
- public function generateMultipleCombinations($combinations, $attributes)
- {
- $attributes_list = array();
- $res = true;
- $default_on = 1;
- foreach ($combinations as $key => $combination)
- {
- $id_combination = (int)$this->productAttributeExists($attributes[$key], false, null, true, true);
- $obj = new Combination($id_combination);
-
- if ($id_combination)
- {
- $obj->minimal_quantity = 1;
- $obj->available_date = '0000-00-00';
- }
- foreach ($combination as $field => $value)
- $obj->$field = $value;
- $obj->default_on = $default_on;
- $default_on = 0;
- $obj->save();
-
- if (!$id_combination)
- {
- $attribute_list = array();
- foreach ($attributes[$key] as $id_attribute)
- $attribute_list[] = array(
- 'id_product_attribute' => (int)$obj->id,
- 'id_attribute' => (int)$id_attribute
- );
- $res &= Db::getInstance()->insert('product_attribute_combination', $attribute_list);
- }
- }
- return $res;
- }
-
- /**
- * @param integer $quantity DEPRECATED
- * @param string $supplier_reference DEPRECATED
- */
- public function addCombinationEntity($wholesale_price, $price, $weight, $unit_impact, $ecotax, $quantity,
- $id_images, $reference, $id_supplier, $ean13, $default, $location = null, $upc = null, $minimal_quantity = 1, array $id_shop_list = array())
- {
- $id_product_attribute = $this->addAttribute(
- $price, $weight, $unit_impact, $ecotax, $id_images,
- $reference, $ean13, $default, $location, $upc, $minimal_quantity, $id_shop_list);
- $this->addSupplierReference($id_supplier, $id_product_attribute);
- $result = ObjectModel::updateMultishopTable('Combination', array(
- 'wholesale_price' => (float)$wholesale_price,
- ), 'a.id_product_attribute = '.(int)$id_product_attribute);
- if (!$id_product_attribute || !$result)
- return false;
- return $id_product_attribute;
- }
- public function addProductAttributeMultiple($attributes, $set_default = true)
- {
- Tools::displayAsDeprecated();
- $return = array();
- $default_value = 1;
- foreach ($attributes as &$attribute)
- {
- $obj = new Combination();
- foreach ($attribute as $key => $value)
- $obj->$key = $value;
- if ($set_default)
- {
- $obj->default_on = $default_value;
- $default_value = 0;
- // if we add a combination for this shop and this product does not use the combination feature in other shop,
- // we clone the default combination in every shop linked to this product
- if (!$this->hasAttributesInOtherShops())
- {
- $id_shop_list_array = Product::getShopsByProduct($this->id);
- $id_shop_list = array();
- foreach ($id_shop_list_array as $array_shop)
- $id_shop_list[] = $array_shop['id_shop'];
- $obj->id_shop_list = $id_shop_list;
- }
- }
- $obj->add();
- $return[] = $obj->id;
- }
- return $return;
- }
- /**
- * Del all default attributes for product
- */
- public function deleteDefaultAttributes()
- {
- return ObjectModel::updateMultishopTable('Combination', array(
- 'default_on' => 0,
- ), 'id_product = '.(int)$this->id);
- }
- public function setDefaultAttribute($id_product_attribute)
- {
- $result = ObjectModel::updateMultishopTable('Combination', array(
- 'default_on' => 1
- ), '`id_product` = '.(int)$this->id.' AND a.`id_product_attribute` = '.(int)$id_product_attribute);
- $result &= ObjectModel::updateMultishopTable('product', array(
- 'cache_default_attribute' => (int)$id_product_attribute,
- ), 'a.`id_product` = '.(int)$this->id);
- return $result;
- }
- /**
- * Update a product attribute
- *
- * @deprecated since 1.5
- * @see updateAttribute() to use instead
- * @see ProductSupplier for manage supplier reference(s)
- *
- */
- public function updateProductAttribute($id_product_attribute, $wholesale_price, $price, $weight, $unit, $ecotax,
- $id_images, $reference, $id_supplier = null, $ean13, $default, $location = null, $upc = null, $minimal_quantity, $available_date)
- {
- Tools::displayAsDeprecated();
- $return = $this->updateAttribute(
- $id_product_attribute, $wholesale_price, $price, $weight, $unit, $ecotax,
- $id_images, $reference, $ean13, $default, $location = null, $upc = null, $minimal_quantity, $available_date
- );
- $this->addSupplierReference($id_supplier, $id_product_attribute);
- return $return;
- }
- /**
- * Sets Supplier Reference
- *
- * @param int $id_supplier
- * @param int $id_product_attribute
- * @param string $supplier_reference
- * @param float $price
- * @param int $id_currency
- */
- public function addSupplierReference($id_supplier, $id_product_attribute, $supplier_reference = null, $price = null, $id_currency = null)
- {
- //in some case we need to add price without supplier reference
- if ($supplier_reference === null)
- $supplier_reference = '';
-
- //Try to set the default supplier reference
- if ($id_supplier > 0)
- {
- $id_product_supplier = (int)ProductSupplier::getIdByProductAndSupplier($this->id, $id_product_attribute, $id_supplier);
- if (!$id_product_supplier)
- {
- //create new record
- $product_supplier_entity = new ProductSupplier();
- $product_supplier_entity->id_product = (int)$this->id;
- $product_supplier_entity->id_product_attribute = (int)$id_product_attribute;
- $product_supplier_entity->id_supplier = (int)$id_supplier;
- $product_supplier_entity->product_supplier_reference = pSQL($supplier_reference);
- $product_supplier_entity->product_supplier_price_te = (int)$price;
- $product_supplier_entity->id_currency = (int)$id_currency;
- $product_supplier_entity->save();
- }
- else
- {
- $product_supplier = new ProductSupplier((int)$id_product_supplier);
- $product_supplier->product_supplier_reference = pSQL($supplier_reference);
- $product_supplier->update();
- }
- }
- }
- /**
- * Update a product attribute
- *
- * @param integer $id_product_attribute Product attribute id
- * @param float $wholesale_price Wholesale price
- * @param float $price Additional price
- * @param float $weight Additional weight
- * @param float $unit
- * @param float $ecotax Additional ecotax
- * @param integer $id_image Image id
- * @param string $reference Reference
- * @param string $ean13 Ean-13 barcode
- * @param int $default Default On
- * @param string $upc Upc barcode
- * @param string $minimal_quantity Minimal quantity
- * @return array Update result
- */
- public function updateAttribute($id_product_attribute, $wholesale_price, $price, $weight, $unit, $ecotax,
- $id_images, $reference, $ean13, $default, $location = null, $upc = null, $minimal_quantity = null, $available_date = null, $update_all_fields = true, array $id_shop_list = array())
- {
- $combination = new Combination($id_product_attribute);
- if (!$update_all_fields)
- $combination->setFieldsToUpdate(array(
- 'price' => !is_null($price),
- 'wholesale_price' => !is_null($wholesale_price),
- 'ecotax' => !is_null($ecotax),
- 'weight' => !is_null($weight),
- 'unit_price_impact' => !is_null($unit),
- 'default_on' => !is_null($default),
- 'minimal_quantity' => !is_null($minimal_quantity),
- 'available_date' => !is_null($available_date),
- ));
- $price = str_replace(',', '.', $price);
- $weight = str_replace(',', '.', $weight);
- $combination->price = (float)$price;
- $combination->wholesale_price = (float)$wholesale_price;
- $combination->ecotax = (float)$ecotax;
- $combination->weight = (float)$weight;
- $combination->unit_price_impact = (float)$unit;
- $combination->reference = pSQL($reference);
- $combination->location = pSQL($location);
- $combination->ean13 = pSQL($ean13);
- $combination->upc = pSQL($upc);
- $combination->default_on = (int)$default;
- $combination->minimal_quantity = (int)$minimal_quantity;
- $combination->available_date = $available_date ? pSQL($available_date) : '0000-00-00';
- if (count($id_shop_list))
- $combination->id_shop_list = $id_shop_list;
- $combination->save();
- if (!empty($id_images))
- $combination->setImages($id_images);
- Product::updateDefaultAttribute($this->id);
- Hook::exec('actionProductAttributeUpdate', array('id_product_attribute' => $id_product_attribute));
- return true;
- }
- /**
- * Add a product attribute
- * @since 1.5.0.1
- *
- * @param float $price Additional price
- * @param float $weight Additional weight
- * @param float $ecotax Additional ecotax
- * @param integer $id_images Image ids
- * @param string $reference Reference
- * @param string $location Location
- * @param string $ean13 Ean-13 barcode
- * @param boolean $default Is default attribute for product
- * @param integer $minimal_quantity Minimal quantity to add to cart
- * @return mixed $id_product_attribute or false
- */
- public function addAttribute($price, $weight, $unit_impact, $ecotax, $id_images, $reference, $ean13,
- $default, $location = null, $upc = null, $minimal_quantity = 1, array $id_shop_list = array())
- {
- if (!$this->id)
- return;
- $price = str_replace(',', '.', $price);
- $weight = str_replace(',', '.', $weight);
- $combination = new Combination();
- $combination->id_product = (int)$this->id;
- $combination->price = (float)$price;
- $combination->ecotax = (float)$ecotax;
- $combination->quantity = 0;
- $combination->weight = (float)$weight;
- $combination->unit_price_impact = (float)$unit_impact;
- $combination->reference = pSQL($reference);
- $combination->location = pSQL($location);
- $combination->ean13 = pSQL($ean13);
- $combination->upc = pSQL($upc);
- $combination->default_on = (int)$default;
- $combination->minimal_quantity = (int)$minimal_quantity;
- // if we add a combination for this shop and this product does not use the combination feature in other shop,
- // we clone the default combination in every shop linked to this product
- if ($default && !$this->hasAttributesInOtherShops())
- {
- $id_shop_list_array = Product::getShopsByProduct($this->id);
- foreach ($id_shop_list_array as $array_shop)
- $id_shop_list[] = $array_shop['id_shop'];
- }
- if (count($id_shop_list))
- $combination->id_shop_list = $id_shop_list;
- $combination->add();
- if (!$combination->id)
- return false;
- Product::updateDefaultAttribute($this->id);
- if (!empty($id_images))
- $combination->setImages($id_images);
- return (int)$combination->id;
- }
- /**
- * @deprecated since 1.5.0
- */
- public function updateQuantityProductWithAttributeQuantity()
- {
- Tools::displayAsDeprecated();
- return Db::getInstance()->execute('
- UPDATE `'._DB_PREFIX_.'product`
- SET `quantity` = IFNULL(
- (
- SELECT SUM(`quantity`)
- FROM `'._DB_PREFIX_.'product_attribute`
- WHERE `id_product` = '.(int)$this->id.'
- ), \'0\')
- WHERE `id_product` = '.(int)$this->id);
- }
- /**
- * Delete product attributes
- *
- * @return array Deletion result
- */
- public function deleteProductAttributes()
- {
- Hook::exec('actionProductAttributeDelete', array('id_product_attribute' => 0, 'id_product' => $this->id, 'deleteAllAttributes' => true));
- $result = true;
- $combinations = new Collection('Combination');
- $combinations->where('id_product', '=', $this->id);
- foreach ($combinations as $combination)
- $result &= $combination->delete();
- SpecificPriceRule::applyAllRules(array((int)$this->id));
- return $result;
- }
- /**
- * Delete product attributes impacts
- *
- * @return Deletion result
- */
- public function deleteAttributesImpacts()
- {
- return Db::getInstance()->execute(
- 'DELETE FROM `'._DB_PREFIX_.'attribute_impact`
- WHERE `id_product` = '.(int)$this->id
- );
- }
- /**
- * Delete product features
- *
- * @return array Deletion result
- */
- public function deleteProductFeatures()
- {
- SpecificPriceRule::applyAllRules(array((int)$this->id));
- return $this->deleteFeatures();
- }
- /**
- * Delete product attachments
- *
- * @return array Deletion result
- */
- public function deleteAttachments()
- {
- return Db::getInstance()->execute('
- DELETE FROM `'._DB_PREFIX_.'product_attachment`
- WHERE `id_product` = '.(int)$this->id
- );
- }
- /**
- * Delete product customizations
- *
- * @return array Deletion result
- */
- public function deleteCustomization()
- {
- return (
- Db::getInstance()->execute(
- 'DELETE FROM `'._DB_PREFIX_.'customization_field`
- WHERE `id_product` = '.(int)$this->id
- )
- &&
- Db::getInstance()->execute(
- 'DELETE FROM `'._DB_PREFIX_.'customization_field_lang`
- WHERE `id_customization_field` NOT IN (SELECT id_customization_field
- FROM `'._DB_PREFIX_.'customization_field`)'
- )
- );
- }
- /**
- * Delete product pack details
- *
- * @return array Deletion result
- */
- public function deletePack()
- {
- return Db::getInstance()->execute(
- 'DELETE FROM `'._DB_PREFIX_.'pack`
- WHERE `id_product_pack` = '.(int)$this->id.'
- OR `id_product_item` = '.(int)$this->id
- );
- }
- /**
- * Delete product sales
- *
- * @return array Deletion result
- */
- public function deleteProductSale()
- {
- return Db::getInstance()->execute(
- 'DELETE FROM `'._DB_PREFIX_.'product_sale`
- WHERE `id_product` = '.(int)$this->id
- );
- }
- /**
- * Delete product in its scenes
- *
- * @return array Deletion result
- */
- public function deleteSceneProducts()
- {
- return Db::getInstance()->execute(
- 'DELETE FROM `'._DB_PREFIX_.'scene_products`
- WHERE `id_product` = '.(int)$this->id
- );
- }
- /**
- * Delete product indexed words
- *
- * @return array Deletion result
- */
- public function deleteSearchIndexes()
- {
- return (
- Db::getInstance()->execute(
- 'DELETE FROM `'._DB_PREFIX_.'search_index`
- WHERE `id_product` = '.(int)$this->id
- )
- &&
- Db::getInstance()->execute(
- 'DELETE FROM `'._DB_PREF…
Large files files are truncated, but you can click here to view the full file