[+] Project : adding Features detachables in order to improve performance
// clean code
This commit is contained in:
+40
-12
@@ -37,6 +37,8 @@ class AliasCore extends ObjectModel
|
||||
|
||||
protected $table = 'alias';
|
||||
protected $identifier = 'id_alias';
|
||||
|
||||
protected static $feature_active = null;
|
||||
|
||||
function __construct($id = NULL, $alias = NULL, $search = NULL, $id_lang = NULL)
|
||||
{
|
||||
@@ -44,27 +46,38 @@ class AliasCore extends ObjectModel
|
||||
parent::__construct($id);
|
||||
elseif ($alias AND Validate::isValidSearch($alias))
|
||||
{
|
||||
$row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
|
||||
SELECT a.id_alias, a.search, a.alias
|
||||
FROM `'._DB_PREFIX_.'alias` a
|
||||
WHERE `alias` LIKE \''.pSQL($alias).'\' AND `active` = 1');
|
||||
|
||||
if ($row)
|
||||
{
|
||||
$this->id = (int)($row['id_alias']);
|
||||
$this->search = $search ? trim($search) : $row['search'];
|
||||
$this->alias = $row['alias'];
|
||||
}
|
||||
else
|
||||
if (!self::isFeatureActive())
|
||||
{
|
||||
$this->alias = trim($alias);
|
||||
$this->search = trim($search);
|
||||
}
|
||||
else
|
||||
{
|
||||
$row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
|
||||
SELECT a.id_alias, a.search, a.alias
|
||||
FROM `'._DB_PREFIX_.'alias` a
|
||||
WHERE `alias` LIKE \''.pSQL($alias).'\' AND `active` = 1');
|
||||
|
||||
if ($row)
|
||||
{
|
||||
$this->id = (int)($row['id_alias']);
|
||||
$this->search = $search ? trim($search) : $row['search'];
|
||||
$this->alias = $row['alias'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->alias = trim($alias);
|
||||
$this->search = trim($search);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getAliases()
|
||||
{
|
||||
if (!self::isFeatureActive())
|
||||
return '';
|
||||
|
||||
$aliases = Db::getInstance()->ExecuteS('
|
||||
SELECT a.alias
|
||||
FROM `'._DB_PREFIX_.'alias` a
|
||||
@@ -83,5 +96,20 @@ class AliasCore extends ObjectModel
|
||||
$fields['active'] = (int)($this->active);
|
||||
return $fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is allow to know if a feature is used or active
|
||||
* @since 1.5.0.1
|
||||
* @return bool
|
||||
*/
|
||||
public static function isFeatureActive()
|
||||
{
|
||||
if (self::$feature_active === null)
|
||||
self::$feature_active = (bool)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
|
||||
SELECT COUNT(*)
|
||||
FROM `'._DB_PREFIX_.'alias`
|
||||
');
|
||||
return self::$feature_active;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -100,6 +100,8 @@ class AttributeCore extends ObjectModel
|
||||
*/
|
||||
public static function getAttributes($id_lang, $notNull = false)
|
||||
{
|
||||
if (!Combination::isFeatureActive())
|
||||
return array();
|
||||
return Db::getInstance()->ExecuteS('
|
||||
SELECT ag.*, agl.*, a.`id_attribute`, al.`name`, agl.`name` AS `attribute_group`
|
||||
FROM `'._DB_PREFIX_.'attribute_group` ag
|
||||
@@ -158,7 +160,7 @@ class AttributeCore extends ObjectModel
|
||||
*
|
||||
* @deprecated since 1.5.0
|
||||
* @param array &$arr
|
||||
* return bool
|
||||
* @return bool
|
||||
*/
|
||||
public static function updateQtyProduct(&$arr)
|
||||
{
|
||||
|
||||
@@ -123,6 +123,8 @@ class AttributeGroupCore extends ObjectModel
|
||||
*/
|
||||
public static function getAttributes($id_lang, $id_attribute_group)
|
||||
{
|
||||
if (!Combination::isFeatureActive())
|
||||
return array();
|
||||
return Db::getInstance()->ExecuteS('
|
||||
SELECT *
|
||||
FROM `'._DB_PREFIX_.'attribute` a
|
||||
@@ -139,6 +141,8 @@ class AttributeGroupCore extends ObjectModel
|
||||
*/
|
||||
public static function getAttributesGroups($id_lang)
|
||||
{
|
||||
if (!Combination::isFeatureActive())
|
||||
return array();
|
||||
return Db::getInstance()->ExecuteS('
|
||||
SELECT *
|
||||
FROM `'._DB_PREFIX_.'attribute_group` ag
|
||||
@@ -154,7 +158,8 @@ class AttributeGroupCore extends ObjectModel
|
||||
public function deleteSelection($selection)
|
||||
{
|
||||
/* Also delete Attributes */
|
||||
foreach ($selection AS $value) {
|
||||
foreach ($selection AS $value)
|
||||
{
|
||||
$obj = new AttributeGroup($value);
|
||||
if (!$obj->delete())
|
||||
return false;
|
||||
|
||||
+152
-95
@@ -254,6 +254,10 @@ class CartCore extends ObjectModel
|
||||
*/
|
||||
public function getDiscounts($lite = false, $refresh = false)
|
||||
{
|
||||
// if discounts are never used
|
||||
if (!Discount::isFeatureActive())
|
||||
return array();
|
||||
|
||||
if (!$this->id)
|
||||
return array();
|
||||
if (!$lite AND !$refresh AND isset(self::$_discounts[$this->id]))
|
||||
@@ -307,12 +311,13 @@ class CartCore extends ObjectModel
|
||||
|
||||
public function getDiscountsCustomer($id_discount)
|
||||
{
|
||||
$result = Db::getInstance()->ExecuteS('
|
||||
SELECT `id_discount`
|
||||
FROM `'._DB_PREFIX_.'cart_discount`
|
||||
WHERE `id_discount` = '.(int)($id_discount).' AND `id_cart` = '.(int)($this->id));
|
||||
if (!Discount::isFeatureActive())
|
||||
return 0;
|
||||
|
||||
return Db::getInstance()->NumRows();
|
||||
return Db::getInstance()->getValue('
|
||||
SELECT COUNT(*)
|
||||
FROM `'._DB_PREFIX_.'cart_discount`
|
||||
WHERE `id_discount` = '.(int)($id_discount).' AND `id_cart` = '.(int)($this->id));
|
||||
}
|
||||
|
||||
public function getLastProduct()
|
||||
@@ -353,37 +358,60 @@ class CartCore extends ObjectModel
|
||||
if (!$id_country)
|
||||
$id_country = Context::getContext()->country->id;
|
||||
|
||||
$sql = 'SELECT cp.`id_product_attribute`, cp.`id_product`, cu.`id_customization`, cp.`quantity` AS cart_quantity, cp.id_shop, cu.`quantity` AS customization_quantity, pl.`name`,
|
||||
// Build query
|
||||
$sql = array();
|
||||
// Build SELECT
|
||||
$sql['select'] = 'SELECT cp.`id_product_attribute`, cp.`id_product`, cp.`quantity` AS cart_quantity, cp.id_shop, pl.`name`,
|
||||
pl.`description_short`, pl.`available_now`, pl.`available_later`, p.`id_product`, p.`id_category_default`, p.`id_supplier`, p.`id_manufacturer`, p.`on_sale`, p.`ecotax`, p.`additional_shipping_cost`, p.`available_for_order`,
|
||||
p.`price`, p.`weight`, p.`width`, p.`height`, p.`depth`, p.`out_of_stock`, p.`active`, p.`date_add`, p.`date_upd`, IFNULL(pa.`minimal_quantity`, p.`minimal_quantity`) as minimal_quantity,
|
||||
t.`id_tax`, tl.`name` AS tax, t.`rate`, pa.`price` AS price_attribute, stock.quantity,
|
||||
pa.`ecotax` AS ecotax_attr, pl.`link_rewrite`, cl.`link_rewrite` AS category, CONCAT(cp.`id_product`, cp.`id_product_attribute`) AS unique_id,
|
||||
IF (IFNULL(pa.`reference`, \'\') = \'\', p.`reference`, pa.`reference`) AS reference,
|
||||
IF (IFNULL(pa.`supplier_reference`, \'\') = \'\', p.`supplier_reference`, pa.`supplier_reference`) AS supplier_reference,
|
||||
(p.`weight`+ pa.`weight`) weight_attribute,
|
||||
IF (IFNULL(pa.`ean13`, \'\') = \'\', p.`ean13`, pa.`ean13`) AS ean13, IF (IFNULL(pa.`upc`, \'\') = \'\', p.`upc`, pa.`upc`) AS upc,
|
||||
pai.`id_image` as pai_id_image
|
||||
FROM `'._DB_PREFIX_.'cart_product` cp
|
||||
LEFT JOIN `'._DB_PREFIX_.'product` p ON p.`id_product` = cp.`id_product`
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.(int)$this->id_lang.Context::getContext()->shop->sqlLang('pl').')
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON (pa.`id_product_attribute` = cp.`id_product_attribute`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON (p.`id_tax_rules_group` = tr.`id_tax_rules_group`
|
||||
AND tr.`id_country` = '.(int)$id_country.'
|
||||
AND tr.`id_state` = 0
|
||||
AND tr.`zipcode_from` = 0)
|
||||
LEFT JOIN `'._DB_PREFIX_.'tax` t ON (t.`id_tax` = tr.`id_tax`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'tax_lang` tl ON (t.`id_tax` = tl.`id_tax` AND tl.`id_lang` = '.(int)$this->id_lang.')
|
||||
LEFT JOIN `'._DB_PREFIX_.'customization` cu ON (p.`id_product` = cu.`id_product`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_attribute_image` pai ON (pai.`id_product_attribute` = pa.`id_product_attribute`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (p.`id_category_default` = cl.`id_category` AND cl.`id_lang` = '.(int)$this->id_lang.Context::getContext()->shop->sqlLang('cl').')
|
||||
'.Product::sqlStock('cp', 'cp').'
|
||||
WHERE cp.`id_cart` = '.(int)$this->id.'
|
||||
'.($id_product ? ' AND cp.`id_product` = '.(int)$id_product : '').'
|
||||
AND p.`id_product` IS NOT NULL
|
||||
GROUP BY unique_id
|
||||
ORDER BY cp.date_add ASC';
|
||||
p.`price`, p.`weight`, p.`width`, p.`height`, p.`depth`, p.`out_of_stock`, p.`active`, p.`date_add`, p.`date_upd`,
|
||||
t.`id_tax`, tl.`name` AS tax, t.`rate`, stock.quantity, pl.`link_rewrite`, cl.`link_rewrite` AS category, CONCAT(cp.`id_product`, cp.`id_product_attribute`) AS unique_id';
|
||||
// Build FROM
|
||||
$sql['from'] = 'FROM `'._DB_PREFIX_.'cart_product` cp';
|
||||
// Build JOIN
|
||||
$sql['join'] = 'LEFT JOIN `'._DB_PREFIX_.'product` p ON p.`id_product` = cp.`id_product`
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.(int)$this->id_lang.Context::getContext()->shop->sqlLang('pl').')
|
||||
LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON (p.`id_tax_rules_group` = tr.`id_tax_rules_group`
|
||||
AND tr.`id_country` = '.(int)$id_country.'
|
||||
AND tr.`id_state` = 0
|
||||
AND tr.`zipcode_from` = 0)
|
||||
LEFT JOIN `'._DB_PREFIX_.'tax` t ON (t.`id_tax` = tr.`id_tax`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'tax_lang` tl ON (t.`id_tax` = tl.`id_tax` AND tl.`id_lang` = '.(int)$this->id_lang.')
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (p.`id_category_default` = cl.`id_category` AND cl.`id_lang` = '.(int)$this->id_lang.Context::getContext()->shop->sqlLang('cl').')
|
||||
'.Product::sqlStock('cp', 'cp');
|
||||
// Build WHERE clauses
|
||||
$sql['where'] = '
|
||||
WHERE cp.`id_cart` = '.(int)$this->id.'
|
||||
'.($id_product ? ' AND cp.`id_product` = '.(int)$id_product : '').'
|
||||
AND p.`id_product` IS NOT NULL';
|
||||
// Build GROUP BY
|
||||
$sql['groupby'] = 'GROUP BY unique_id';
|
||||
// Build ORDER BY
|
||||
$sql['orderby'] = 'ORDER BY cp.date_add ASC';
|
||||
|
||||
if (Customization::isFeatureActive())
|
||||
{
|
||||
$sql['select'] .= ', cu.`id_customization`, cu.`quantity` AS customization_quantity';
|
||||
$sql['join'] .= 'LEFT JOIN `'._DB_PREFIX_.'customization` cu ON (p.`id_product` = cu.`id_product`)';
|
||||
}
|
||||
|
||||
$result = Db::getInstance()->ExecuteS($sql);
|
||||
if (Combination::isFeatureActive())
|
||||
{
|
||||
$sql['select'] .= ', pa.`price` AS price_attribute, pa.`ecotax` AS ecotax_attr,
|
||||
IF (IFNULL(pa.`reference`, \'\') = \'\', p.`reference`, pa.`reference`) AS reference,
|
||||
IF (IFNULL(pa.`supplier_reference`, \'\') = \'\', p.`supplier_reference`, pa.`supplier_reference`) AS supplier_reference,
|
||||
(p.`weight`+ pa.`weight`) weight_attribute,
|
||||
IF (IFNULL(pa.`ean13`, \'\') = \'\', p.`ean13`, pa.`ean13`) AS ean13, IF (IFNULL(pa.`upc`, \'\') = \'\', p.`upc`, pa.`upc`) AS upc,
|
||||
pai.`id_image` as pai_id_image, IFNULL(pa.`minimal_quantity`, p.`minimal_quantity`) as minimal_quantity, pa.`ecotax` AS ecotax_attr';
|
||||
$sql['join'] .= '
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON (pa.`id_product_attribute` = cp.`id_product_attribute`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_attribute_image` pai ON (pai.`id_product_attribute` = pa.`id_product_attribute`)
|
||||
';
|
||||
}
|
||||
else
|
||||
$sql['select'] .= ', p.`reference` AS reference, p.`supplier_reference` AS supplier_reference,
|
||||
p.`ean13`, p.`upc` AS upc, p.`minimal_quantity` AS minimal_quantity';
|
||||
|
||||
$result = Db::getInstance()->ExecuteS(Tools::buildQuery($sql));
|
||||
// Reset the cache before the following return, or else an empty cart will add dozens of queries
|
||||
|
||||
$productsIds = array();
|
||||
@@ -408,9 +436,7 @@ class CartCore extends ObjectModel
|
||||
// for compatibility with 1.2 themes
|
||||
$row['quantity'] = (int)($row['cart_quantity']);
|
||||
if (isset($row['id_product_attribute']) AND (int)$row['id_product_attribute'])
|
||||
{
|
||||
$row['weight'] = $row['weight_attribute'];
|
||||
}
|
||||
if ($this->_taxCalculationMethod == PS_TAX_EXC)
|
||||
{
|
||||
$row['price'] = Product::getPriceStatic((int)$row['id_product'], false, isset($row['id_product_attribute']) ? (int)($row['id_product_attribute']) : NULL, 2, NULL, false, true, (int)($row['cart_quantity']), false, ((int)($this->id_customer) ? (int)($this->id_customer) : NULL), (int)($this->id), ((int)($this->{Configuration::get('PS_TAX_ADDRESS_TYPE')}) ? (int)($this->{Configuration::get('PS_TAX_ADDRESS_TYPE')}) : NULL), $specificPriceOutput); // Here taxes are computed only once the quantity has been applied to the product price
|
||||
@@ -464,6 +490,8 @@ class CartCore extends ObjectModel
|
||||
|
||||
public static function cacheSomeAttributesLists($ipaList, $id_lang)
|
||||
{
|
||||
if (!Combination::isFeatureActive())
|
||||
return;
|
||||
$paImplode = array();
|
||||
foreach ($ipaList as $id_product_attribute)
|
||||
if ((int)$id_product_attribute AND !array_key_exists($id_product_attribute.'-'.$id_lang, self::$_attributesLists))
|
||||
@@ -532,7 +560,7 @@ class CartCore extends ObjectModel
|
||||
return Db::getInstance()->AutoExecute(_DB_PREFIX_.'cart_discount', array('id_discount' => (int)($id_discount), 'id_cart' => (int)($this->id)), 'INSERT');
|
||||
}
|
||||
|
||||
public function containsProduct($id_product, $id_product_attribute, $id_customization)
|
||||
public function containsProduct($id_product, $id_product_attribute = 0, $id_customization = false)
|
||||
{
|
||||
return Db::getInstance()->getRow('
|
||||
SELECT cp.`quantity`
|
||||
@@ -550,7 +578,7 @@ class CartCore extends ObjectModel
|
||||
* @param integer $id_product_attribute Attribute ID if needed
|
||||
* @param string $operator Indicate if quantity must be increased or decreased
|
||||
*/
|
||||
public function updateQty($quantity, $id_product, $id_product_attribute = NULL, $id_customization = false, $operator = 'up', Shop $shop = null)
|
||||
public function updateQty($quantity, $id_product, $id_product_attribute = null, $id_customization = false, $operator = 'up', Shop $shop = null)
|
||||
{
|
||||
if (!$shop)
|
||||
$shop = Context::getContext()->shop;
|
||||
@@ -581,7 +609,6 @@ class CartCore extends ObjectModel
|
||||
$result = $this->containsProduct($id_product, $id_product_attribute, (int)$id_customization);
|
||||
|
||||
/* Update quantity if product already exist */
|
||||
|
||||
if ($result)
|
||||
{
|
||||
if ($operator == 'up')
|
||||
@@ -740,7 +767,7 @@ class CartCore extends ObjectModel
|
||||
WHERE id_customization = '.(int)$customization['id_customization'].'
|
||||
AND type = '.(int)$customization['type'].'
|
||||
AND `index` = '.(int)$customization['index']);
|
||||
if ($type == _CUSTOMIZE_FILE_)
|
||||
if ($type == Product::CUSTOMIZE_FILE)
|
||||
{
|
||||
@unlink(_PS_UPLOAD_DIR_.$customization['value']);
|
||||
@unlink(_PS_UPLOAD_DIR_.$customization['value'].'_small');
|
||||
@@ -749,7 +776,8 @@ class CartCore extends ObjectModel
|
||||
}
|
||||
}
|
||||
$id_customization = $exising_customization[0]['id_customization'];
|
||||
}else
|
||||
}
|
||||
else
|
||||
{
|
||||
Db::getInstance()->Execute('INSERT INTO `'._DB_PREFIX_.'customization` (`id_cart`, `id_product`, `id_product_attribute`, `quantity`) VALUES ('.(int)($this->id).', '.(int)($id_product).', '.(int)($id_product_attribute).', '.(int)($quantity).')');
|
||||
$id_customization = Db::getInstance()->Insert_ID();
|
||||
@@ -819,12 +847,23 @@ class CartCore extends ObjectModel
|
||||
}
|
||||
|
||||
/* Get customization quantity */
|
||||
if (($result = Db::getInstance()->getRow('SELECT SUM(`quantity`) AS \'quantity\' FROM `'._DB_PREFIX_.'customization` WHERE `id_cart` = '.(int)($this->id).' AND `id_product` = '.(int)($id_product).' AND `id_product_attribute` = '.(int)($id_product_attribute))) === false)
|
||||
if (($result = Db::getInstance()->getRow('
|
||||
SELECT SUM(`quantity`) AS \'quantity\'
|
||||
FROM `'._DB_PREFIX_.'customization`
|
||||
WHERE `id_cart` = '.(int)$this->id.'
|
||||
AND `id_product` = '.(int)$id_product.'
|
||||
AND `id_product_attribute` = '.(int)$id_product_attribute)
|
||||
) === false)
|
||||
return false;
|
||||
|
||||
/* If the product still possesses customization it does not have to be deleted */
|
||||
if (Db::getInstance()->NumRows() AND (int)($result['quantity']))
|
||||
return Db::getInstance()->Execute('UPDATE `'._DB_PREFIX_.'cart_product` SET `quantity` = '.(int)($result['quantity']).' WHERE `id_cart` = '.(int)($this->id).' AND `id_product` = '.(int)($id_product).($id_product_attribute != NULL ? ' AND `id_product_attribute` = '.(int)($id_product_attribute) : ''));
|
||||
return Db::getInstance()->Execute('
|
||||
UPDATE `'._DB_PREFIX_.'cart_product`
|
||||
SET `quantity` = '.(int)($result['quantity']).'
|
||||
WHERE `id_cart` = '.(int)($this->id).'
|
||||
AND `id_product` = '.(int)($id_product).
|
||||
($id_product_attribute != NULL ? ' AND `id_product_attribute` = '.(int)($id_product_attribute) : ''));
|
||||
|
||||
/* Product deletion */
|
||||
if (Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'cart_product` WHERE `id_product` = '.(int)($id_product).($id_product_attribute != NULL ? ' AND `id_product_attribute` = '.(int)($id_product_attribute) : '').' AND `id_cart` = '.(int)($this->id)))
|
||||
@@ -922,6 +961,9 @@ class CartCore extends ObjectModel
|
||||
if (!in_array($type, array(Cart::ONLY_PRODUCTS, Cart::ONLY_DISCOUNTS, Cart::BOTH, Cart::BOTH_WITHOUT_SHIPPING, Cart::ONLY_SHIPPING, Cart::ONLY_WRAPPING, Cart::ONLY_PRODUCTS_WITHOUT_SHIPPING)))
|
||||
die(Tools::displayError());
|
||||
|
||||
// if discounts are never used
|
||||
if ($type == Cart::ONLY_DISCOUNTS && !Discount::isFeatureActive())
|
||||
return 0;
|
||||
// no shipping cost if is a cart with only virtuals products
|
||||
$virtual = $this->isVirtualCart();
|
||||
if ($virtual AND $type == Cart::ONLY_SHIPPING)
|
||||
@@ -940,7 +982,6 @@ class CartCore extends ObjectModel
|
||||
{
|
||||
if ($this->_taxCalculationMethod == PS_TAX_EXC)
|
||||
{
|
||||
|
||||
// Here taxes are computed only once the quantity has been applied to the product price
|
||||
$price = Product::getPriceStatic((int)$product['id_product'], false, (int)$product['id_product_attribute'], 2, NULL, false, true, $product['cart_quantity'], false, (int)$this->id_customer ? (int)$this->id_customer : NULL, (int)$this->id, ($this->{Configuration::get('PS_TAX_ADDRESS_TYPE')}));
|
||||
|
||||
@@ -981,45 +1022,48 @@ class CartCore extends ObjectModel
|
||||
if ($type != Cart::ONLY_PRODUCTS)
|
||||
{
|
||||
$discounts = array();
|
||||
/* Firstly get all discounts, looking for a free shipping one (in order to substract shipping fees to the total amount) */
|
||||
if ($discountIds = $this->getDiscounts(true))
|
||||
if (Discount::isFeatureActive())
|
||||
{
|
||||
foreach ($discountIds AS $id_discount)
|
||||
/* Firstly get all discounts, looking for a free shipping one (in order to substract shipping fees to the total amount) */
|
||||
if ($discountIds = $this->getDiscounts(true))
|
||||
{
|
||||
$discount = new Discount((int)($id_discount['id_discount']));
|
||||
if (Validate::isLoadedObject($discount))
|
||||
foreach ($discountIds AS $id_discount)
|
||||
{
|
||||
$discounts[] = $discount;
|
||||
if ($discount->id_discount_type == 3)
|
||||
foreach($products AS $product)
|
||||
{
|
||||
$categories = Discount::getCategories($discount->id);
|
||||
if (count($categories) AND Product::idIsOnCategoryId($product['id_product'], $categories))
|
||||
$discount = new Discount((int)($id_discount['id_discount']));
|
||||
if (Validate::isLoadedObject($discount))
|
||||
{
|
||||
$discounts[] = $discount;
|
||||
if ($discount->id_discount_type == Discount::FREE_SHIPPING)
|
||||
foreach($products AS $product)
|
||||
{
|
||||
if($type == Cart::ONLY_DISCOUNTS)
|
||||
$order_total -= $shipping_fees;
|
||||
$shipping_fees = 0;
|
||||
break;
|
||||
$categories = Discount::getCategories($discount->id);
|
||||
if (count($categories) AND Product::idIsOnCategoryId($product['id_product'], $categories))
|
||||
{
|
||||
if($type == Cart::ONLY_DISCOUNTS)
|
||||
$order_total -= $shipping_fees;
|
||||
$shipping_fees = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Secondly applying all vouchers to the correct amount */
|
||||
$shrunk = false;
|
||||
foreach ($discounts AS $discount)
|
||||
if ($discount->id_discount_type != Discount::FREE_SHIPPING)
|
||||
{
|
||||
$order_total -= Tools::ps_round((float)($discount->getValue(sizeof($discounts), $order_total_products, $shipping_fees, $this->id, (int)($withTaxes))), 2);
|
||||
if ($discount->id_discount_type == Discount::AMOUNT)
|
||||
if (in_array($discount->behavior_not_exhausted, array(1,2)))
|
||||
$shrunk = true;
|
||||
}
|
||||
|
||||
$order_total_discount = 0;
|
||||
if ($shrunk AND $order_total < (-$wrapping_fees - $order_total_products - $shipping_fees))
|
||||
$order_total_discount = -$wrapping_fees - $order_total_products - $shipping_fees;
|
||||
else
|
||||
$order_total_discount = $order_total;
|
||||
}
|
||||
/* Secondly applying all vouchers to the correct amount */
|
||||
$shrunk = false;
|
||||
foreach ($discounts AS $discount)
|
||||
if ($discount->id_discount_type != 3)
|
||||
{
|
||||
$order_total -= Tools::ps_round((float)($discount->getValue(sizeof($discounts), $order_total_products, $shipping_fees, $this->id, (int)($withTaxes))), 2);
|
||||
if ($discount->id_discount_type == 2)
|
||||
if (in_array($discount->behavior_not_exhausted, array(1,2)))
|
||||
$shrunk = true;
|
||||
}
|
||||
|
||||
$order_total_discount = 0;
|
||||
if ($shrunk AND $order_total < (-$wrapping_fees - $order_total_products - $shipping_fees))
|
||||
$order_total_discount = -$wrapping_fees - $order_total_products - $shipping_fees;
|
||||
else
|
||||
$order_total_discount = $order_total;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1048,10 +1092,13 @@ class CartCore extends ObjectModel
|
||||
|
||||
// Checking discounts in cart
|
||||
$products = $this->getProducts();
|
||||
$discounts = $this->getDiscounts(true);
|
||||
if (Discount::isFeatureActive())
|
||||
$discounts = $this->getDiscounts(true);
|
||||
else
|
||||
$discounts = null;
|
||||
if ($discounts)
|
||||
foreach ($discounts AS $id_discount)
|
||||
if ($id_discount['id_discount_type'] == 3)
|
||||
if ($id_discount['id_discount_type'] == Discount::FREE_SHIPPING)
|
||||
{
|
||||
if ($id_discount['minimal'] > 0)
|
||||
{
|
||||
@@ -1281,20 +1328,25 @@ class CartCore extends ObjectModel
|
||||
{
|
||||
if (!isset(self::$_totalWeight[$this->id]))
|
||||
{
|
||||
$result = Db::getInstance()->getRow('
|
||||
SELECT SUM((p.`weight` + pa.`weight`) * cp.`quantity`) as nb
|
||||
FROM `'._DB_PREFIX_.'cart_product` cp
|
||||
LEFT JOIN `'._DB_PREFIX_.'product` p ON cp.`id_product` = p.`id_product`
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON cp.`id_product_attribute` = pa.`id_product_attribute`
|
||||
WHERE (cp.`id_product_attribute` IS NOT NULL AND cp.`id_product_attribute` != 0)
|
||||
AND cp.`id_cart` = '.(int)($this->id));
|
||||
$result2 = Db::getInstance()->getRow('
|
||||
if (Combination::isFeatureActive())
|
||||
$weight_product_with_attribute = Db::getInstance()->getValue('
|
||||
SELECT SUM((p.`weight` + pa.`weight`) * cp.`quantity`) as nb
|
||||
FROM `'._DB_PREFIX_.'cart_product` cp
|
||||
LEFT JOIN `'._DB_PREFIX_.'product` p ON (cp.`id_product` = p.`id_product`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON (cp.`id_product_attribute` = pa.`id_product_attribute`)
|
||||
WHERE (cp.`id_product_attribute` IS NOT NULL AND cp.`id_product_attribute` != 0)
|
||||
AND cp.`id_cart` = '.(int)($this->id));
|
||||
else
|
||||
$weight_product_with_attribute = 0;
|
||||
|
||||
$weight_product_without_attribute = Db::getInstance()->getValue('
|
||||
SELECT SUM(p.`weight` * cp.`quantity`) as nb
|
||||
FROM `'._DB_PREFIX_.'cart_product` cp
|
||||
LEFT JOIN `'._DB_PREFIX_.'product` p ON cp.`id_product` = p.`id_product`
|
||||
LEFT JOIN `'._DB_PREFIX_.'product` p ON (cp.`id_product` = p.`id_product`)
|
||||
WHERE (cp.`id_product_attribute` IS NULL OR cp.`id_product_attribute` = 0)
|
||||
AND cp.`id_cart` = '.(int)($this->id));
|
||||
self::$_totalWeight[$this->id] = round((float)($result['nb']) + (float)($result2['nb']), 3);
|
||||
|
||||
self::$_totalWeight[$this->id] = round((float)$weight_product_with_attribute + (float)$weight_product_without_attribute, 3);
|
||||
}
|
||||
return self::$_totalWeight[$this->id];
|
||||
}
|
||||
@@ -1317,7 +1369,7 @@ class CartCore extends ObjectModel
|
||||
return Tools::displayError('This voucher has already been used or is disabled.');
|
||||
if (!$discountObj->quantity)
|
||||
return Tools::displayError('This voucher has expired (usage limit attained).');
|
||||
if ($discountObj->id_discount_type == 2 AND $this->id_currency != $discountObj->id_currency)
|
||||
if ($discountObj->id_discount_type == Discount::AMOUNT AND $this->id_currency != $discountObj->id_currency)
|
||||
return Tools::displayError('This voucher can only be used in the following currency:').'
|
||||
'.Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('SELECT `name` FROM `'._DB_PREFIX_.'currency` WHERE id_currency = '.(int)$discountObj->id_currency);
|
||||
if ($checkCartDiscount
|
||||
@@ -1412,7 +1464,7 @@ class CartCore extends ObjectModel
|
||||
$discounts = $this->getDiscounts();
|
||||
$total_free_ship = $free_ship - ($this->getOrderTotal(true, Cart::ONLY_PRODUCTS) + $this->getOrderTotal(true, Cart::ONLY_DISCOUNTS));
|
||||
foreach ($discounts as $discount)
|
||||
if ($discount['id_discount_type'] == 3)
|
||||
if ($discount['id_discount_type'] == Discount::FREE_SHIPPING)
|
||||
{
|
||||
$total_free_ship = 0;
|
||||
break;
|
||||
@@ -1473,6 +1525,9 @@ class CartCore extends ObjectModel
|
||||
*/
|
||||
public function isVirtualCart()
|
||||
{
|
||||
if (!ProductDownload::isFeatureActive())
|
||||
return false;
|
||||
|
||||
if (!isset(self::$_isVirtualCart[$this->id]))
|
||||
{
|
||||
$products = $this->getProducts();
|
||||
@@ -1575,14 +1630,16 @@ class CartCore extends ObjectModel
|
||||
*/
|
||||
public function getProductCustomization($id_product, $type = null, $not_in_cart = false)
|
||||
{
|
||||
if (!Customization::isFeatureActive())
|
||||
return array();
|
||||
$result = Db::getInstance()->ExecuteS('
|
||||
SELECT cu.id_customization, cd.index, cd.value, cd.type, cu.in_cart, cu.quantity FROM `'._DB_PREFIX_.'customization` cu
|
||||
LEFT JOIN `'._DB_PREFIX_.'customized_data` cd
|
||||
ON cu.`id_customization` = cd.`id_customization`
|
||||
SELECT cu.id_customization, cd.index, cd.value, cd.type, cu.in_cart, cu.quantity
|
||||
FROM `'._DB_PREFIX_.'customization` cu
|
||||
LEFT JOIN `'._DB_PREFIX_.'customized_data` cd ON (cu.`id_customization` = cd.`id_customization`)
|
||||
WHERE cu.id_cart = '.(int)$this->id.'
|
||||
AND cu.id_product = '.(int)$id_product.
|
||||
($type === _CUSTOMIZE_FILE_ ? ' AND type = '.(int)_CUSTOMIZE_FILE_ : '').
|
||||
($type === _CUSTOMIZE_TEXTFIELD_ ? ' AND type = '.(int)_CUSTOMIZE_TEXTFIELD_ : '').
|
||||
($type === Product::CUSTOMIZE_FILE ? ' AND type = '.(int)Product::CUSTOMIZE_FILE : '').
|
||||
($type === Product::CUSTOMIZE_TEXTFIELD ? ' AND type = '.(int)Product::CUSTOMIZE_TEXTFIELD : '').
|
||||
($not_in_cart ? ' AND in_cart = 0' : '')
|
||||
);
|
||||
return $result;
|
||||
|
||||
@@ -562,10 +562,8 @@ class CategoryCore extends ObjectModel
|
||||
$sql .= ' LIMIT 0, '.(int)($randomNumberProducts);
|
||||
}
|
||||
else
|
||||
{
|
||||
$sql .= ' ORDER BY '.(isset($orderByPrefix) ? $orderByPrefix.'.' : '').'`'.pSQL($orderBy).'` '.pSQL($orderWay).'
|
||||
LIMIT '.(((int)($p) - 1) * (int)($n)).','.(int)($n);
|
||||
}
|
||||
|
||||
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($sql);
|
||||
if ($orderBy == 'orderprice')
|
||||
|
||||
+24
-1
@@ -158,7 +158,7 @@ class CombinationCore extends ObjectModel
|
||||
FROM `'._DB_PREFIX_.'product_attribute_image`
|
||||
WHERE `id_product_attribute` = '.(int)($this->id).'
|
||||
');
|
||||
}
|
||||
}
|
||||
|
||||
public function setWsImages($values)
|
||||
{
|
||||
@@ -175,6 +175,29 @@ class CombinationCore extends ObjectModel
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is allow to know if a feature is active
|
||||
* @since 1.5.0.1
|
||||
* @return bool
|
||||
*/
|
||||
public static function isFeatureActive()
|
||||
{
|
||||
return Configuration::get('PS_COMBINATION_FEATURE_ACTIVE');
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is allow to know if a feature is in use
|
||||
* @since 1.5.0.1
|
||||
* @return bool
|
||||
*/
|
||||
public static function isActuallyUsed()
|
||||
{
|
||||
return (bool)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
|
||||
SELECT COUNT(*)
|
||||
FROM `ps_product_attribute`
|
||||
');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -481,6 +481,9 @@ class CustomerCore extends ObjectModel
|
||||
|
||||
public static function getGroupsStatic($id_customer)
|
||||
{
|
||||
if (!Group::isFeatureActive())
|
||||
return array(1);
|
||||
|
||||
$groups = array();
|
||||
$result = Db::getInstance()->ExecuteS('
|
||||
SELECT cg.`id_group`
|
||||
@@ -511,6 +514,9 @@ class CustomerCore extends ObjectModel
|
||||
|
||||
public static function getDefaultGroupId($id_customer)
|
||||
{
|
||||
if (!Group::isFeatureActive())
|
||||
return 1;
|
||||
|
||||
if (!isset(self::$_defaultGroupId[(int)($id_customer)]))
|
||||
self::$_defaultGroupId[(int)($id_customer)] = Db::getInstance()->getValue('SELECT `id_default_group` FROM `'._DB_PREFIX_.'customer` WHERE `id_customer` = '.(int)$id_customer);
|
||||
return self::$_defaultGroupId[(int)($id_customer)];
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
|
||||
class CustomizationCore
|
||||
{
|
||||
protected static $feature_active = null;
|
||||
|
||||
public static function getReturnedCustomizations($id_order)
|
||||
{
|
||||
@@ -94,9 +95,7 @@ class CustomizationCore
|
||||
WHERE `id_customization` IN ('.$in_values.')');
|
||||
|
||||
foreach($results as $row)
|
||||
{
|
||||
$quantities[$row['id_customization']] = $row;
|
||||
}
|
||||
}
|
||||
|
||||
return $quantities;
|
||||
@@ -114,12 +113,25 @@ class CustomizationCore
|
||||
);
|
||||
|
||||
foreach($results as $row)
|
||||
{
|
||||
$quantity[$row['id_product']][$row['product_attribute_id']] = $row['quantity'];
|
||||
}
|
||||
|
||||
return $quantity;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is allow to know if a feature is used or active
|
||||
* @since 1.5.0.1
|
||||
* @return bool
|
||||
*/
|
||||
public static function isFeatureActive()
|
||||
{
|
||||
if (self::$feature_active === null)
|
||||
self::$feature_active = (Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
|
||||
SELECT COUNT(*)
|
||||
FROM `'._DB_PREFIX_.'customization_field`
|
||||
') > 1);
|
||||
return self::$feature_active;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
+141
-40
@@ -101,6 +101,7 @@ class DiscountCore extends ObjectModel
|
||||
protected $table = 'discount';
|
||||
protected $identifier = 'id_discount';
|
||||
|
||||
protected static $feature_active = null;
|
||||
|
||||
protected $webserviceParameters = array(
|
||||
'fields' => array(
|
||||
@@ -126,8 +127,10 @@ class DiscountCore extends ObjectModel
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
|
||||
const PERCENT = 1;
|
||||
const AMOUNT = 2;
|
||||
const FREE_SHIPPING = 3;
|
||||
|
||||
public function getFields()
|
||||
{
|
||||
$this->validateFields();
|
||||
@@ -211,38 +214,67 @@ class DiscountCore extends ObjectModel
|
||||
*/
|
||||
public static function getIdByName($discountName)
|
||||
{
|
||||
if (!Validate::isDiscountName($discountName))
|
||||
if (!self::isFeatureActive())
|
||||
return 0;
|
||||
|
||||
if (!Validate::isDiscountName($discountName))
|
||||
die(Tools::displayError());
|
||||
|
||||
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
|
||||
SELECT `id_discount`
|
||||
FROM `'._DB_PREFIX_.'discount`
|
||||
WHERE `name` = \''.pSQL($discountName).'\'');
|
||||
return isset($result['id_discount']) ? $result['id_discount'] : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return customer discounts
|
||||
*
|
||||
* @param integer $id_lang Language ID
|
||||
* @param boolean $id_customer Customer ID
|
||||
* @return array Discounts
|
||||
*/
|
||||
static public function getCustomerDiscounts($id_lang, $id_customer, $active = false, $includeGenericOnes = true, $stock = false, Cart $cart = null)
|
||||
*
|
||||
* This method allow to get the customer discount
|
||||
* @param int $id_lang
|
||||
* @param int $id_customer
|
||||
* @param bool $active
|
||||
* @param bool $includeGenericOnes include the discount available for all customers
|
||||
* @param bool $hasStock
|
||||
* @param Cart $cart
|
||||
*/
|
||||
public static function getCustomerDiscounts($id_lang, $id_customer, $active = false, $includeGenericOnes = true, $hasStock = false, Cart $cart = null)
|
||||
{
|
||||
if (!$cart)
|
||||
if (!self::isFeatureActive())
|
||||
return array();
|
||||
|
||||
if (!$cart)
|
||||
$cart = Context::getContext()->cart;
|
||||
$res = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
|
||||
|
||||
$sql = '
|
||||
SELECT d.*, dtl.`name` AS `type`, dl.`description`
|
||||
FROM `'._DB_PREFIX_.'discount` d
|
||||
LEFT JOIN `'._DB_PREFIX_.'discount_lang` dl ON (d.`id_discount` = dl.`id_discount` AND dl.`id_lang` = '.(int)($id_lang).')
|
||||
LEFT JOIN `'._DB_PREFIX_.'discount_type` dt ON dt.`id_discount_type` = d.`id_discount_type`
|
||||
LEFT JOIN `'._DB_PREFIX_.'discount_type_lang` dtl ON (dt.`id_discount_type` = dtl.`id_discount_type` AND dtl.`id_lang` = '.(int)($id_lang).')
|
||||
WHERE (`id_customer` = '.(int)($id_customer).'
|
||||
OR `id_group` IN (SELECT `id_group` FROM `'._DB_PREFIX_.'customer_group` WHERE `id_customer` = '.(int)($id_customer).')'.
|
||||
($includeGenericOnes ? ' OR (`id_customer` = 0 AND `id_group` = 0)' : '').')
|
||||
'.($active ? ' AND d.`active` = 1' : '').'
|
||||
'.($stock ? ' AND d.`quantity` != 0' : ''));
|
||||
WHERE (d.`id_customer` = '.(int)$id_customer.'
|
||||
';
|
||||
|
||||
// Group clause
|
||||
if (Group::isFeatureActive())
|
||||
$sql .= 'OR d.`id_group` IN (
|
||||
SELECT `id_group`
|
||||
FROM `'._DB_PREFIX_.'customer_group` cg
|
||||
WHERE cg.`id_customer` = '.(int)$id_customer.'
|
||||
)';
|
||||
else
|
||||
$sql .= 'OR d.`id_group` = 1';
|
||||
|
||||
if ($includeGenericOnes)
|
||||
$sql .= 'OR (d.`id_customer` = 0 AND d.`id_group` = 0)';
|
||||
|
||||
$sql .= ')'; // close parenthsis openned befor d.`id_customer`
|
||||
|
||||
if ($active)
|
||||
$sql .= ' AND d.`active` = 1';
|
||||
|
||||
if ($hasStock)
|
||||
$sql .= ' AND d.`quantity` != 0';
|
||||
|
||||
$res = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($sql);
|
||||
|
||||
foreach ($res as &$discount)
|
||||
if ($discount['quantity_per_user'])
|
||||
@@ -257,14 +289,19 @@ class DiscountCore extends ObjectModel
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param int $id_customer
|
||||
* @return bool
|
||||
*/
|
||||
public function usedByCustomer($id_customer)
|
||||
{
|
||||
$sql = 'SELECT COUNT(*)
|
||||
FROM `'._DB_PREFIX_.'order_discount` od
|
||||
LEFT JOIN `'._DB_PREFIX_.'orders` o ON (od.`id_order` = o.`id_order`)
|
||||
WHERE od.`id_discount` = '.(int)$this->id.'
|
||||
AND o.`id_customer` = '.(int)$id_customer;
|
||||
return Db::getInstance()->getValue($sql);
|
||||
return (bool)Db::getInstance()->getValue('
|
||||
SELECT COUNT(*)
|
||||
FROM `'._DB_PREFIX_.'order_discount` od
|
||||
LEFT JOIN `'._DB_PREFIX_.'orders` o ON (od.`id_order` = o.`id_order`)
|
||||
WHERE od.`id_discount` = '.(int)$this->id.'
|
||||
AND o.`id_customer` = '.(int)$id_customer);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -276,6 +313,9 @@ class DiscountCore extends ObjectModel
|
||||
*/
|
||||
public function getValue($nb_discounts = 0, $order_total_products = 0, $shipping_fees = 0, $idCart = false, $useTax = true, Currency $currency = null, Shop $shop = null)
|
||||
{
|
||||
if (!self::isFeatureActive())
|
||||
return 0;
|
||||
|
||||
if (!$currency)
|
||||
$currency = Context::getContext()->currency;
|
||||
if (!$shop)
|
||||
@@ -308,7 +348,7 @@ class DiscountCore extends ObjectModel
|
||||
switch ($this->id_discount_type)
|
||||
{
|
||||
/* Relative value (% of the order total) */
|
||||
case 1:
|
||||
case Discount::PERCENT:
|
||||
$amount = 0;
|
||||
$percentage = $this->value / 100;
|
||||
foreach ($products AS $product)
|
||||
@@ -318,7 +358,7 @@ class DiscountCore extends ObjectModel
|
||||
return $amount;
|
||||
|
||||
/* Absolute value */
|
||||
case 2:
|
||||
case Discount::AMOUNT:
|
||||
// An "absolute" voucher is available in one currency only
|
||||
$currency = ((int)$cart->id_currency ? Currency::getCurrencyInstance($cart->id_currency) : $currency);
|
||||
if ($this->id_currency != $currency->id)
|
||||
@@ -337,7 +377,7 @@ class DiscountCore extends ObjectModel
|
||||
return $value;
|
||||
|
||||
/* Free shipping (does not return a value but a special code) */
|
||||
case 3:
|
||||
case Discount::FREE_SHIPPING:
|
||||
return '!';
|
||||
}
|
||||
return 0;
|
||||
@@ -366,7 +406,9 @@ class DiscountCore extends ObjectModel
|
||||
}
|
||||
elseif (!is_array($categories) OR !sizeof($categories))
|
||||
return false;
|
||||
Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'discount_category` WHERE `id_discount`='.(int)($this->id));
|
||||
Db::getInstance()->Execute('
|
||||
DELETE FROM `'._DB_PREFIX_.'discount_category`
|
||||
WHERE `id_discount`='.(int)$this->id);
|
||||
foreach($categories AS $category)
|
||||
{
|
||||
Db::getInstance()->ExecuteS('
|
||||
@@ -374,13 +416,22 @@ class DiscountCore extends ObjectModel
|
||||
FROM `'._DB_PREFIX_.'discount_category`
|
||||
WHERE `id_discount`='.(int)($this->id).' AND `id_category`='.(int)($category));
|
||||
if (Db::getInstance()->NumRows() == 0)
|
||||
Db::getInstance()->Execute('INSERT INTO `'._DB_PREFIX_.'discount_category` (`id_discount`, `id_category`) VALUES('.(int)($this->id).','.(int)($category).')');
|
||||
Db::getInstance()->Execute('
|
||||
INSERT INTO `'._DB_PREFIX_.'discount_category` (`id_discount`, `id_category`)
|
||||
VALUES('.(int)($this->id).','.(int)($category).')');
|
||||
}
|
||||
}
|
||||
|
||||
public static function discountExists($discountName, $id_discount = 0)
|
||||
{
|
||||
return Db::getInstance()->getRow('SELECT `id_discount` FROM '._DB_PREFIX_.'discount WHERE `name` LIKE \''.pSQL($discountName).'\' AND `id_discount` != '.(int)($id_discount));
|
||||
if (!self::isFeatureActive())
|
||||
return false;
|
||||
|
||||
return (bool)Db::getInstance()->getValue('
|
||||
SELECT `id_discount`
|
||||
FROM `'._DB_PREFIX_.'discount`
|
||||
WHERE `name` LIKE \''.pSQL($discountName).'\'
|
||||
AND `id_discount` != '.(int)$id_discount);
|
||||
}
|
||||
|
||||
public static function createOrderDiscount($order, $productList, $qtyList, $name, $shipping_cost = false, $id_category = 0, $subcategory = 0)
|
||||
@@ -394,9 +445,9 @@ class DiscountCore extends ObjectModel
|
||||
$total_tmp = $total;
|
||||
foreach ($discounts as $discount)
|
||||
{
|
||||
if ($discount['id_discount_type'] == 1)
|
||||
if ($discount['id_discount_type'] == Discount::PERCENT)
|
||||
$total -= $total_tmp * ($discount['value'] / 100);
|
||||
elseif ($discount['id_discount_type'] == 2)
|
||||
elseif ($discount['id_discount_type'] == Discount::AMOUNT)
|
||||
$total -= ($discount['value'] * ($total_tmp / $order->total_products_wt));
|
||||
}
|
||||
if ($shipping_cost)
|
||||
@@ -404,7 +455,7 @@ class DiscountCore extends ObjectModel
|
||||
|
||||
// create discount
|
||||
$voucher = new Discount();
|
||||
$voucher->id_discount_type = 2;
|
||||
$voucher->id_discount_type = Discount::AMOUNT;
|
||||
foreach ($languages as $language)
|
||||
$voucher->description[$language['id_lang']] = strval($name).(int)($order->id);
|
||||
$voucher->value = (float)($total);
|
||||
@@ -444,18 +495,52 @@ class DiscountCore extends ObjectModel
|
||||
return ''; // return a string because it's a display method
|
||||
}
|
||||
|
||||
public static function getVouchersToCartDisplay($id_lang, $id_customer)
|
||||
/**
|
||||
*
|
||||
* This method allows to get the vouchers can be shown in order page
|
||||
* @param int $id_lang
|
||||
* @param int $id_customer
|
||||
* @return array contains discount
|
||||
*/
|
||||
public static function getVouchersToCartDisplay($id_lang, $id_customer = 0)
|
||||
{
|
||||
return Db::getInstance()->ExecuteS('
|
||||
if (!self::isFeatureActive())
|
||||
return array();
|
||||
|
||||
$sql = '
|
||||
SELECT d.`name`, dl.`description`, d.`id_discount`
|
||||
FROM `'._DB_PREFIX_.'discount` d
|
||||
LEFT JOIN `'._DB_PREFIX_.'discount_lang` dl ON (d.`id_discount` = dl.`id_discount`)
|
||||
WHERE d.`active` = 1
|
||||
AND d.`date_from` <= \''.pSQL(date('Y-m-d H:i:s')).'\' AND d.`date_to` >= \''.pSQL(date('Y-m-d H:i:s')).'\'
|
||||
AND dl.`id_lang` = '.(int)($id_lang).'
|
||||
AND d.`cart_display` = 1 AND d.`quantity` > 0
|
||||
AND ((d.`id_customer` = 0 AND d.`id_group` = 0) '.($id_customer ? 'OR (d.`id_customer` = '.$id_customer.'
|
||||
OR d.`id_group` IN (SELECT `id_group` FROM `'._DB_PREFIX_.'customer_group` WHERE `id_customer` = '.(int)($id_customer).')))' : 'OR d.`id_group` = 1)'));
|
||||
AND dl.`id_lang` = '.(int)$id_lang.'
|
||||
AND d.`cart_display` = 1
|
||||
AND d.`quantity` > 0
|
||||
AND (
|
||||
(d.`id_customer` = 0 AND d.`id_group` = 0)';
|
||||
|
||||
if ($id_customer)
|
||||
{
|
||||
$sql .= ' OR (';
|
||||
// adding id_customer clause
|
||||
$sql .= 'd.`id_customer` = '.(int)$id_customer;
|
||||
if (Group::isFeatureActive())
|
||||
$sql .= '
|
||||
OR d.`id_group` IN (
|
||||
SELECT cg.`id_group`
|
||||
FROM `'._DB_PREFIX_.'customer_group` cg
|
||||
WHERE cg.`id_customer` = '.(int)$id_customer.'
|
||||
)';
|
||||
else
|
||||
$sql .= ' OR d.`id_group` = 1';
|
||||
$sql .= ')';
|
||||
}
|
||||
else
|
||||
$sql .= ' OR d.`id_group` = 1';
|
||||
|
||||
$sql .= ')'; // close parenthesis openned above
|
||||
|
||||
return Db::getInstance()->ExecuteS($sql);
|
||||
}
|
||||
|
||||
public static function deleteByIdCustomer($id_customer)
|
||||
@@ -486,4 +571,20 @@ class DiscountCore extends ObjectModel
|
||||
{
|
||||
return Db::getInstance()->getRow('SELECT * FROM `'._DB_PREFIX_.'discount` WHERE `id_discount` = '.(int)$id_discount);
|
||||
}
|
||||
|
||||
/**
|
||||
* This metohd is allow to know if a feature is used or active
|
||||
* @since 1.5.0.1
|
||||
* @return bool
|
||||
*/
|
||||
public static function isFeatureActive()
|
||||
{
|
||||
if (self::$feature_active === null)
|
||||
self::$feature_active = (Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
|
||||
SELECT COUNT(*)
|
||||
FROM `'._DB_PREFIX_.'discount`
|
||||
WHERE `active` = 1
|
||||
') > 1);
|
||||
return self::$feature_active;
|
||||
}
|
||||
}
|
||||
@@ -428,10 +428,8 @@ class DispatcherCore
|
||||
$controller_files = scandir(_PS_ROOT_DIR_.DIRECTORY_SEPARATOR.'controllers');
|
||||
$controllers = array();
|
||||
foreach ($controller_files as $controller_filename)
|
||||
{
|
||||
if (substr($controller_filename, -14, 14) == 'Controller.php')
|
||||
$controllers[strtolower(substr($controller_filename, 0, -14))] = basename($controller_filename, '.php');
|
||||
}
|
||||
|
||||
// add default controller
|
||||
$controllers['index'] = 'IndexController';
|
||||
|
||||
@@ -187,6 +187,9 @@ class FeatureCore extends ObjectModel
|
||||
|
||||
public static function getFeaturesForComparison($list_ids_product, $id_lang)
|
||||
{
|
||||
if (!Feature::isFeatureActive())
|
||||
return false;
|
||||
|
||||
$ids = '';
|
||||
foreach($list_ids_product as $id)
|
||||
$ids .= (int)($id).',';
|
||||
@@ -206,5 +209,15 @@ class FeatureCore extends ObjectModel
|
||||
GROUP BY f.`id_feature`
|
||||
ORDER BY nb DESC');
|
||||
}
|
||||
|
||||
/**
|
||||
* This metohd is allow to know if a feature is used or active
|
||||
* @since 1.5.0.1
|
||||
* @return bool
|
||||
*/
|
||||
public static function isFeatureActive()
|
||||
{
|
||||
return Configuration::get('PS_FEATURE_FEATURE_ACTIVE');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -637,6 +637,9 @@ class FrontControllerCore
|
||||
|
||||
public static function getCurrentCustomerGroups()
|
||||
{
|
||||
if (!Group::isFeatureActive())
|
||||
return array();
|
||||
|
||||
$context = Context::getContext();
|
||||
if (!$context->customer->id)
|
||||
return array();
|
||||
|
||||
+18
-2
@@ -59,6 +59,7 @@ class GroupCore extends ObjectModel
|
||||
|
||||
protected static $_cacheReduction = array();
|
||||
protected static $_groupPriceDisplayMethod = array();
|
||||
protected static $feature_active = null;
|
||||
|
||||
protected $webserviceParameters = array();
|
||||
|
||||
@@ -127,7 +128,7 @@ class GroupCore extends ObjectModel
|
||||
self::$_cacheReduction['group'][$id_group] = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
|
||||
SELECT `reduction`
|
||||
FROM `'._DB_PREFIX_.'group`
|
||||
WHERE `id_group` = '.$id_group);
|
||||
WHERE `id_group` = '.(int)$id_group);
|
||||
}
|
||||
return self::$_cacheReduction['group'][$id_group];
|
||||
}
|
||||
@@ -138,7 +139,7 @@ class GroupCore extends ObjectModel
|
||||
self::$_groupPriceDisplayMethod[$id_group] = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
|
||||
SELECT `price_display_method`
|
||||
FROM `'._DB_PREFIX_.'group`
|
||||
WHERE `id_group` = '.(int)($id_group));
|
||||
WHERE `id_group` = '.(int)$id_group);
|
||||
return self::$_groupPriceDisplayMethod[$id_group];
|
||||
}
|
||||
|
||||
@@ -167,6 +168,21 @@ class GroupCore extends ObjectModel
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is allow to know if a feature is used or active
|
||||
* @since 1.5.0.1
|
||||
* @return bool
|
||||
*/
|
||||
public static function isFeatureActive()
|
||||
{
|
||||
if (self::$feature_active === null)
|
||||
self::$feature_active = (Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
|
||||
SELECT COUNT(*)
|
||||
FROM `'._DB_PREFIX_.'group`
|
||||
') > 1);
|
||||
return self::$feature_active;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -118,9 +118,9 @@ class OrderSlipCore extends ObjectModel
|
||||
$realProductPrice = $resTab[$key]['product_price'];
|
||||
foreach ($discounts as $discount)
|
||||
{
|
||||
if ($discount['id_discount_type'] == 1)
|
||||
if ($discount['id_discount_type'] == Discount::PERCENT)
|
||||
$resTab[$key]['product_price'] -= $realProductPrice * ($discount['value'] / 100);
|
||||
elseif ($discount['id_discount_type'] == 2)
|
||||
elseif ($discount['id_discount_type'] == Discount::AMOUNT)
|
||||
$resTab[$key]['product_price'] -= (($discount['value'] * ($product['product_price_wt'] / $order->total_products_wt)) / (1.00 + ($product['tax_rate'] / 100)));
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -787,11 +787,11 @@ class PDFCore extends PDF_PageGroupCore
|
||||
$customizationGroup = $customizedData['datas'];
|
||||
$nb_images = 0;
|
||||
|
||||
if (array_key_exists(_CUSTOMIZE_FILE_, $customizationGroup))
|
||||
$nb_images = sizeof($customizationGroup[_CUSTOMIZE_FILE_]);
|
||||
if (array_key_exists(Product::CUSTOMIZE_FILE, $customizationGroup))
|
||||
$nb_images = sizeof($customizationGroup[Product::CUSTOMIZE_FILE]);
|
||||
|
||||
if (array_key_exists(_CUSTOMIZE_TEXTFIELD_, $customizationGroup))
|
||||
foreach($customizationGroup[_CUSTOMIZE_TEXTFIELD_] as $customization)
|
||||
if (array_key_exists(Product::CUSTOMIZE_TEXTFIELD, $customizationGroup))
|
||||
foreach($customizationGroup[Product::CUSTOMIZE_TEXTFIELD] as $customization)
|
||||
if(!empty($customization['name'])) $custoLabel .= '- '.$customization['name'].': '.$customization['value']."\n";
|
||||
|
||||
|
||||
|
||||
@@ -30,9 +30,13 @@ class PackCore extends Product
|
||||
protected static $cachePackItems = array();
|
||||
protected static $cacheIsPack = array();
|
||||
protected static $cacheIsPacked = array();
|
||||
protected static $feature_active = null;
|
||||
|
||||
public static function isPack($id_product)
|
||||
{
|
||||
if (!self::isFeatureActive())
|
||||
return false;
|
||||
|
||||
if (!array_key_exists($id_product, self::$cacheIsPack))
|
||||
{
|
||||
$result = Db::getInstance()->getValue('SELECT COUNT(*) FROM '._DB_PREFIX_.'pack WHERE id_product_pack = '.(int)($id_product));
|
||||
@@ -43,6 +47,9 @@ class PackCore extends Product
|
||||
|
||||
public static function isPacked($id_product)
|
||||
{
|
||||
if (!self::isFeatureActive())
|
||||
return false;
|
||||
|
||||
if (!array_key_exists($id_product, self::$cacheIsPacked))
|
||||
{
|
||||
$result = Db::getInstance()->getValue('SELECT COUNT(*) FROM '._DB_PREFIX_.'pack WHERE id_product_item = '.(int)($id_product));
|
||||
@@ -63,6 +70,9 @@ class PackCore extends Product
|
||||
|
||||
public static function getItems($id_product, $id_lang)
|
||||
{
|
||||
if (!self::isFeatureActive())
|
||||
return array();
|
||||
|
||||
if (array_key_exists($id_product, self::$cachePackItems))
|
||||
return self::$cachePackItems[$id_product];
|
||||
$result = Db::getInstance()->ExecuteS('SELECT id_product_item, quantity FROM '._DB_PREFIX_.'pack where id_product_pack = '.(int)($id_product));
|
||||
@@ -79,6 +89,9 @@ class PackCore extends Product
|
||||
|
||||
public static function isInStock($id_product)
|
||||
{
|
||||
if (!self::isFeatureActive())
|
||||
return true;
|
||||
|
||||
$items = self::getItems((int)($id_product), Configuration::get('PS_LANG_DEFAULT'));
|
||||
foreach ($items AS $item)
|
||||
if ($item->quantity < $item->pack_quantity AND !$item->isAvailableWhenOutOfStock((int)($item->out_of_stock)))
|
||||
@@ -88,6 +101,9 @@ class PackCore extends Product
|
||||
|
||||
public static function getItemTable($id_product, $id_lang, $full = false)
|
||||
{
|
||||
if (!self::isFeatureActive())
|
||||
return array();
|
||||
|
||||
$sql = 'SELECT p.*, pl.*, i.`id_image`, il.`legend`, t.`rate`, cl.`name` AS category_default, a.quantity AS pack_quantity
|
||||
FROM `'._DB_PREFIX_.'pack` a
|
||||
LEFT JOIN `'._DB_PREFIX_.'product` p ON p.id_product = a.id_product_item
|
||||
@@ -114,6 +130,9 @@ class PackCore extends Product
|
||||
|
||||
public static function getPacksTable($id_product, $id_lang, $full = false, $limit = NULL)
|
||||
{
|
||||
if (!self::isFeatureActive())
|
||||
return array();
|
||||
|
||||
$packs = Db::getInstance()->getValue('
|
||||
SELECT GROUP_CONCAT(a.`id_product_pack`)
|
||||
FROM `'._DB_PREFIX_.'pack` a
|
||||
@@ -177,5 +196,20 @@ class PackCore extends Product
|
||||
// If return query result, a non-pack product will return false
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is allow to know if a feature is used or active
|
||||
* @since 1.5.0.1
|
||||
* @return bool
|
||||
*/
|
||||
public static function isFeatureActive()
|
||||
{
|
||||
if (self::$feature_active === null)
|
||||
self::$feature_active = (bool)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
|
||||
SELECT COUNT(*)
|
||||
FROM `'._DB_PREFIX_.'pack`
|
||||
');
|
||||
return self::$feature_active;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -256,12 +256,12 @@ abstract class PaymentModuleCore extends Module
|
||||
$customizationText = '';
|
||||
foreach ($customizedDatas[$product['id_product']][$product['id_product_attribute']] AS $customization)
|
||||
{
|
||||
if (isset($customization['datas'][_CUSTOMIZE_TEXTFIELD_]))
|
||||
foreach ($customization['datas'][_CUSTOMIZE_TEXTFIELD_] AS $text)
|
||||
if (isset($customization['datas'][Product::CUSTOMIZE_TEXTFIELD]))
|
||||
foreach ($customization['datas'][Product::CUSTOMIZE_TEXTFIELD] AS $text)
|
||||
$customizationText .= $text['name'].':'.' '.$text['value'].'<br />';
|
||||
|
||||
if (isset($customization['datas'][_CUSTOMIZE_FILE_]))
|
||||
$customizationText .= sizeof($customization['datas'][_CUSTOMIZE_FILE_]) .' '. Tools::displayError('image(s)').'<br />';
|
||||
if (isset($customization['datas'][Product::CUSTOMIZE_FILE]))
|
||||
$customizationText .= sizeof($customization['datas'][Product::CUSTOMIZE_FILE]) .' '. Tools::displayError('image(s)').'<br />';
|
||||
|
||||
$customizationText .= '---<br />';
|
||||
}
|
||||
@@ -301,13 +301,13 @@ abstract class PaymentModuleCore extends Module
|
||||
{
|
||||
$objDiscount = new Discount((int)$discount['id_discount']);
|
||||
$value = $objDiscount->getValue(sizeof($discounts), $cart->getOrderTotal(true, Cart::ONLY_PRODUCTS), $order->total_shipping, $cart->id);
|
||||
if ($objDiscount->id_discount_type == 2 AND in_array($objDiscount->behavior_not_exhausted, array(1,2)))
|
||||
if ($objDiscount->id_discount_type == Discount::AMOUNT AND in_array($objDiscount->behavior_not_exhausted, array(1,2)))
|
||||
$shrunk = true;
|
||||
|
||||
if ($shrunk AND ($total_discount_value + $value) > ($order->total_products_wt + $order->total_shipping + $order->total_wrapping))
|
||||
{
|
||||
$amount_to_add = ($order->total_products_wt + $order->total_shipping + $order->total_wrapping) - $total_discount_value;
|
||||
if ($objDiscount->id_discount_type == 2 AND $objDiscount->behavior_not_exhausted == 2)
|
||||
if ($objDiscount->id_discount_type == Discount::AMOUNT AND $objDiscount->behavior_not_exhausted == 2)
|
||||
{
|
||||
$voucher = new Discount();
|
||||
foreach ($objDiscount AS $key => $discountValue)
|
||||
|
||||
+201
-122
@@ -25,7 +25,13 @@
|
||||
* 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
|
||||
@@ -298,6 +304,9 @@ class ProductCore extends ObjectModel
|
||||
),
|
||||
);
|
||||
|
||||
const CUSTOMIZE_FILE = 0;
|
||||
const CUSTOMIZE_TEXTFIELD = 1;
|
||||
|
||||
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);
|
||||
@@ -503,12 +512,15 @@ class ProductCore extends ObjectModel
|
||||
*/
|
||||
public static function getDefaultAttribute($id_product, $minimumQuantity = 0)
|
||||
{
|
||||
if (!Combination::isFeatureActive())
|
||||
return 0;
|
||||
|
||||
$sql = 'SELECT pa.id_product_attribute
|
||||
FROM '._DB_PREFIX_.'product_attribute pa'
|
||||
.($minimumQuantity > 0 ? Product::sqlStock('pa', 'pa') : '').
|
||||
' WHERE pa.default_on = 1 '
|
||||
.($minimumQuantity > 0 ? ' AND stock.quantity >= '.(int)$minimumQuantity : '').
|
||||
' AND pa.id_product = '.(int)$id_product;
|
||||
.($minimumQuantity > 0 ? ' AND stock.quantity >= '.(int)$minimumQuantity : '').
|
||||
' AND pa.id_product = '.(int)$id_product;
|
||||
$result = Db::getInstance()->getValue($sql);
|
||||
|
||||
if (!$result)
|
||||
@@ -517,7 +529,7 @@ class ProductCore extends ObjectModel
|
||||
FROM '._DB_PREFIX_.'product_attribute pa'
|
||||
.($minimumQuantity > 0 ? Product::sqlStock('pa', 'pa') : '').
|
||||
' WHERE pa.id_product = '.(int)$id_product
|
||||
.($minimumQuantity > 0 ? ' AND stock.quantity >= '.(int)$minimumQuantity : '');
|
||||
.($minimumQuantity > 0 ? ' AND stock.quantity >= '.(int)$minimumQuantity : '');
|
||||
$result = Db::getInstance()->getValue($sql);
|
||||
}
|
||||
|
||||
@@ -526,7 +538,7 @@ class ProductCore extends ObjectModel
|
||||
$sql = 'SELECT id_product_attribute
|
||||
FROM '._DB_PREFIX_.'product_attribute
|
||||
WHERE `default_on` = 1
|
||||
AND id_product = '.(int)$id_product;
|
||||
AND id_product = '.(int)$id_product;
|
||||
$result = Db::getInstance()->getValue($sql);
|
||||
}
|
||||
|
||||
@@ -754,10 +766,10 @@ class ProductCore extends ObjectModel
|
||||
$status = true;
|
||||
if ($result)
|
||||
foreach($result as $row)
|
||||
{
|
||||
$image = new Image($row['id_image']);
|
||||
$status &= $image->delete();
|
||||
}
|
||||
{
|
||||
$image = new Image($row['id_image']);
|
||||
$status &= $image->delete();
|
||||
}
|
||||
return $status;
|
||||
}
|
||||
|
||||
@@ -843,6 +855,8 @@ class ProductCore extends ObjectModel
|
||||
|
||||
public function productAttributeExists($attributesList, $currentProductAttribute = false)
|
||||
{
|
||||
if (!Combination::isFeatureActive())
|
||||
return false;
|
||||
$result = Db::getInstance()->ExecuteS('SELECT pac.`id_attribute`, pac.`id_product_attribute`
|
||||
FROM `'._DB_PREFIX_.'product_attribute` pa
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_attribute_combination` pac ON (pac.`id_product_attribute` = pa.`id_product_attribute`)
|
||||
@@ -1117,8 +1131,10 @@ class ProductCore extends ObjectModel
|
||||
*/
|
||||
public function deleteAttachments()
|
||||
{
|
||||
return Db::getInstance()->Execute('DELETE FROM '._DB_PREFIX_.'product_attachment WHERE id_product = '.(int)($this->id));
|
||||
}
|
||||
return Db::getInstance()->Execute('
|
||||
DELETE FROM `'._DB_PREFIX_.'product_attachment`
|
||||
WHERE `id_product` = '.(int)$this->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete product customizations
|
||||
@@ -1275,6 +1291,8 @@ class ProductCore extends ObjectModel
|
||||
*/
|
||||
public function getAttributeCombinaisons($id_lang)
|
||||
{
|
||||
if (!Combination::isFeatureActive())
|
||||
return array();
|
||||
$sql = 'SELECT pa.*, ag.`id_attribute_group`, ag.`is_color_group`, agl.`name` AS group_name, al.`name` AS attribute_name, a.`id_attribute`, pa.`unit_price_impact`, stock.quantity
|
||||
FROM `'._DB_PREFIX_.'product_attribute` pa
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_attribute_combination` pac ON pac.`id_product_attribute` = pa.`id_product_attribute`
|
||||
@@ -1290,6 +1308,8 @@ class ProductCore extends ObjectModel
|
||||
|
||||
public function getCombinationImages($id_lang)
|
||||
{
|
||||
if (!Combination::isFeatureActive())
|
||||
return false;
|
||||
if (!$productAttributes = Db::getInstance()->ExecuteS('SELECT `id_product_attribute` FROM `'._DB_PREFIX_.'product_attribute` WHERE `id_product` = '.(int)($this->id)))
|
||||
return false;
|
||||
$ids = array();
|
||||
@@ -1315,6 +1335,8 @@ class ProductCore extends ObjectModel
|
||||
*/
|
||||
public function hasAttributes()
|
||||
{
|
||||
if (!Combination::isFeatureActive())
|
||||
return 0;
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
|
||||
SELECT COUNT(`id_product_attribute`)
|
||||
FROM `'._DB_PREFIX_.'product_attribute`
|
||||
@@ -1354,41 +1376,53 @@ class ProductCore extends ObjectModel
|
||||
FROM `'._DB_PREFIX_.'product` p
|
||||
'.$context->shop->sqlAsso('product', 'p').'
|
||||
WHERE `active` = 1
|
||||
AND DATEDIFF(p.`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
|
||||
AND p.`id_product` IN (
|
||||
SELECT cp.`id_product`
|
||||
FROM `'._DB_PREFIX_.'category_group` cg
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_category` = cg.`id_category`)
|
||||
WHERE cg.`id_group` '.$sqlGroups.'
|
||||
)';
|
||||
return (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql);
|
||||
}
|
||||
|
||||
$sql = 'SELECT p.*, pl.`description`, pl.`description_short`, pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`, p.`ean13`, p.`upc`,
|
||||
i.`id_image`, il.`legend`, t.`rate`, m.`name` AS manufacturer_name, DATEDIFF(p.`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 AS new,
|
||||
(p.`price` * ((100 + (t.`rate`))/100)) AS orderprice, pa.id_product_attribute
|
||||
FROM `'._DB_PREFIX_.'product` p
|
||||
'.$context->shop->sqlAsso('product', 'p').'
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.(int)$id_lang.$context->shop->sqlLang('pl').')
|
||||
LEFT OUTER JOIN `'._DB_PREFIX_.'product_attribute` pa ON (p.`id_product` = pa.`id_product` AND `default_on` = 1)
|
||||
LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product` AND i.`cover` = 1)
|
||||
LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$id_lang.')
|
||||
LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON (p.`id_tax_rules_group` = tr.`id_tax_rules_group`
|
||||
AND tr.`id_country` = '.(int)$context->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`)
|
||||
WHERE p.`active` = 1
|
||||
AND DATEDIFF(p.`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
|
||||
AND p.`id_product` IN (
|
||||
SELECT cp.`id_product`
|
||||
FROM `'._DB_PREFIX_.'category_group` cg
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_category` = cg.`id_category`)
|
||||
WHERE cg.`id_group` '.$sqlGroups.'
|
||||
)
|
||||
ORDER BY '.(isset($orderByPrefix) ? pSQL($orderByPrefix).'.' : '').'`'.pSQL($orderBy).'` '.pSQL($orderWay).'
|
||||
LIMIT '.(int)($pageNumber * $nbProducts).', '.(int)($nbProducts);
|
||||
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($sql);
|
||||
)';
|
||||
return (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql);
|
||||
}
|
||||
|
||||
$sql = array();
|
||||
$sql['select'] = '
|
||||
SELECT p.*, pl.`description`, pl.`description_short`, pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`, p.`ean13`, p.`upc`,
|
||||
i.`id_image`, il.`legend`, t.`rate`, m.`name` AS manufacturer_name, DATEDIFF(p.`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 AS new,
|
||||
(p.`price` * ((100 + (t.`rate`))/100)) AS orderprice
|
||||
';
|
||||
$sql['from'] = 'FROM `'._DB_PREFIX_.'product` p';
|
||||
$sql['join'] = $context->shop->sqlAsso('product', 'p').'
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.(int)$id_lang.$context->shop->sqlLang('pl').')
|
||||
LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product` AND i.`cover` = 1)
|
||||
LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$id_lang.')
|
||||
LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON (p.`id_tax_rules_group` = tr.`id_tax_rules_group`
|
||||
AND tr.`id_country` = '.(int)$context->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`)
|
||||
';
|
||||
$sql['where'] = '
|
||||
WHERE p.`active` = 1
|
||||
AND DATEDIFF(p.`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
|
||||
AND p.`id_product` IN (
|
||||
SELECT cp.`id_product`
|
||||
FROM `'._DB_PREFIX_.'category_group` cg
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_category` = cg.`id_category`)
|
||||
WHERE cg.`id_group` '.$sqlGroups.'
|
||||
)
|
||||
';
|
||||
$sql['orderby'] = 'ORDER BY '.(isset($orderByPrefix) ? pSQL($orderByPrefix).'.' : '').'`'.pSQL($orderBy).'` '.pSQL($orderWay);
|
||||
$sql['limit'] = 'LIMIT '.(int)($pageNumber * $nbProducts).', '.(int)($nbProducts);
|
||||
|
||||
if (Combination::isFeatureActive())
|
||||
{
|
||||
$sql['select'] .= ', pa.id_product_attribute';
|
||||
$sql['join'] .= 'LEFT OUTER JOIN `'._DB_PREFIX_.'product_attribute` pa ON (p.`id_product` = pa.`id_product` AND `default_on` = 1)';
|
||||
}
|
||||
|
||||
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(Tools::buildQuery($sql));
|
||||
|
||||
if ($orderBy == 'price')
|
||||
Tools::orderbyPrice($result, $orderWay);
|
||||
@@ -1404,7 +1438,7 @@ class ProductCore extends ObjectModel
|
||||
return Product::getProductsProperties((int)$id_lang, $result);
|
||||
}
|
||||
|
||||
static protected function _getProductIdByDate($beginning, $ending, Context $context = null)
|
||||
protected static function _getProductIdByDate($beginning, $ending, Context $context = null)
|
||||
{
|
||||
if (!$context)
|
||||
$context = Context::getContext();
|
||||
@@ -1692,10 +1726,10 @@ class ProductCore extends ObjectModel
|
||||
FROM `'._DB_PREFIX_.'cart_product`
|
||||
WHERE `id_product` = '.(int)($id_product).'
|
||||
AND `id_cart` = '.(int)($id_cart).' '.$condition
|
||||
);
|
||||
);
|
||||
|
||||
$cart_quantity = self::$_cart_quantity[$cache_name];
|
||||
}
|
||||
}
|
||||
}
|
||||
$quantity = ($id_cart AND $cart_quantity) ? $cart_quantity : $quantity;
|
||||
$id_currency = (int)(Validate::isLoadedObject($context->currency) ? $context->currency->id : Configuration::get('PS_CURRENCY_DEFAULT'));
|
||||
@@ -1773,14 +1807,25 @@ class ProductCore extends ObjectModel
|
||||
// fetch price & attribute price
|
||||
$cacheId2 = $id_product.'-'.$id_product_attribute;
|
||||
if (!isset(self::$_pricesLevel2[$cacheId2]))
|
||||
self::$_pricesLevel2[$cacheId2] = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
|
||||
SELECT p.`price`,
|
||||
'.($id_product_attribute ? 'pa.`price`' : 'IFNULL((SELECT pa.price FROM `'._DB_PREFIX_.'product_attribute` pa WHERE id_product = '.(int)($id_product).' AND default_on = 1), 0)').' AS attribute_price,
|
||||
p.`ecotax`
|
||||
'.($id_product_attribute ? ', pa.`ecotax` AS attribute_ecotax' : '').'
|
||||
FROM `'._DB_PREFIX_.'product` p
|
||||
'.($id_product_attribute ? 'LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON pa.`id_product_attribute` = '.(int)($id_product_attribute) : '').'
|
||||
WHERE p.`id_product` = '.(int)($id_product));
|
||||
{
|
||||
$sql = array();
|
||||
$sql['select'] = 'SELECT p.`price`, p.`ecotax`';
|
||||
$sql['from'] = 'FROM `'._DB_PREFIX_.'product` p';
|
||||
$sql['where'] = 'WHERE p.`id_product` = '.(int)($id_product);
|
||||
|
||||
if (Combination::isFeatureActive())
|
||||
{
|
||||
if ($id_product_attribute)
|
||||
{
|
||||
$sql['select'] .= ', pa.`price` AS attribute_price';
|
||||
$sql['join'] = 'LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON (pa.`id_product_attribute` = '.(int)($id_product_attribute).')';
|
||||
}
|
||||
else
|
||||
$sql['select'] .= ', IFNULL((SELECT pa.price FROM `'._DB_PREFIX_.'product_attribute` pa WHERE id_product = '.(int)($id_product).' AND default_on = 1), 0) AS attribute_price';
|
||||
}
|
||||
|
||||
self::$_pricesLevel2[$cacheId2] = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow(Tools::buildQuery($sql));
|
||||
}
|
||||
$result = self::$_pricesLevel2[$cacheId2];
|
||||
|
||||
$price = (float)(!$specific_price OR $specific_price['price'] == 0) ? $result['price'] : $specific_price['price'];
|
||||
@@ -1851,9 +1896,9 @@ class ProductCore extends ObjectModel
|
||||
{
|
||||
// reinit the tax manager for ecotax handling
|
||||
$tax_manager = TaxManagerFactory::getManager(
|
||||
$address,
|
||||
(int)Configuration::get('PS_ECOTAX_TAX_RULES_GROUP_ID')
|
||||
);
|
||||
$address,
|
||||
(int)Configuration::get('PS_ECOTAX_TAX_RULES_GROUP_ID')
|
||||
);
|
||||
$ecotax_tax_calculator = $tax_manager->getTaxCalculator();
|
||||
$price += $ecotax_tax_calculator->addTaxes($ecotax);
|
||||
}
|
||||
@@ -1912,6 +1957,8 @@ class ProductCore extends ObjectModel
|
||||
|
||||
public function getIdProductAttributeMostExpensive()
|
||||
{
|
||||
if (!Combination::isFeatureActive())
|
||||
return 0;
|
||||
$row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
|
||||
SELECT `id_product_attribute`
|
||||
FROM `'._DB_PREFIX_.'product_attribute`
|
||||
@@ -1926,25 +1973,6 @@ class ProductCore extends ObjectModel
|
||||
return self::getPriceStatic((int)($this->id), !$notax, $id_product_attribute, 6, NULL, false, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get product price for display
|
||||
* Also display currency sign and reduction
|
||||
*
|
||||
* @deprecated as of 1.4.2
|
||||
* @param array $params Product price, reduction...
|
||||
* @param object $smarty Smarty object
|
||||
* @return string Product price fully formated in customer currency
|
||||
*/
|
||||
static function productPrice($params, &$smarty)
|
||||
{
|
||||
Tools::displayAsDeprecated();
|
||||
$ret = '';
|
||||
if (isset($params['p']['reduction']) AND $params['p']['reduction'])
|
||||
$ret .= '<span class="discounted">'.Tools::displayPrice($params['p']['price_without_reduction'], $smarty->ps_currency).'</span><br />';
|
||||
$ret .= Tools::displayPrice($params['p']['price'], $smarty->ps_currency);
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display price with right format and currency
|
||||
*
|
||||
@@ -2130,8 +2158,8 @@ class ProductCore extends ObjectModel
|
||||
$sql = 'SELECT quantity
|
||||
FROM '._DB_PREFIX_.'stock
|
||||
WHERE id_product = '.$this->id.'
|
||||
AND id_product_attribute = '.(int)$id_product_attribute
|
||||
.$context->shop->sqlRestriction(Shop::SHARE_STOCK);
|
||||
AND id_product_attribute = '.(int)$id_product_attribute.
|
||||
$context->shop->sqlRestriction(Shop::SHARE_STOCK);
|
||||
|
||||
self::$cacheStock[$this->id][$id_product_attribute] = (int)Db::getInstance()->getValue($sql);
|
||||
}
|
||||
@@ -2251,6 +2279,8 @@ class ProductCore extends ObjectModel
|
||||
*/
|
||||
public function getAttributesGroups($id_lang)
|
||||
{
|
||||
if (!Combination::isFeatureActive())
|
||||
return array();
|
||||
$sql = 'SELECT ag.`id_attribute_group`, ag.`is_color_group`, agl.`name` AS group_name, agl.`public_name` AS public_group_name, a.`id_attribute`, al.`name` AS attribute_name,
|
||||
a.`color` AS attribute_color, pa.`id_product_attribute`, stock.quantity, pa.`price`, pa.`ecotax`, pa.`weight`, pa.`default_on`, pa.`reference`, pa.`unit_price_impact`, pa.`minimal_quantity`
|
||||
FROM `'._DB_PREFIX_.'product_attribute` pa
|
||||
@@ -2402,6 +2432,8 @@ class ProductCore extends ObjectModel
|
||||
|
||||
public static function getFeaturesStatic($id_product)
|
||||
{
|
||||
if (!Feature::isFeatureActive())
|
||||
return array();
|
||||
if (!array_key_exists($id_product, self::$_cacheFeatures))
|
||||
self::$_cacheFeatures[$id_product] = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
|
||||
SELECT id_feature, id_product, id_feature_value
|
||||
@@ -2412,6 +2444,9 @@ class ProductCore extends ObjectModel
|
||||
|
||||
public static function cacheProductsFeatures($productIds)
|
||||
{
|
||||
if (!Feature::isFeatureActive())
|
||||
return;
|
||||
|
||||
$productImplode = array();
|
||||
foreach ($productIds as $id_product)
|
||||
if ((int)$id_product AND !array_key_exists($id_product, self::$_cacheFeatures))
|
||||
@@ -2433,6 +2468,9 @@ class ProductCore extends ObjectModel
|
||||
|
||||
public static function cacheFrontFeatures($productIds, $id_lang)
|
||||
{
|
||||
if (!Feature::isFeatureActive())
|
||||
return;
|
||||
|
||||
$productImplode = array();
|
||||
foreach ($productIds as $id_product)
|
||||
if ((int)$id_product AND !array_key_exists($id_product.'-'.$id_lang, self::$_cacheFeatures))
|
||||
@@ -2467,21 +2505,33 @@ class ProductCore extends ObjectModel
|
||||
if (!$context)
|
||||
$context = Context::getContext();
|
||||
|
||||
$sql = 'SELECT p.`id_product`, pl.`name`, p.`active`, p.`reference`, m.`name` AS manufacturer_name, stock.quantity
|
||||
FROM `'._DB_PREFIX_.'category_product` cp
|
||||
LEFT JOIN `'._DB_PREFIX_.'product` p ON p.`id_product` = cp.`id_product`
|
||||
'.$context->shop->sqlAsso('product', 'p').'
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.(int)$id_lang.$context->shop->sqlLang('pl').')
|
||||
LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON m.`id_manufacturer` = p.`id_manufacturer`
|
||||
$sql = array();
|
||||
$sql['select'] = 'SELECT p.`id_product`, pl.`name`, p.`active`, p.`reference`, m.`name` AS manufacturer_name, stock.`quantity`';
|
||||
$sql['from'] = 'FROM `'._DB_PREFIX_.'category_product` cp';
|
||||
$sql['join'] = '
|
||||
LEFT JOIN `'._DB_PREFIX_.'product` p ON p.`id_product` = cp.`id_product`
|
||||
'.$context->shop->sqlAsso('product', 'p').'
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.(int)$id_lang.$context->shop->sqlLang('pl').')
|
||||
LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON m.`id_manufacturer` = p.`id_manufacturer`
|
||||
';
|
||||
$sql['where'] = '
|
||||
WHERE pl.`name` LIKE \'%'.pSQL($query).'%\'
|
||||
OR p.`reference` LIKE \'%'.pSQL($query).'%\'
|
||||
OR p.`supplier_reference` LIKE \'%'.pSQL($query).'%\'';
|
||||
$sql['groupby'] = 'GROUP BY `id_product`';
|
||||
$sql['orderby'] = 'ORDER BY pl.`name` ASC';
|
||||
|
||||
if (Combination::isFeatureActive())
|
||||
{
|
||||
$sql['join'] .= '
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON pa.`id_product` = p.`id_product`
|
||||
'.Product::sqlStock('p', 'pa', false, $context->shop).'
|
||||
WHERE pl.`name` LIKE \'%'.pSQL($query).'%\'
|
||||
OR p.`reference` LIKE \'%'.pSQL($query).'%\'
|
||||
OR p.`supplier_reference` LIKE \'%'.pSQL($query).'%\'
|
||||
OR pa.`reference` LIKE \'%'.pSQL($query).'%\'
|
||||
GROUP BY `id_product`
|
||||
ORDER BY pl.`name` ASC';
|
||||
$result = Db::getInstance()->ExecuteS($sql);
|
||||
'.Product::sqlStock('p', 'pa', false, $context->shop);
|
||||
$sql['where'] .= 'OR pa.`reference` LIKE \'%'.pSQL($query).'%\'';
|
||||
}
|
||||
else
|
||||
$sql['join'] .= Product::sqlStock('p', null, false, $context->shop);
|
||||
|
||||
$result = Db::getInstance()->ExecuteS(Tools::buildQuery($sql));
|
||||
|
||||
if (!$result)
|
||||
return false;
|
||||
@@ -2540,7 +2590,7 @@ class ProductCore extends ObjectModel
|
||||
/**
|
||||
* Get product attribute image associations
|
||||
* @param integer $id_product_attribute
|
||||
* @return boolean
|
||||
* @return array
|
||||
*/
|
||||
public static function _getAttributeImageAssociations($id_product_attribute)
|
||||
{
|
||||
@@ -2645,8 +2695,11 @@ class ProductCore extends ObjectModel
|
||||
return $return;
|
||||
}
|
||||
|
||||
static protected function _getCustomizationFieldsNLabels($productId)
|
||||
protected static function _getCustomizationFieldsNLabels($productId)
|
||||
{
|
||||
if (!Customization::isFeatureActive())
|
||||
return false;
|
||||
|
||||
$customizations = array();
|
||||
if (($customizations['fields'] = Db::getInstance()->ExecuteS('
|
||||
SELECT `id_customization_field`, `type`, `required`
|
||||
@@ -2747,12 +2800,12 @@ class ProductCore extends ObjectModel
|
||||
|
||||
// Product::getDefaultAttribute is only called if id_product_attribute is missing from the SQL query at the origin of it: consider adding it in order to avoid unnecessary queries
|
||||
$row['allow_oosp'] = Product::isAvailableWhenOutOfStock($row['out_of_stock']);
|
||||
if ((!isset($row['id_product_attribute']) OR !$row['id_product_attribute'])
|
||||
if (Combination::isFeatureActive() AND (!isset($row['id_product_attribute']) OR !$row['id_product_attribute'])
|
||||
AND ((isset($row['cache_default_attribute']) AND ($ipa_default = $row['cache_default_attribute']) !== NULL)
|
||||
OR ($ipa_default = Product::getDefaultAttribute($row['id_product'], !$row['allow_oosp'])))
|
||||
)
|
||||
$row['id_product_attribute'] = $ipa_default;
|
||||
if (!isset($row['id_product_attribute']))
|
||||
if (!Combination::isFeatureActive() OR !isset($row['id_product_attribute']))
|
||||
$row['id_product_attribute'] = 0;
|
||||
|
||||
// Tax
|
||||
@@ -2820,6 +2873,8 @@ class ProductCore extends ObjectModel
|
||||
*/
|
||||
public static function getFrontFeaturesStatic($id_lang, $id_product)
|
||||
{
|
||||
if (!Feature::isFeatureActive())
|
||||
return array();
|
||||
if (!array_key_exists($id_product.'-'.$id_lang, self::$_frontFeaturesCache))
|
||||
{
|
||||
self::$_frontFeaturesCache[$id_product.'-'.$id_lang] = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
|
||||
@@ -2858,6 +2913,9 @@ class ProductCore extends ObjectModel
|
||||
|
||||
public static function getAllCustomizedDatas($id_cart, $id_lang = null, $only_in_cart = true)
|
||||
{
|
||||
if (!Customization::isFeatureActive())
|
||||
return false;
|
||||
|
||||
// No need to query if there isn't any real cart!
|
||||
if (!$id_cart)
|
||||
return false;
|
||||
@@ -2889,6 +2947,9 @@ class ProductCore extends ObjectModel
|
||||
|
||||
public static function addCustomizationPrice(&$products, &$customizedDatas)
|
||||
{
|
||||
if (!Customization::isFeatureActive())
|
||||
return;
|
||||
|
||||
foreach ($products AS &$productUpdate)
|
||||
{
|
||||
$customizationQuantity = 0;
|
||||
@@ -2936,26 +2997,26 @@ class ProductCore extends ObjectModel
|
||||
|
||||
protected function _deleteOldLabels()
|
||||
{
|
||||
$max = array(_CUSTOMIZE_FILE_ => (int)(Tools::getValue('uploadable_files')), _CUSTOMIZE_TEXTFIELD_ => (int)(Tools::getValue('text_fields')));
|
||||
$max = array(Product::CUSTOMIZE_FILE => (int)(Tools::getValue('uploadable_files')), Product::CUSTOMIZE_TEXTFIELD => (int)(Tools::getValue('text_fields')));
|
||||
/* Get customization field ids */
|
||||
if (($result = Db::getInstance()->ExecuteS('SELECT `id_customization_field`, `type` FROM `'._DB_PREFIX_.'customization_field` WHERE `id_product` = '.(int)($this->id).' ORDER BY `id_customization_field`')) === false)
|
||||
return false;
|
||||
if (empty($result))
|
||||
return true;
|
||||
$customizationFields = array(_CUSTOMIZE_FILE_ => array(), _CUSTOMIZE_TEXTFIELD_ => array());
|
||||
$customizationFields = array(Product::CUSTOMIZE_FILE => array(), Product::CUSTOMIZE_TEXTFIELD => array());
|
||||
foreach ($result AS $row)
|
||||
$customizationFields[(int)($row['type'])][] = (int)($row['id_customization_field']);
|
||||
$extraFile = count($customizationFields[_CUSTOMIZE_FILE_]) - $max[_CUSTOMIZE_FILE_];
|
||||
$extraText = count($customizationFields[_CUSTOMIZE_TEXTFIELD_]) - $max[_CUSTOMIZE_TEXTFIELD_];
|
||||
$extraFile = count($customizationFields[Product::CUSTOMIZE_FILE]) - $max[Product::CUSTOMIZE_FILE];
|
||||
$extraText = count($customizationFields[Product::CUSTOMIZE_TEXTFIELD]) - $max[Product::CUSTOMIZE_TEXTFIELD];
|
||||
|
||||
/* If too much inside the database, deletion */
|
||||
if ($extraFile > 0 AND count($customizationFields[_CUSTOMIZE_FILE_]) - $extraFile >= 0 AND
|
||||
(!Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'customization_field` WHERE `id_product` = '.(int)($this->id).' AND `type` = '._CUSTOMIZE_FILE_.' AND `id_customization_field` >= '.(int)($customizationFields[_CUSTOMIZE_FILE_][count($customizationFields[_CUSTOMIZE_FILE_]) - $extraFile]))
|
||||
if ($extraFile > 0 AND count($customizationFields[Product::CUSTOMIZE_FILE]) - $extraFile >= 0 AND
|
||||
(!Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'customization_field` WHERE `id_product` = '.(int)($this->id).' AND `type` = '.Product::CUSTOMIZE_FILE.' AND `id_customization_field` >= '.(int)($customizationFields[Product::CUSTOMIZE_FILE][count($customizationFields[Product::CUSTOMIZE_FILE]) - $extraFile]))
|
||||
OR !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`)')))
|
||||
return false;
|
||||
|
||||
if ($extraText > 0 AND count($customizationFields[_CUSTOMIZE_TEXTFIELD_]) - $extraText >= 0 AND
|
||||
(!Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'customization_field` WHERE `id_product` = '.(int)($this->id).' AND `type` = '._CUSTOMIZE_TEXTFIELD_.' AND `id_customization_field` >= '.(int)($customizationFields[_CUSTOMIZE_TEXTFIELD_][count($customizationFields[_CUSTOMIZE_TEXTFIELD_]) - $extraText]))
|
||||
if ($extraText > 0 AND count($customizationFields[Product::CUSTOMIZE_TEXTFIELD]) - $extraText >= 0 AND
|
||||
(!Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'customization_field` WHERE `id_product` = '.(int)($this->id).' AND `type` = '.Product::CUSTOMIZE_TEXTFIELD.' AND `id_customization_field` >= '.(int)($customizationFields[Product::CUSTOMIZE_TEXTFIELD][count($customizationFields[Product::CUSTOMIZE_TEXTFIELD]) - $extraText]))
|
||||
OR !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`)')))
|
||||
return false;
|
||||
return true;
|
||||
@@ -2982,11 +3043,11 @@ class ProductCore extends ObjectModel
|
||||
$languages = Language::getLanguages();
|
||||
if ((int)($uploadableFiles) > 0)
|
||||
for ($i = 0; $i < (int)($uploadableFiles); $i++)
|
||||
if (!$this->_createLabel($languages, _CUSTOMIZE_FILE_))
|
||||
if (!$this->_createLabel($languages, Product::CUSTOMIZE_FILE))
|
||||
return false;
|
||||
if ((int)($textFields) > 0)
|
||||
for ($i = 0; $i < (int)($textFields); $i++)
|
||||
if (!$this->_createLabel($languages, _CUSTOMIZE_TEXTFIELD_))
|
||||
if (!$this->_createLabel($languages, Product::CUSTOMIZE_TEXTFIELD))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
@@ -3021,6 +3082,8 @@ class ProductCore extends ObjectModel
|
||||
|
||||
public function getCustomizationFields($id_lang = false)
|
||||
{
|
||||
if (!Customization::isFeatureActive())
|
||||
return false;
|
||||
if (!$result = Db::getInstance()->ExecuteS('
|
||||
SELECT cf.`id_customization_field`, cf.`type`, cf.`required`, cfl.`name`, cfl.`id_lang`
|
||||
FROM `'._DB_PREFIX_.'customization_field` cf
|
||||
@@ -3038,16 +3101,30 @@ class ProductCore extends ObjectModel
|
||||
|
||||
public function getCustomizationFieldIds()
|
||||
{
|
||||
return Db::getInstance()->ExecuteS('SELECT `id_customization_field`, `type` FROM `'._DB_PREFIX_.'customization_field` WHERE `id_product` = '.(int)($this->id));
|
||||
if (!Customization::isFeatureActive())
|
||||
return array();
|
||||
return Db::getInstance()->ExecuteS('
|
||||
SELECT `id_customization_field`, `type`
|
||||
FROM `'._DB_PREFIX_.'customization_field`
|
||||
WHERE `id_product` = '.(int)($this->id));
|
||||
}
|
||||
|
||||
public function getRequiredCustomizableFields()
|
||||
{
|
||||
return Db::getInstance()->ExecuteS('SELECT `id_customization_field`, `type` FROM `'._DB_PREFIX_.'customization_field` WHERE `id_product` = '.(int)($this->id).' AND `required` = 1');
|
||||
if (!Customization::isFeatureActive())
|
||||
return array();
|
||||
return Db::getInstance()->ExecuteS('
|
||||
SELECT `id_customization_field`, `type`
|
||||
FROM `'._DB_PREFIX_.'customization_field`
|
||||
WHERE `id_product` = '.(int)($this->id).'
|
||||
AND `required` = 1'
|
||||
);
|
||||
}
|
||||
|
||||
public function hasAllRequiredCustomizableFields(Context $context = null)
|
||||
{
|
||||
if (!Customization::isFeatureActive())
|
||||
return true;
|
||||
if (!$context)
|
||||
$context = Context::getContext();
|
||||
|
||||
@@ -3158,28 +3235,30 @@ class ProductCore extends ObjectModel
|
||||
|
||||
public function getStockMvts($id_lang)
|
||||
{
|
||||
$sql = 'SELECT sm.id_stock_mvt, sm.date_add, sm.quantity, sm.id_order, CONCAT(pl.name, \' \', GROUP_CONCAT(IFNULL(al.name, \'\'), \'\')) product_name, CONCAT(e.lastname, \' \', e.firstname) employee, mrl.name reason
|
||||
FROM `'._DB_PREFIX_.'stock_mvt` sm
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (sm.id_product = pl.id_product AND pl.id_lang = '.(int)$id_lang.Context::getContext()->shop->sqlLang('pl').')
|
||||
LEFT JOIN `'._DB_PREFIX_.'stock_mvt_reason_lang` mrl ON (sm.id_stock_mvt_reason = mrl.id_stock_mvt_reason AND mrl.id_lang = '.(int)$id_lang.')
|
||||
LEFT JOIN `'._DB_PREFIX_.'employee` e ON (e.id_employee = sm.id_employee)
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_attribute_combination` pac ON (pac.id_product_attribute = sm.id_product_attribute)
|
||||
LEFT JOIN `'._DB_PREFIX_.'attribute_lang` al ON (al.id_attribute = pac.id_attribute AND al.id_lang = '.(int)$id_lang.')
|
||||
WHERE sm.id_product='.(int)$this->id.'
|
||||
GROUP BY sm.id_stock_mvt';
|
||||
return Db::getInstance()->ExecuteS($sql);
|
||||
return Db::getInstance()->ExecuteS('
|
||||
SELECT sm.id_stock_mvt, sm.date_add, sm.quantity, sm.id_order, CONCAT(pl.name, \' \', GROUP_CONCAT(IFNULL(al.name, \'\'), \'\')) product_name, CONCAT(e.lastname, \' \', e.firstname) employee, mrl.name reason
|
||||
FROM `'._DB_PREFIX_.'stock_mvt` sm
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (sm.id_product = pl.id_product AND pl.id_lang = '.(int)$id_lang.Context::getContext()->shop->sqlLang('pl').')
|
||||
LEFT JOIN `'._DB_PREFIX_.'stock_mvt_reason_lang` mrl ON (sm.id_stock_mvt_reason = mrl.id_stock_mvt_reason AND mrl.id_lang = '.(int)$id_lang.')
|
||||
LEFT JOIN `'._DB_PREFIX_.'employee` e ON (e.id_employee = sm.id_employee)
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_attribute_combination` pac ON (pac.id_product_attribute = sm.id_product_attribute)
|
||||
LEFT JOIN `'._DB_PREFIX_.'attribute_lang` al ON (al.id_attribute = pac.id_attribute AND al.id_lang = '.(int)$id_lang.')
|
||||
WHERE sm.id_product='.(int)$this->id.'
|
||||
GROUP BY sm.id_stock_mvt
|
||||
');
|
||||
}
|
||||
|
||||
public static function getUrlRewriteInformations($id_product)
|
||||
{
|
||||
$sql = 'SELECT pl.`id_lang`, pl.`link_rewrite`, p.`ean13`, cl.`link_rewrite` AS category_rewrite
|
||||
FROM `'._DB_PREFIX_.'product` p
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product`'.Context::getContext()->shop->sqlLang('pl').')
|
||||
LEFT JOIN `'._DB_PREFIX_.'lang` l ON (pl.`id_lang` = l.`id_lang`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (cl.`id_category` = p.`id_category_default` AND cl.`id_lang` = pl.`id_lang`'.Context::getContext()->shop->sqlLang('cl').')
|
||||
WHERE p.`id_product` = '.(int)$id_product. '
|
||||
AND l.`active` = 1';
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($sql);
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
|
||||
SELECT pl.`id_lang`, pl.`link_rewrite`, p.`ean13`, cl.`link_rewrite` AS category_rewrite
|
||||
FROM `'._DB_PREFIX_.'product` p
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product`'.Context::getContext()->shop->sqlLang('pl').')
|
||||
LEFT JOIN `'._DB_PREFIX_.'lang` l ON (pl.`id_lang` = l.`id_lang`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (cl.`id_category` = p.`id_category_default` AND cl.`id_lang` = pl.`id_lang`'.Context::getContext()->shop->sqlLang('cl').')
|
||||
WHERE p.`id_product` = '.(int)$id_product. '
|
||||
AND l.`active` = 1
|
||||
');
|
||||
}
|
||||
|
||||
public static function getIdTaxRulesGroupByIdProduct($id_product)
|
||||
|
||||
@@ -80,6 +80,8 @@ class ProductDownloadCore extends ObjectModel
|
||||
protected $table = 'product_download';
|
||||
protected $identifier = 'id_product_download';
|
||||
|
||||
protected static $feature_active = null;
|
||||
|
||||
/**
|
||||
* Build a virtual product
|
||||
*
|
||||
@@ -158,6 +160,9 @@ class ProductDownloadCore extends ObjectModel
|
||||
*/
|
||||
public static function getIdFromIdProduct($id_product)
|
||||
{
|
||||
if (!self::isFeatureActive())
|
||||
return false;
|
||||
|
||||
if (array_key_exists($id_product, self::$_productIds))
|
||||
return self::$_productIds[$id_product];
|
||||
|
||||
@@ -206,7 +211,7 @@ class ProductDownloadCore extends ObjectModel
|
||||
* @param string $hash hash code in table order detail (optionnal)
|
||||
* @return string Html all the code for print a link to the file
|
||||
*/
|
||||
public function getTextLink($admin=true, $hash=false)
|
||||
public function getTextLink($admin = true, $hash = false)
|
||||
{
|
||||
$key = $this->physically_filename . '-' . ($hash ? $hash : 'orderdetail');
|
||||
$link = ($admin) ? 'get-file-admin.php?' : Tools::getHttpHost(true, true).'index.php?controller=get-file&';
|
||||
@@ -268,6 +273,21 @@ class ProductDownloadCore extends ObjectModel
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is allow to know if a feature is used or active
|
||||
* @since 1.5.0.1
|
||||
* @return bool
|
||||
*/
|
||||
public static function isFeatureActive()
|
||||
{
|
||||
if (self::$feature_active === null)
|
||||
self::$feature_active = (bool)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
|
||||
SELECT COUNT(*)
|
||||
FROM `'._DB_PREFIX_.'product_download`
|
||||
');
|
||||
return self::$feature_active;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
+24
-1
@@ -51,6 +51,8 @@ class SceneCore extends ObjectModel
|
||||
protected $fieldsSizeLang = array('name' => 100);
|
||||
protected $fieldsValidateLang = array('name' => 'isGenericName');
|
||||
|
||||
protected static $feature_active = null;
|
||||
|
||||
public function __construct($id = NULL, $id_lang = NULL, $liteResult = true, $hideScenePosition = false)
|
||||
{
|
||||
parent::__construct((int)($id), (int)($id_lang));
|
||||
@@ -181,8 +183,11 @@ class SceneCore extends ObjectModel
|
||||
*
|
||||
* @return array Products
|
||||
*/
|
||||
static public function getScenes($id_category, $id_lang = NULL, $onlyActive = true, $liteResult = true, $hideScenePosition = true, Context $context = null)
|
||||
public static function getScenes($id_category, $id_lang = NULL, $onlyActive = true, $liteResult = true, $hideScenePosition = true, Context $context = null)
|
||||
{
|
||||
if (!self::isFeatureActive())
|
||||
return array();
|
||||
|
||||
if (!$context)
|
||||
$context = Context::getContext();
|
||||
$id_lang = is_null($id_lang) ? $context->language->id : $id_lang;
|
||||
@@ -211,6 +216,9 @@ class SceneCore extends ObjectModel
|
||||
*/
|
||||
public function getProducts($onlyActive = true, $id_lang = NULL, $liteResult = true, Context $context = null)
|
||||
{
|
||||
if (!self::isFeatureActive())
|
||||
return array();
|
||||
|
||||
if (!$context)
|
||||
$context = Context::getContext();
|
||||
$id_lang = is_null($id_lang) ? $context->language->id : $id_lang;
|
||||
@@ -257,6 +265,21 @@ class SceneCore extends ObjectModel
|
||||
{
|
||||
return preg_replace('/^[0-9]+\./', '', $name);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is allow to know if a feature is used or active
|
||||
* @since 1.5.0.1
|
||||
* @return bool
|
||||
*/
|
||||
public static function isFeatureActive()
|
||||
{
|
||||
if (self::$feature_active === null)
|
||||
self::$feature_active = (bool)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
|
||||
SELECT COUNT(*)
|
||||
FROM `'._DB_PREFIX_.'scene`
|
||||
');
|
||||
return self::$feature_active;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -307,6 +307,9 @@ class SearchCore
|
||||
|
||||
public static function getAttributes($db, $id_product, $id_lang)
|
||||
{
|
||||
if (!Cobmination::isFeatureActive())
|
||||
return '';
|
||||
|
||||
$attributes = '';
|
||||
$attributesArray = $db->ExecuteS('
|
||||
SELECT al.name FROM '._DB_PREFIX_.'product_attribute pa
|
||||
@@ -320,6 +323,9 @@ class SearchCore
|
||||
|
||||
public static function getFeatures($db, $id_product, $id_lang)
|
||||
{
|
||||
if (!Feature::isFeatureActive())
|
||||
return '';
|
||||
|
||||
$features = '';
|
||||
$featuresArray = $db->ExecuteS('
|
||||
SELECT fvl.value FROM '._DB_PREFIX_.'feature_product fp
|
||||
|
||||
+43
-11
@@ -47,6 +47,7 @@ class SpecificPriceCore extends ObjectModel
|
||||
|
||||
protected static $_specificPriceCache = array();
|
||||
protected static $_cache_priorities = array();
|
||||
protected static $feature_active = null;
|
||||
|
||||
public function getFields()
|
||||
{
|
||||
@@ -67,16 +68,18 @@ class SpecificPriceCore extends ObjectModel
|
||||
|
||||
public static function getByProductId($id_product)
|
||||
{
|
||||
return Db::getInstance()->ExecuteS('
|
||||
SELECT * FROM `'._DB_PREFIX_.'specific_price` WHERE `id_product` = '.(int)($id_product)
|
||||
);
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
|
||||
SELECT *
|
||||
FROM `'._DB_PREFIX_.'specific_price`
|
||||
WHERE `id_product` = '.(int)$id_product);
|
||||
}
|
||||
|
||||
public static function getIdsByProductId($id_product)
|
||||
{
|
||||
return Db::getInstance()->ExecuteS('
|
||||
SELECT `id_specific_price` FROM `'._DB_PREFIX_.'specific_price` WHERE `id_product` = '.(int)$id_product.'
|
||||
');
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
|
||||
SELECT `id_specific_price`
|
||||
FROM `'._DB_PREFIX_.'specific_price`
|
||||
WHERE `id_product` = '.(int)$id_product);
|
||||
}
|
||||
|
||||
// score generation for quantity discount
|
||||
@@ -96,10 +99,12 @@ class SpecificPriceCore extends ObjectModel
|
||||
|
||||
public static function getPriority($id_product)
|
||||
{
|
||||
if (!self::isFeatureActive())
|
||||
return Configuration::get('PS_SPECIFIC_PRICE_PRIORITIES');
|
||||
|
||||
if (!isset(self::$_cache_priorities[(int)$id_product]))
|
||||
{
|
||||
self::$_cache_priorities[(int)$id_product] = Db::getInstance()->getValue('
|
||||
self::$_cache_priorities[(int)$id_product] = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
|
||||
SELECT `priority`
|
||||
FROM `'._DB_PREFIX_.'specific_price_priority`
|
||||
WHERE `id_product` = '.(int)$id_product);
|
||||
@@ -114,6 +119,9 @@ class SpecificPriceCore extends ObjectModel
|
||||
|
||||
public static function getSpecificPrice($id_product, $id_shop, $id_currency, $id_country, $id_group, $quantity)
|
||||
{
|
||||
if (!self::isFeatureActive())
|
||||
return array();
|
||||
|
||||
/*
|
||||
** The date is not taken into account for the cache, but this is for the better because it keeps the consistency for the whole script.
|
||||
** The price must not change between the top and the bottom of the page
|
||||
@@ -123,7 +131,7 @@ class SpecificPriceCore extends ObjectModel
|
||||
if (!array_key_exists($key, self::$_specificPriceCache))
|
||||
{
|
||||
$now = date('Y-m-d H:i:s');
|
||||
self::$_specificPriceCache[$key] = Db::getInstance()->getRow('
|
||||
self::$_specificPriceCache[$key] = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
|
||||
SELECT *, '.self::_getScoreQuery($id_product, $id_shop, $id_currency, $id_country, $id_group).'
|
||||
FROM `'._DB_PREFIX_.'specific_price`
|
||||
WHERE `id_product` IN (0, '.(int)$id_product.')
|
||||
@@ -176,8 +184,11 @@ class SpecificPriceCore extends ObjectModel
|
||||
|
||||
public static function getQuantityDiscounts($id_product, $id_shop, $id_currency, $id_country, $id_group)
|
||||
{
|
||||
if (!self::isFeatureActive())
|
||||
return array();
|
||||
|
||||
$now = date('Y-m-d H:i:s');
|
||||
$res = Db::getInstance()->ExecuteS('
|
||||
$res = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
|
||||
SELECT *,
|
||||
'.self::_getScoreQuery($id_product, $id_shop, $id_currency, $id_country, $id_group).'
|
||||
FROM `'._DB_PREFIX_.'specific_price`
|
||||
@@ -215,8 +226,11 @@ class SpecificPriceCore extends ObjectModel
|
||||
|
||||
public static function getQuantityDiscount($id_product, $id_shop, $id_currency, $id_country, $id_group, $quantity)
|
||||
{
|
||||
if (!self::isFeatureActive())
|
||||
return array();
|
||||
|
||||
$now = date('Y-m-d H:i:s');
|
||||
return Db::getInstance()->getRow('
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
|
||||
SELECT *,
|
||||
'.self::_getScoreQuery($id_product, $id_shop, $id_currency, $id_country, $id_group).'
|
||||
FROM `'._DB_PREFIX_.'specific_price`
|
||||
@@ -238,7 +252,10 @@ class SpecificPriceCore extends ObjectModel
|
||||
|
||||
public static function getProductIdByDate($id_shop, $id_currency, $id_country, $id_group, $beginning, $ending)
|
||||
{
|
||||
$resource = Db::getInstance()->ExecuteS('
|
||||
if (!self::isFeatureActive())
|
||||
return array();
|
||||
|
||||
$resource = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
|
||||
SELECT `id_product`
|
||||
FROM `'._DB_PREFIX_.'specific_price`
|
||||
WHERE `id_shop` IN(0, '.(int)($id_shop).') AND
|
||||
@@ -271,5 +288,20 @@ class SpecificPriceCore extends ObjectModel
|
||||
$this->id_product = (int)($id_product);
|
||||
return $this->add();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is allow to know if a feature is used or active
|
||||
* @since 1.5.0.1
|
||||
* @return bool
|
||||
*/
|
||||
public static function isFeatureActive()
|
||||
{
|
||||
if (self::$feature_active === null)
|
||||
self::$feature_active = (bool)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
|
||||
SELECT COUNT(*)
|
||||
FROM `'._DB_PREFIX_.'specific_price`
|
||||
');
|
||||
return self::$feature_active;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+42
-7
@@ -657,12 +657,10 @@ class ToolsCore
|
||||
elseif ($id_category = self::getValue('id_category'))
|
||||
{
|
||||
$page_number = self::getValue('p');
|
||||
$sql = 'SELECT `name`, `meta_title`, `meta_description`, `meta_keywords`, `description`
|
||||
FROM `'._DB_PREFIX_.'category_lang`
|
||||
WHERE id_lang = '.(int)$id_lang.'
|
||||
AND id_category = '.(int)$id_category
|
||||
.Context::getContext()->shop->sqlLang();
|
||||
$row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql);
|
||||
$row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
|
||||
SELECT `name`, `meta_title`, `meta_description`, `meta_keywords`, `description`
|
||||
FROM `'._DB_PREFIX_.'category_lang` cl
|
||||
WHERE cl.`id_lang` = '.(int)($id_lang).' AND cl.`id_category` = '.(int)$id_category.Context::getContext()->shop->sqlLang('cl'));
|
||||
if ($row)
|
||||
{
|
||||
if (empty($row['meta_description']))
|
||||
@@ -2065,12 +2063,49 @@ FileETag INode MTime Size
|
||||
return 1024 * 1024 * 1024 * (int)$memory_limit;
|
||||
|
||||
return $memory_limit;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return bool true if the server use 64bit arch
|
||||
*/
|
||||
public static function isX86_64arch()
|
||||
{
|
||||
return (PHP_INT_MAX == '9223372036854775807');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array SQL query in array
|
||||
* @return string SQL query
|
||||
*/
|
||||
public static function buildQuery(array $sql)
|
||||
{
|
||||
if (!isset($sql['select']))
|
||||
$sql['select'] = 'SELECT *';
|
||||
|
||||
$req = $sql['select']."\n";
|
||||
$req .= $sql['from']."\n";
|
||||
|
||||
if (isset($sql['join']))
|
||||
$req .= $sql['join']."\n";
|
||||
|
||||
if (isset($sql['where']))
|
||||
$req .= $sql['where']."\n";
|
||||
|
||||
if (isset($sql['groupby']))
|
||||
$req .= $sql['groupby']."\n";
|
||||
|
||||
if (isset($sql['having']))
|
||||
$req .= $sql['having']."\n";
|
||||
|
||||
if (isset($sql['orderby']))
|
||||
$req .= $sql['orderby']."\n";
|
||||
|
||||
if (isset($sql['limit']))
|
||||
$req .= $sql['limit']."\n";
|
||||
|
||||
return $req;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -682,7 +682,7 @@ class ValidateCore
|
||||
|
||||
public static function isUnixName($data)
|
||||
{
|
||||
return preg_match('/^[a-z0-9_-]+$/ui', $data);
|
||||
return preg_match('/^[a-z0-9\._-]+$/ui', $data);
|
||||
}
|
||||
|
||||
public static function isTablePrefix($data)
|
||||
|
||||
Reference in New Issue
Block a user