[*] BO : carriers are now sortable by position
// Carriers class is now normalized // Attribute class is now normalized
This commit is contained in:
@@ -149,7 +149,7 @@ abstract class AdminTabCore
|
||||
|
||||
public $smarty;
|
||||
|
||||
protected $identifiersDnd = array('id_product' => 'id_product', 'id_category' => 'id_category_to_move','id_cms_category' => 'id_cms_category_to_move', 'id_cms' => 'id_cms', 'id_attribute' => 'id_attribute', 'id_attribute_group' => 'id_attribute_group', 'id_feature' => 'id_feature');
|
||||
protected $identifiersDnd = array('id_product' => 'id_product', 'id_category' => 'id_category_to_move','id_cms_category' => 'id_cms_category_to_move', 'id_cms' => 'id_cms', 'id_attribute' => 'id_attribute', 'id_attribute_group' => 'id_attribute_group', 'id_feature' => 'id_feature', 'id_carrier' => 'id_carrier');
|
||||
|
||||
/** @var bool Redirect or not ater a creation */
|
||||
protected $_redirect = true;
|
||||
@@ -592,6 +592,8 @@ abstract class AdminTabCore
|
||||
{
|
||||
$object->deleteImage();
|
||||
$object->deleted = 1;
|
||||
if(method_exists($object, 'cleanPositions'))
|
||||
$object->cleanPositions();
|
||||
if ($object->update())
|
||||
Tools::redirectAdmin(self::$currentIndex.'&conf=1&token='.$token);
|
||||
}
|
||||
@@ -673,6 +675,8 @@ abstract class AdminTabCore
|
||||
Tools::redirectAdmin(self::$currentIndex.'&conf=2&token='.$token);
|
||||
$this->_errors[] = Tools::displayError('An error occurred while deleting selection.');
|
||||
}
|
||||
// clean carriers positions
|
||||
Carrier::cleanPositions();
|
||||
}
|
||||
else
|
||||
$this->_errors[] = Tools::displayError('You must select at least one element to delete.');
|
||||
|
||||
+46
-39
@@ -28,25 +28,25 @@
|
||||
class AttributeCore extends ObjectModel
|
||||
{
|
||||
/** @var integer Group id which attribute belongs */
|
||||
public $id_attribute_group;
|
||||
public $id_attribute_group;
|
||||
|
||||
/** @var string Name */
|
||||
public $name;
|
||||
public $color;
|
||||
public $position;
|
||||
public $default;
|
||||
public $name;
|
||||
public $color;
|
||||
public $position;
|
||||
public $default;
|
||||
|
||||
protected $fieldsRequired = array('id_attribute_group');
|
||||
protected $fieldsValidate = array('id_attribute_group' => 'isUnsignedId', 'color' => 'isColor', 'position' => 'isInt');
|
||||
protected $fieldsRequiredLang = array('name');
|
||||
protected $fieldsSizeLang = array('name' => 64);
|
||||
protected $fieldsValidateLang = array('name' => 'isGenericName');
|
||||
protected $fieldsRequired = array('id_attribute_group');
|
||||
protected $fieldsValidate = array('id_attribute_group' => 'isUnsignedId', 'color' => 'isColor', 'position' => 'isInt');
|
||||
protected $fieldsRequiredLang = array('name');
|
||||
protected $fieldsSizeLang = array('name' => 64);
|
||||
protected $fieldsValidateLang = array('name' => 'isGenericName');
|
||||
|
||||
protected $table = 'attribute';
|
||||
protected $identifier = 'id_attribute';
|
||||
protected $table = 'attribute';
|
||||
protected $identifier = 'id_attribute';
|
||||
protected $image_dir = _PS_COL_IMG_DIR_;
|
||||
|
||||
protected $webserviceParameters = array(
|
||||
protected $webserviceParameters = array(
|
||||
'objectsNodeName' => 'product_option_values',
|
||||
'objectNodeName' => 'product_option_value',
|
||||
'fields' => array(
|
||||
@@ -56,7 +56,7 @@ class AttributeCore extends ObjectModel
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->image_dir = _PS_COL_IMG_DIR_;
|
||||
$this->image_dir = _PS_COL_IMG_DIR_;
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
@@ -85,16 +85,23 @@ class AttributeCore extends ObjectModel
|
||||
|
||||
public function delete()
|
||||
{
|
||||
if (($result = Db::getInstance()->executeS('SELECT `id_product_attribute` FROM `'._DB_PREFIX_.'product_attribute_combination` WHERE `'.$this->identifier.'` = '.(int)$this->id)) === false)
|
||||
if (($result = Db::getInstance()->executeS('
|
||||
SELECT `id_product_attribute`
|
||||
FROM `'._DB_PREFIX_.'product_attribute_combination`
|
||||
WHERE `'.$this->identifier.'` = '.(int)$this->id)) === false)
|
||||
return false;
|
||||
$combinationIds = array();
|
||||
$combination_ids = array();
|
||||
if (Db::getInstance()->numRows())
|
||||
{
|
||||
foreach ($result AS $row)
|
||||
$combinationIds[] = (int)$row['id_product_attribute'];
|
||||
if (Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'product_attribute_combination` WHERE `'.$this->identifier.'` = '.(int)$this->id) === false)
|
||||
foreach ($result as $row)
|
||||
$combination_ids[] = (int)$row['id_product_attribute'];
|
||||
if (Db::getInstance()->execute('
|
||||
DELETE FROM `'._DB_PREFIX_.'product_attribute_combination`
|
||||
WHERE `'.$this->identifier.'` = '.(int)$this->id) === false)
|
||||
return false;
|
||||
if (Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'product_attribute` WHERE `id_product_attribute` IN ('.implode(', ', $combinationIds).')') === false)
|
||||
if (Db::getInstance()->execute('
|
||||
DELETE FROM `'._DB_PREFIX_.'product_attribute`
|
||||
WHERE `id_product_attribute` IN ('.implode(', ', $combination_ids).')') === false)
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -107,17 +114,17 @@ class AttributeCore extends ObjectModel
|
||||
return $return;
|
||||
}
|
||||
|
||||
public function update($nullValues = false)
|
||||
public function update($null_values = false)
|
||||
{
|
||||
$return = parent::update($nullValues);
|
||||
$return = parent::update($null_values);
|
||||
if ($return)
|
||||
Module::hookExec('afterSaveAttribute', array('id_attribute' => $this->id));
|
||||
return $return;
|
||||
}
|
||||
|
||||
public function add($autodate = true, $nullValues = false)
|
||||
public function add($autodate = true, $null_values = false)
|
||||
{
|
||||
$return = parent::add($autodate, $nullValues);
|
||||
$return = parent::add($autodate, $null_values);
|
||||
if ($return)
|
||||
Module::hookExec('afterSaveAttribute', array('id_attribute' => $this->id));
|
||||
return $return;
|
||||
@@ -130,7 +137,7 @@ class AttributeCore extends ObjectModel
|
||||
* @param boolean $notNull Get only not null fields if true
|
||||
* @return array Attributes
|
||||
*/
|
||||
public static function getAttributes($id_lang, $notNull = false)
|
||||
public static function getAttributes($id_lang, $not_null = false)
|
||||
{
|
||||
if (!Combination::isFeatureActive())
|
||||
return array();
|
||||
@@ -140,7 +147,7 @@ class AttributeCore extends ObjectModel
|
||||
LEFT JOIN `'._DB_PREFIX_.'attribute_group_lang` agl ON (ag.`id_attribute_group` = agl.`id_attribute_group` AND agl.`id_lang` = '.(int)$id_lang.')
|
||||
LEFT JOIN `'._DB_PREFIX_.'attribute` a ON a.`id_attribute_group` = ag.`id_attribute_group`
|
||||
LEFT JOIN `'._DB_PREFIX_.'attribute_lang` al ON (a.`id_attribute` = al.`id_attribute` AND al.`id_lang` = '.(int)$id_lang.')
|
||||
'.($notNull ? 'WHERE a.`id_attribute` IS NOT NULL AND al.`name` IS NOT NULL' : '').'
|
||||
'.($not_null ? 'WHERE a.`id_attribute` IS NOT NULL AND al.`name` IS NOT NULL' : '').'
|
||||
ORDER BY agl.`name` ASC, a.`position` ASC');
|
||||
}
|
||||
|
||||
@@ -152,7 +159,7 @@ class AttributeCore extends ObjectModel
|
||||
* @param integer $qty Quantity needed
|
||||
* @return boolean Quantity is available or not
|
||||
*/
|
||||
static public function checkAttributeQty($id_product_attribute, $qty, Shop $shop = null)
|
||||
public static function checkAttributeQty($id_product_attribute, $qty, Shop $shop = null)
|
||||
{
|
||||
if (!$shop)
|
||||
$shop = Context::getContext()->shop;
|
||||
@@ -163,7 +170,7 @@ class AttributeCore extends ObjectModel
|
||||
.$shop->sqlRestriction(Shop::SHARE_STOCK);
|
||||
$result = (int)Db::getInstance()->getValue($sql);
|
||||
|
||||
return ($result AND $qty <= $result);
|
||||
return ($result && $qty <= $result);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -182,7 +189,7 @@ class AttributeCore extends ObjectModel
|
||||
FROM `'._DB_PREFIX_.'product_attribute`
|
||||
WHERE `id_product` = '.(int)$id_product);
|
||||
|
||||
if ($row['quantity'] !== NULL)
|
||||
if ($row['quantity'] !== null)
|
||||
return (int)$row['quantity'];
|
||||
return false;
|
||||
}
|
||||
@@ -260,11 +267,11 @@ class AttributeCore extends ObjectModel
|
||||
))
|
||||
return false;
|
||||
|
||||
foreach ($res AS $attribute)
|
||||
foreach ($res as $attribute)
|
||||
if ((int)$attribute['id_attribute'] == (int)$this->id)
|
||||
$movedAttribute = $attribute;
|
||||
$moved_attribute = $attribute;
|
||||
|
||||
if (!isset($movedAttribute) || !isset($position))
|
||||
if (!isset($moved_attribute) || !isset($position))
|
||||
return false;
|
||||
|
||||
// < and > statements rather than BETWEEN operator
|
||||
@@ -274,14 +281,14 @@ class AttributeCore extends ObjectModel
|
||||
SET `position`= `position` '.($way ? '- 1' : '+ 1').'
|
||||
WHERE `position`
|
||||
'.($way
|
||||
? '> '.(int)$movedAttribute['position'].' AND `position` <= '.(int)$position
|
||||
: '< '.(int)$movedAttribute['position'].' AND `position` >= '.(int)$position).'
|
||||
AND `id_attribute_group`='.(int)$movedAttribute['id_attribute_group'])
|
||||
AND Db::getInstance()->execute('
|
||||
? '> '.(int)$moved_attribute['position'].' AND `position` <= '.(int)$position
|
||||
: '< '.(int)$moved_attribute['position'].' AND `position` >= '.(int)$position).'
|
||||
AND `id_attribute_group`='.(int)$moved_attribute['id_attribute_group'])
|
||||
&& Db::getInstance()->execute('
|
||||
UPDATE `'._DB_PREFIX_.'attribute`
|
||||
SET `position` = '.(int)$position.'
|
||||
WHERE `id_attribute` = '.(int)$movedAttribute['id_attribute'].'
|
||||
AND `id_attribute_group`='.(int)$movedAttribute['id_attribute_group']));
|
||||
WHERE `id_attribute` = '.(int)$moved_attribute['id_attribute'].'
|
||||
AND `id_attribute_group`='.(int)$moved_attribute['id_attribute_group']));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -301,7 +308,7 @@ class AttributeCore extends ObjectModel
|
||||
FROM `'._DB_PREFIX_.'attribute`
|
||||
WHERE `id_attribute_group` = '.(int)$id_attribute_group;
|
||||
// when delete, you must use $use_last_attribute
|
||||
if($use_last_attribute)
|
||||
if ($use_last_attribute)
|
||||
$sql .= '
|
||||
AND `id_attribute` != '.(int)$this->id;
|
||||
$sql .= '
|
||||
|
||||
+258
-170
@@ -83,12 +83,16 @@ class CarrierCore extends ObjectModel
|
||||
/** @var boolean Need Range */
|
||||
public $need_range = 0;
|
||||
|
||||
/** @var int Position */
|
||||
public $position;
|
||||
|
||||
protected $langMultiShop = true;
|
||||
|
||||
protected $fieldsRequired = array('name', 'active');
|
||||
protected $fieldsSize = array('name' => 64);
|
||||
protected $fieldsValidate = array('id_tax_rules_group' => 'isInt', 'name' => 'isCarrierName', 'active' => 'isBool',
|
||||
'is_free' => 'isBool', 'url' => 'isAbsoluteUrl', 'shipping_handling' => 'isBool', 'range_behavior' => 'isBool', 'shipping_method' => 'isUnsignedInt');
|
||||
'is_free' => 'isBool', 'url' => 'isAbsoluteUrl', 'shipping_handling' => 'isBool', 'range_behavior' => 'isBool',
|
||||
'shipping_method' => 'isUnsignedInt');
|
||||
protected $fieldsRequiredLang = array('delay');
|
||||
protected $fieldsSizeLang = array('delay' => 128);
|
||||
protected $fieldsValidateLang = array('delay' => 'isGenericName');
|
||||
@@ -96,12 +100,12 @@ class CarrierCore extends ObjectModel
|
||||
protected $table = 'carrier';
|
||||
protected $identifier = 'id_carrier';
|
||||
|
||||
protected static $priceByWeight = array();
|
||||
protected static $priceByWeight2 = array();
|
||||
protected static $priceByPrice = array();
|
||||
protected static $priceByPrice2 = array();
|
||||
protected static $price_by_weight = array();
|
||||
protected static $price_by_weight2 = array();
|
||||
protected static $price_by_price = array();
|
||||
protected static $price_by_price2 = array();
|
||||
|
||||
protected static $_cache_tax_rule = array();
|
||||
protected static $cache_tax_rule = array();
|
||||
|
||||
protected $webserviceParameters = array(
|
||||
'fields' => array(
|
||||
@@ -114,19 +118,20 @@ class CarrierCore extends ObjectModel
|
||||
public function getFields()
|
||||
{
|
||||
$this->validateFields();
|
||||
$fields['id_tax_rules_group'] = (int)($this->id_tax_rules_group);
|
||||
$fields['id_tax_rules_group'] = (int)$this->id_tax_rules_group;
|
||||
$fields['name'] = pSQL($this->name);
|
||||
$fields['url'] = pSQL($this->url);
|
||||
$fields['active'] = (int)($this->active);
|
||||
$fields['deleted'] = (int)($this->deleted);
|
||||
$fields['shipping_handling'] = (int)($this->shipping_handling);
|
||||
$fields['range_behavior'] = (int)($this->range_behavior);
|
||||
$fields['shipping_method'] = (int)($this->shipping_method);
|
||||
$fields['is_module'] = (int)($this->is_module);
|
||||
$fields['is_free'] = (int)($this->is_free);
|
||||
$fields['shipping_external'] = (int)($this->shipping_external);
|
||||
$fields['active'] = (int)$this->active;
|
||||
$fields['deleted'] = (int)$this->deleted;
|
||||
$fields['shipping_handling'] = (int)$this->shipping_handling;
|
||||
$fields['range_behavior'] = (int)$this->range_behavior;
|
||||
$fields['shipping_method'] = (int)$this->shipping_method;
|
||||
$fields['is_module'] = (int)$this->is_module;
|
||||
$fields['is_free'] = (int)$this->is_free;
|
||||
$fields['shipping_external'] = (int)$this->shipping_external;
|
||||
$fields['external_module_name'] = $this->external_module_name;
|
||||
$fields['need_range'] = $this->need_range;
|
||||
$fields['position'] = (int)$this->position;
|
||||
|
||||
return $fields;
|
||||
}
|
||||
@@ -149,20 +154,20 @@ class CarrierCore extends ObjectModel
|
||||
return $this->getTranslationsFields(array('delay'));
|
||||
}
|
||||
|
||||
public function add($autodate = true, $nullValues = false)
|
||||
public function add($autodate = true, $null_values = false)
|
||||
{
|
||||
if (!parent::add($autodate, $nullValues) || !Validate::isLoadedObject($this))
|
||||
if (!parent::add($autodate, $null_values) || !Validate::isLoadedObject($this))
|
||||
return false;
|
||||
if (!Db::getInstance()->executeS('SELECT `id_carrier` FROM `'._DB_PREFIX_.$this->table.'` WHERE `deleted` = 0'))
|
||||
return false;
|
||||
if (!$numRows = Db::getInstance()->NumRows())
|
||||
if (!$num_rows = Db::getInstance()->NumRows())
|
||||
return false;
|
||||
if ((int)($numRows) == 1)
|
||||
Configuration::updateValue('PS_CARRIER_DEFAULT', (int)($this->id));
|
||||
|
||||
if ((int)$num_rows == 1)
|
||||
Configuration::updateValue('PS_CARRIER_DEFAULT', (int)$this->id);
|
||||
|
||||
// Register reference
|
||||
Db::getInstance()->execute('UPDATE `'._DB_PREFIX_.$this->table.'` SET `id_reference` = '.$this->id.' WHERE `id_carrier` = '.$this->id);
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -173,7 +178,7 @@ class CarrierCore extends ObjectModel
|
||||
*/
|
||||
public function setConfiguration($id_old)
|
||||
{
|
||||
Db::getInstance()->execute('UPDATE `'._DB_PREFIX_.'delivery` SET `id_carrier` = '.(int)($this->id).' WHERE `id_carrier` = '.(int)($id_old));
|
||||
Db::getInstance()->execute('UPDATE `'._DB_PREFIX_.'delivery` SET `id_carrier` = '.(int)$this->id.' WHERE `id_carrier` = '.(int)$id_old);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -183,47 +188,47 @@ class CarrierCore extends ObjectModel
|
||||
* @param integer $id_zone Zone id (for customer delivery address)
|
||||
* @return float Delivery price
|
||||
*/
|
||||
public function getDeliveryPriceByWeight($totalWeight, $id_zone, Shop $shop = null)
|
||||
public function getDeliveryPriceByWeight($total_weight, $id_zone, Shop $shop = null)
|
||||
{
|
||||
$cache_key = $this->id.'_'.$totalWeight.'_'.$id_zone;
|
||||
if (!isset(self::$priceByWeight[$cache_key]))
|
||||
$cache_key = $this->id.'_'.$total_weight.'_'.$id_zone;
|
||||
if (!isset(self::$price_by_weight[$cache_key]))
|
||||
{
|
||||
$sql = 'SELECT d.`price`
|
||||
FROM `'._DB_PREFIX_.'delivery` d
|
||||
LEFT JOIN `'._DB_PREFIX_.'range_weight` w ON (d.`id_range_weight` = w.`id_range_weight`)
|
||||
WHERE d.`id_zone` = '.(int)($id_zone).'
|
||||
AND '.(float)$totalWeight.' >= w.`delimiter1`
|
||||
AND '.(float)$totalWeight.' < w.`delimiter2`
|
||||
WHERE d.`id_zone` = '.(int)$id_zone.'
|
||||
AND '.(float)$total_weight.' >= w.`delimiter1`
|
||||
AND '.(float)$total_weight.' < w.`delimiter2`
|
||||
AND d.`id_carrier` = '.(int)$this->id.'
|
||||
'.Carrier::sqlDeliveryRangeShop('range_weight', $shop).'
|
||||
ORDER BY w.`delimiter1` ASC';
|
||||
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql);
|
||||
if (!isset($result['price']))
|
||||
self::$priceByWeight[$cache_key] = $this->getMaxDeliveryPriceByWeight($id_zone);
|
||||
self::$price_by_weight[$cache_key] = $this->getMaxDeliveryPriceByWeight($id_zone);
|
||||
else
|
||||
self::$priceByWeight[$cache_key] = $result['price'];
|
||||
self::$price_by_weight[$cache_key] = $result['price'];
|
||||
}
|
||||
return self::$priceByWeight[$cache_key];
|
||||
return self::$price_by_weight[$cache_key];
|
||||
}
|
||||
|
||||
public static function checkDeliveryPriceByWeight($id_carrier, $totalWeight, $id_zone, Shop $shop = null)
|
||||
public static function checkDeliveryPriceByWeight($id_carrier, $total_weight, $id_zone, Shop $shop = null)
|
||||
{
|
||||
$cache_key = $id_carrier.'_'.$totalWeight.'_'.$id_zone;
|
||||
if (!isset(self::$priceByWeight2[$cache_key]))
|
||||
$cache_key = $id_carrier.'_'.$total_weight.'_'.$id_zone;
|
||||
if (!isset(self::$price_by_weight2[$cache_key]))
|
||||
{
|
||||
$sql = 'SELECT d.`price`
|
||||
FROM `'._DB_PREFIX_.'delivery` d
|
||||
LEFT JOIN `'._DB_PREFIX_.'range_weight` w ON d.`id_range_weight` = w.`id_range_weight`
|
||||
WHERE d.`id_zone` = '.(int)$id_zone.'
|
||||
AND '.(float)$totalWeight.' >= w.`delimiter1`
|
||||
AND '.(float)$totalWeight.' < w.`delimiter2`
|
||||
AND '.(float)$total_weight.' >= w.`delimiter1`
|
||||
AND '.(float)$total_weight.' < w.`delimiter2`
|
||||
AND d.`id_carrier` = '.(int)$id_carrier.'
|
||||
'.Carrier::sqlDeliveryRangeShop('range_weight', $shop).'
|
||||
ORDER BY w.`delimiter1` ASC';
|
||||
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql);
|
||||
self::$priceByWeight2[$cache_key] = (isset($result['price']));
|
||||
self::$price_by_weight2[$cache_key] = (isset($result['price']));
|
||||
}
|
||||
return self::$priceByWeight2[$cache_key];
|
||||
return self::$price_by_weight2[$cache_key];
|
||||
}
|
||||
|
||||
public function getMaxDeliveryPriceByWeight($id_zone, Shop $shop = null)
|
||||
@@ -248,30 +253,30 @@ class CarrierCore extends ObjectModel
|
||||
* @param integer $id_zone Zone id (for customer delivery address)
|
||||
* @return float Delivery price
|
||||
*/
|
||||
public function getDeliveryPriceByPrice($orderTotal, $id_zone, $id_currency = null, Shop $shop = null)
|
||||
public function getDeliveryPriceByPrice($order_total, $id_zone, $id_currency = null, Shop $shop = null)
|
||||
{
|
||||
$cache_key = $this->id.'_'.$orderTotal.'_'.$id_zone.'_'.$id_currency;
|
||||
if (!isset(self::$priceByPrice[$cache_key]))
|
||||
$cache_key = $this->id.'_'.$order_total.'_'.$id_zone.'_'.$id_currency;
|
||||
if (!isset(self::$price_by_price[$cache_key]))
|
||||
{
|
||||
if (!empty($id_currency))
|
||||
$orderTotal = Tools::convertPrice($orderTotal, $id_currency, false);
|
||||
$order_total = Tools::convertPrice($order_total, $id_currency, false);
|
||||
|
||||
$sql = 'SELECT d.`price`
|
||||
FROM `'._DB_PREFIX_.'delivery` d
|
||||
LEFT JOIN `'._DB_PREFIX_.'range_price` r ON d.`id_range_price` = r.`id_range_price`
|
||||
WHERE d.`id_zone` = '.(int)($id_zone).'
|
||||
AND '.(float)$orderTotal.' >= r.`delimiter1`
|
||||
AND '.(float)$orderTotal.' < r.`delimiter2`
|
||||
AND d.`id_carrier` = '.(int)($this->id).'
|
||||
WHERE d.`id_zone` = '.(int)$id_zone.'
|
||||
AND '.(float)$order_total.' >= r.`delimiter1`
|
||||
AND '.(float)$order_total.' < r.`delimiter2`
|
||||
AND d.`id_carrier` = '.(int)$this->id.'
|
||||
'.Carrier::sqlDeliveryRangeShop('range_price', $shop).'
|
||||
ORDER BY r.`delimiter1` ASC';
|
||||
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql);
|
||||
if (!isset($result['price']))
|
||||
self::$priceByPrice[$cache_key] = $this->getMaxDeliveryPriceByPrice($id_zone);
|
||||
self::$price_by_price[$cache_key] = $this->getMaxDeliveryPriceByPrice($id_zone);
|
||||
else
|
||||
self::$priceByPrice[$cache_key] = $result['price'];
|
||||
self::$price_by_price[$cache_key] = $result['price'];
|
||||
}
|
||||
return self::$priceByPrice[$cache_key];
|
||||
return self::$price_by_price[$cache_key];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -283,27 +288,27 @@ class CarrierCore extends ObjectModel
|
||||
* @param integer $id_currency
|
||||
* @return float Delivery price
|
||||
*/
|
||||
public static function checkDeliveryPriceByPrice($id_carrier, $orderTotal, $id_zone, $id_currency = null, Shop $shop = null)
|
||||
public static function checkDeliveryPriceByPrice($id_carrier, $order_total, $id_zone, $id_currency = null, Shop $shop = null)
|
||||
{
|
||||
$cache_key = $id_carrier.'_'.$orderTotal.'_'.$id_zone.'_'.$id_currency;
|
||||
if (!isset(self::$priceByPrice2[$cache_key]))
|
||||
$cache_key = $id_carrier.'_'.$order_total.'_'.$id_zone.'_'.$id_currency;
|
||||
if (!isset(self::$price_by_price2[$cache_key]))
|
||||
{
|
||||
if (!empty($id_currency))
|
||||
$orderTotal = Tools::convertPrice($orderTotal, $id_currency, false);
|
||||
$order_total = Tools::convertPrice($order_total, $id_currency, false);
|
||||
|
||||
$sql = 'SELECT d.`price`
|
||||
FROM `'._DB_PREFIX_.'delivery` d
|
||||
LEFT JOIN `'._DB_PREFIX_.'range_price` r ON d.`id_range_price` = r.`id_range_price`
|
||||
WHERE d.`id_zone` = '.(int)($id_zone).'
|
||||
AND '.(float)$orderTotal.' >= r.`delimiter1`
|
||||
AND '.(float)$orderTotal.' < r.`delimiter2`
|
||||
WHERE d.`id_zone` = '.(int)$id_zone.'
|
||||
AND '.(float)$order_total.' >= r.`delimiter1`
|
||||
AND '.(float)$order_total.' < r.`delimiter2`
|
||||
AND d.`id_carrier` = '.(int)$id_carrier.'
|
||||
'.Carrier::sqlDeliveryRangeShop('range_price', $shop).'
|
||||
ORDER BY r.`delimiter1` ASC';
|
||||
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql);
|
||||
self::$priceByPrice2[$cache_key] = (isset($result['price']));
|
||||
self::$price_by_price2[$cache_key] = (isset($result['price']));
|
||||
}
|
||||
return self::$priceByPrice2[$cache_key];
|
||||
return self::$price_by_price2[$cache_key];
|
||||
}
|
||||
|
||||
public function getMaxDeliveryPriceByPrice($id_zone, Shop $shop = null)
|
||||
@@ -327,16 +332,16 @@ class CarrierCore extends ObjectModel
|
||||
* @param string $rangeTable Table name (price or weight)
|
||||
* @return array Delivery prices
|
||||
*/
|
||||
public static function getDeliveryPriceByRanges($rangeTable, $id_carrier, Shop $shop = null)
|
||||
public static function getDeliveryPriceByRanges($range_table, $id_carrier, Shop $shop = null)
|
||||
{
|
||||
$rangeTable = pSQL($rangeTable);
|
||||
$sql = 'SELECT d.id_'.$rangeTable.', d.id_carrier, d.id_zone, d.price
|
||||
$range_table = pSQL($range_table);
|
||||
$sql = 'SELECT d.id_'.$range_table.', d.id_carrier, d.id_zone, d.price
|
||||
FROM '._DB_PREFIX_.'delivery d
|
||||
LEFT JOIN '._DB_PREFIX_.$rangeTable.' r ON r.id_'.$rangeTable.' = d.id_'.$rangeTable.'
|
||||
LEFT JOIN '._DB_PREFIX_.$range_table.' r ON r.id_'.$range_table.' = d.id_'.$range_table.'
|
||||
WHERE d.id_carrier = '.(int)$id_carrier.'
|
||||
AND d.id_'.$rangeTable.' IS NOT NULL
|
||||
AND d.id_'.$rangeTable.' != 0
|
||||
'.Carrier::sqlDeliveryRangeShop($rangeTable, $shop).'
|
||||
AND d.id_'.$range_table.' IS NOT NULL
|
||||
AND d.id_'.$range_table.' != 0
|
||||
'.Carrier::sqlDeliveryRangeShop($range_table, $shop).'
|
||||
ORDER BY r.delimiter1';
|
||||
return Db::getInstance()->executeS($sql);
|
||||
}
|
||||
@@ -362,7 +367,7 @@ class CarrierCore extends ObjectModel
|
||||
{
|
||||
$ids = '';
|
||||
foreach ($ids_group as $id)
|
||||
$ids .= (int)($id).', ';
|
||||
$ids .= (int)$id.', ';
|
||||
$ids = rtrim($ids, ', ');
|
||||
if ($ids == '')
|
||||
return array();
|
||||
@@ -397,7 +402,8 @@ class CarrierCore extends ObjectModel
|
||||
|
||||
}
|
||||
$sql .= ($ids_group ? ' AND c.id_carrier IN (SELECT id_carrier FROM '._DB_PREFIX_.'carrier_group WHERE id_group IN ('.$ids.')) ' : '').'
|
||||
GROUP BY c.`id_carrier`';
|
||||
GROUP BY c.`id_carrier`
|
||||
ORDER BY c.`position` ASC';
|
||||
|
||||
$carriers = Db::getInstance()->executeS($sql);
|
||||
|
||||
@@ -413,9 +419,9 @@ class CarrierCore extends ObjectModel
|
||||
return $carriers;
|
||||
}
|
||||
|
||||
public static function getDeliveredCountries($id_lang, $activeCountries = false, $activeCarriers = false, $containStates = null)
|
||||
public static function getDeliveredCountries($id_lang, $active_countries = false, $active_carriers = false, $contain_states = null)
|
||||
{
|
||||
if (!Validate::isBool($activeCountries) || !Validate::isBool($activeCarriers))
|
||||
if (!Validate::isBool($active_countries) || !Validate::isBool($active_carriers))
|
||||
die(Tools::displayError());
|
||||
|
||||
$states = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
|
||||
@@ -426,12 +432,12 @@ class CarrierCore extends ObjectModel
|
||||
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
|
||||
SELECT cl.*,c.*, cl.`name` AS country, zz.`name` AS zone FROM `'._DB_PREFIX_.'country` c
|
||||
LEFT JOIN `'._DB_PREFIX_.'country_lang` cl ON (c.`id_country` = cl.`id_country` AND cl.`id_lang` = 1)
|
||||
INNER JOIN (`'._DB_PREFIX_.'carrier_zone` cz INNER JOIN `'._DB_PREFIX_.'carrier` cr ON ( cr.id_carrier = cz.id_carrier AND cr.deleted = 0 '.($activeCarriers ?
|
||||
'AND cr.active = 1) ' : ') ').'
|
||||
INNER JOIN (`'._DB_PREFIX_.'carrier_zone` cz INNER JOIN `'._DB_PREFIX_.'carrier` cr ON ( cr.id_carrier = cz.id_carrier AND cr.deleted = 0 '.
|
||||
($active_carriers ? 'AND cr.active = 1) ' : ') ').'
|
||||
LEFT JOIN `'._DB_PREFIX_.'zone` zz ON cz.id_zone = zz.id_zone) ON zz.`id_zone` = c.`id_zone`
|
||||
WHERE 1
|
||||
'.($activeCountries ? 'AND c.active = 1' : '').'
|
||||
'.(!is_null($containStates) ? 'AND c.`contains_states` = '.(int)($containStates) : '').'
|
||||
'.($active_countries ? 'AND c.active = 1' : '').'
|
||||
'.(!is_null($contain_states) ? 'AND c.`contains_states` = '.(int)$contain_states : '').'
|
||||
ORDER BY cl.name ASC');
|
||||
|
||||
$countries = array();
|
||||
@@ -451,22 +457,22 @@ class CarrierCore extends ObjectModel
|
||||
* @param array $defaultCarrier the last carrier selected
|
||||
* @return number the id of the default carrier
|
||||
*/
|
||||
public static function getDefaultCarrierSelection($carriers, $defaultCarrier = 0)
|
||||
public static function getDefaultCarrierSelection($carriers, $default_carrier = 0)
|
||||
{
|
||||
if(empty($carriers))
|
||||
if (empty($carriers))
|
||||
return 0;
|
||||
|
||||
if ((int)$defaultCarrier != 0)
|
||||
foreach ($carriers AS $carrier)
|
||||
if ($carrier['id_carrier'] == (int)$defaultCarrier)
|
||||
|
||||
if ((int)$default_carrier != 0)
|
||||
foreach ($carriers as $carrier)
|
||||
if ($carrier['id_carrier'] == (int)$default_carrier)
|
||||
return (int)$carrier['id_carrier'];
|
||||
foreach ($carriers AS $carrier)
|
||||
foreach ($carriers as $carrier)
|
||||
if ($carrier['id_carrier'] == (int)Configuration::get('PS_CARRIER_DEFAULT'))
|
||||
return (int)$carrier['id_carrier'];
|
||||
|
||||
|
||||
return (int)$carriers[0]['id_carrier'];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param int $id_zone
|
||||
@@ -484,44 +490,45 @@ class CarrierCore extends ObjectModel
|
||||
$result = Carrier::getCarriers($id_lang, true, false, (int)$id_zone, $groups, self::PS_CARRIERS_AND_CARRIER_MODULES_NEED_RANGE);
|
||||
else
|
||||
$result = Carrier::getCarriers($id_lang, true, false, (int)$id_zone, array(1), self::PS_CARRIERS_AND_CARRIER_MODULES_NEED_RANGE);
|
||||
$resultsArray = array();
|
||||
$results_array = array();
|
||||
|
||||
foreach ($result as $k => $row)
|
||||
{
|
||||
$carrier = new Carrier((int)$row['id_carrier']);
|
||||
$shippingMethod = $carrier->getShippingMethod();
|
||||
if ($shippingMethod != Carrier::SHIPPING_METHOD_FREE)
|
||||
$shipping_method = $carrier->getShippingMethod();
|
||||
if ($shipping_method != Carrier::SHIPPING_METHOD_FREE)
|
||||
{
|
||||
// Get only carriers that are compliant with shipping method
|
||||
if (($shippingMethod == Carrier::SHIPPING_METHOD_WEIGHT && $carrier->getMaxDeliveryPriceByWeight($id_zone) === false)
|
||||
|| ($shippingMethod == Carrier::SHIPPING_METHOD_PRICE && $carrier->getMaxDeliveryPriceByPrice($id_zone) === false))
|
||||
{
|
||||
unset($result[$k]);
|
||||
continue;
|
||||
}
|
||||
// Get only carriers that are compliant with shipping method
|
||||
if (($shipping_method == Carrier::SHIPPING_METHOD_WEIGHT && $carrier->getMaxDeliveryPriceByWeight($id_zone) === false)
|
||||
|| ($shipping_method == Carrier::SHIPPING_METHOD_PRICE && $carrier->getMaxDeliveryPriceByPrice($id_zone) === false))
|
||||
{
|
||||
unset($result[$k]);
|
||||
continue;
|
||||
}
|
||||
|
||||
// If out-of-range behavior carrier is set on "Desactivate carrier"
|
||||
if ($row['range_behavior'])
|
||||
{
|
||||
// Get id zone
|
||||
if (!$id_zone)
|
||||
$id_zone = Country::getIdZone(Country::getDefaultCountryId());
|
||||
// If out-of-range behavior carrier is set on "Desactivate carrier"
|
||||
if ($row['range_behavior'])
|
||||
{
|
||||
// Get id zone
|
||||
if (!$id_zone)
|
||||
$id_zone = Country::getIdZone(Country::getDefaultCountryId());
|
||||
|
||||
// Get only carriers that have a range compatible with cart
|
||||
if (($shippingMethod == Carrier::SHIPPING_METHOD_WEIGHT && (!Carrier::checkDeliveryPriceByWeight($row['id_carrier'], $cart->getTotalWeight(), $id_zone)))
|
||||
|| ($shippingMethod == Carrier::SHIPPING_METHOD_PRICE
|
||||
// Get only carriers that have a range compatible with cart
|
||||
if (($shipping_method == Carrier::SHIPPING_METHOD_WEIGHT
|
||||
&& (!Carrier::checkDeliveryPriceByWeight($row['id_carrier'], $cart->getTotalWeight(), $id_zone)))
|
||||
|| ($shipping_method == Carrier::SHIPPING_METHOD_PRICE
|
||||
&& (!Carrier::checkDeliveryPriceByPrice($row['id_carrier'], $cart->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING), $id_zone, $id_currency))))
|
||||
{
|
||||
unset($result[$k]);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$row['name'] = (strval($row['name']) != '0' ? $row['name'] : Configuration::get('PS_SHOP_NAME'));
|
||||
$row['price'] = ($shippingMethod == Carrier::SHIPPING_METHOD_FREE ? 0 : $cart->getOrderShippingCost((int)$row['id_carrier']));
|
||||
$row['price_tax_exc'] = ($shippingMethod == Carrier::SHIPPING_METHOD_FREE ? 0 : $cart->getOrderShippingCost((int)$row['id_carrier'], false));
|
||||
$row['img'] = file_exists(_PS_SHIP_IMG_DIR_.(int)($row['id_carrier']).'.jpg') ? _THEME_SHIP_DIR_.(int)($row['id_carrier']).'.jpg' : '';
|
||||
$row['price'] = ($shipping_method == Carrier::SHIPPING_METHOD_FREE ? 0 : $cart->getOrderShippingCost((int)$row['id_carrier']));
|
||||
$row['price_tax_exc'] = ($shipping_method == Carrier::SHIPPING_METHOD_FREE ? 0 : $cart->getOrderShippingCost((int)$row['id_carrier'], false));
|
||||
$row['img'] = file_exists(_PS_SHIP_IMG_DIR_.(int)$row['id_carrier']).'.jpg' ? _THEME_SHIP_DIR_.(int)$row['id_carrier'].'.jpg' : '';
|
||||
|
||||
// If price is false, then the carrier is unavailable (carrier module)
|
||||
if ($row['price'] === false)
|
||||
@@ -529,10 +536,9 @@ class CarrierCore extends ObjectModel
|
||||
unset($result[$k]);
|
||||
continue;
|
||||
}
|
||||
|
||||
$resultsArray[] = $row;
|
||||
$results_array[] = $row;
|
||||
}
|
||||
return $resultsArray;
|
||||
return $results_array;
|
||||
}
|
||||
|
||||
public static function checkCarrierZone($id_carrier, $id_zone)
|
||||
@@ -541,11 +547,11 @@ class CarrierCore extends ObjectModel
|
||||
SELECT c.`id_carrier`
|
||||
FROM `'._DB_PREFIX_.'carrier` c
|
||||
LEFT JOIN `'._DB_PREFIX_.'carrier_zone` cz ON (cz.`id_carrier` = c.`id_carrier`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'zone` z ON (z.`id_zone` = '.(int)($id_zone).')
|
||||
WHERE c.`id_carrier` = '.(int)($id_carrier).'
|
||||
LEFT JOIN `'._DB_PREFIX_.'zone` z ON (z.`id_zone` = '.(int)$id_zone.')
|
||||
WHERE c.`id_carrier` = '.(int)$id_carrier.'
|
||||
AND c.`deleted` = 0
|
||||
AND c.`active` = 1
|
||||
AND cz.`id_zone` = '.(int)($id_zone).'
|
||||
AND cz.`id_zone` = '.(int)$id_zone.'
|
||||
AND z.`active` = 1'
|
||||
);
|
||||
}
|
||||
@@ -561,7 +567,7 @@ class CarrierCore extends ObjectModel
|
||||
SELECT *
|
||||
FROM `'._DB_PREFIX_.'carrier_zone` cz
|
||||
LEFT JOIN `'._DB_PREFIX_.'zone` z ON cz.`id_zone` = z.`id_zone`
|
||||
WHERE cz.`id_carrier` = '.(int)($this->id));
|
||||
WHERE cz.`id_carrier` = '.(int)$this->id);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -574,8 +580,8 @@ class CarrierCore extends ObjectModel
|
||||
return Db::getInstance()->executeS('
|
||||
SELECT *
|
||||
FROM `'._DB_PREFIX_.'carrier_zone`
|
||||
WHERE `id_carrier` = '.(int)($this->id).'
|
||||
AND `id_zone` = '.(int)($id_zone));
|
||||
WHERE `id_carrier` = '.(int)$this->id.'
|
||||
AND `id_zone` = '.(int)$id_zone);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -585,7 +591,7 @@ class CarrierCore extends ObjectModel
|
||||
{
|
||||
return Db::getInstance()->execute('
|
||||
INSERT INTO `'._DB_PREFIX_.'carrier_zone` (`id_carrier` , `id_zone`)
|
||||
VALUES ('.(int)($this->id).', '.(int)($id_zone).')');
|
||||
VALUES ('.(int)$this->id.', '.(int)$id_zone.')');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -595,8 +601,8 @@ class CarrierCore extends ObjectModel
|
||||
{
|
||||
return Db::getInstance()->execute('
|
||||
DELETE FROM `'._DB_PREFIX_.'carrier_zone`
|
||||
WHERE `id_carrier` = '.(int)($this->id).'
|
||||
AND `id_zone` = '.(int)($id_zone).' LIMIT 1');
|
||||
WHERE `id_carrier` = '.(int)$this->id.'
|
||||
AND `id_zone` = '.(int)$id_zone.' LIMIT 1');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -605,20 +611,20 @@ class CarrierCore extends ObjectModel
|
||||
* @param string $rangeTable Table name to clean (weight or price according to shipping method)
|
||||
* @return boolean Deletion result
|
||||
*/
|
||||
public function deleteDeliveryPrice($rangeTable, Shop $shop = null)
|
||||
public function deleteDeliveryPrice($range_table, Shop $shop = null)
|
||||
{
|
||||
$where = '`id_carrier` = '.(int)$this->id.' AND (`id_'.$rangeTable.'` IS NOT NULL OR `id_'.$rangeTable.'` = 0) ';
|
||||
$where = '`id_carrier` = '.(int)$this->id.' AND (`id_'.$range_table.'` IS NOT NULL OR `id_'.$range_table.'` = 0) ';
|
||||
|
||||
if (!$shop)
|
||||
$shop = Context::getContext()->shop;
|
||||
$shopID = $shop->getID();
|
||||
$shopGroupID = $shop->getGroupID();
|
||||
if (!$shopID && !$shopGroupID)
|
||||
$shop_id = $shop->getID();
|
||||
$shop_group_id = $shop->getGroupID();
|
||||
if (!$shop_id && !$shop_group_id)
|
||||
$where .= 'AND id_shop IS NULL AND id_group_shop IS NULL';
|
||||
else if (!$shopID)
|
||||
$where .= 'AND id_shop IS NULL AND id_group_shop = '.$shopGroupID;
|
||||
else if (!$shop_id)
|
||||
$where .= 'AND id_shop IS NULL AND id_group_shop = '.$shop_group_id;
|
||||
else
|
||||
$where .= 'AND id_shop = '.$shopID;
|
||||
$where .= 'AND id_shop = '.$shop_id;
|
||||
|
||||
return Db::getInstance()->delete(_DB_PREFIX_.'delivery', $where);
|
||||
}
|
||||
@@ -629,12 +635,12 @@ class CarrierCore extends ObjectModel
|
||||
* @param array $priceList Prices list in multiple arrays (changed to array since 1.5.0)
|
||||
* @return boolean Insertion result
|
||||
*/
|
||||
public function addDeliveryPrice($priceList, Shop $shop = null)
|
||||
public function addDeliveryPrice($price_list, Shop $shop = null)
|
||||
{
|
||||
if (!$priceList)
|
||||
if (!$price_list)
|
||||
return false;
|
||||
|
||||
$keys = array_keys($priceList[0]);
|
||||
$keys = array_keys($price_list[0]);
|
||||
if (!in_array('id_shop', $keys))
|
||||
$keys[] = 'id_shop';
|
||||
if (!in_array('id_group_shop', $keys))
|
||||
@@ -642,16 +648,16 @@ class CarrierCore extends ObjectModel
|
||||
|
||||
if (!$shop)
|
||||
$shop = Context::getContext()->shop;
|
||||
$shopID = $shop->getID();
|
||||
$shopGroupID = $shop->getGroupID();
|
||||
$shop_id = $shop->getID();
|
||||
$shop_group_id = $shop->getGroupID();
|
||||
|
||||
$sql = 'INSERT INTO `'._DB_PREFIX_.'delivery` ('.implode(', ', $keys).') VALUES ';
|
||||
foreach ($priceList as $values)
|
||||
foreach ($price_list as $values)
|
||||
{
|
||||
if (!isset($values['id_shop']))
|
||||
$values['id_shop'] = ($shopID) ? $shopID : null;
|
||||
$values['id_shop'] = ($shop_id) ? $shop_id : null;
|
||||
if (!isset($values['id_group_shop']))
|
||||
$values['id_group_shop'] = ($shopGroupID) ? $shopGroupID : null;
|
||||
$values['id_group_shop'] = ($shop_group_id) ? $shop_group_id : null;
|
||||
|
||||
$sql .= '(';
|
||||
foreach ($values as $v)
|
||||
@@ -675,36 +681,36 @@ class CarrierCore extends ObjectModel
|
||||
*
|
||||
* @param integer $oldId Old id carrier (copy from that id)
|
||||
*/
|
||||
public function copyCarrierData($oldId)
|
||||
public function copyCarrierData($old_id)
|
||||
{
|
||||
if (!Validate::isUnsignedId($oldId))
|
||||
if (!Validate::isUnsignedId($old_id))
|
||||
die(Tools::displayError());
|
||||
|
||||
if (!$this->id)
|
||||
return false;
|
||||
|
||||
$oldLogo = _PS_SHIP_IMG_DIR_.'/'.(int)$oldId.'.jpg';
|
||||
if (file_exists($oldLogo))
|
||||
copy($oldLogo, _PS_SHIP_IMG_DIR_.'/'.$this->id.'.jpg');
|
||||
$old_logo = _PS_SHIP_IMG_DIR_.'/'.(int)$old_id.'.jpg';
|
||||
if (file_exists($old_logo))
|
||||
copy($old_logo, _PS_SHIP_IMG_DIR_.'/'.$this->id.'.jpg');
|
||||
|
||||
// Copy existing ranges price
|
||||
foreach (array('range_price', 'range_weight') as $range)
|
||||
{
|
||||
$sql = 'SELECT id_'.$range.' id_range, delimiter1, delimiter2 FROM `'._DB_PREFIX_.$range.'`
|
||||
WHERE id_carrier = '.(int)$oldId;
|
||||
WHERE id_carrier = '.(int)$old_id;
|
||||
$res = Db::getInstance()->executeS($sql);
|
||||
foreach ($res as $val)
|
||||
{
|
||||
$sql = 'INSERT INTO `'._DB_PREFIX_.$range.'` (`id_carrier`, `delimiter1`, `delimiter2`)
|
||||
VALUES ('.$this->id.','.(float)$val['delimiter1'].','.(float)$val['delimiter2'].')';
|
||||
Db::getInstance()->execute($sql);
|
||||
$rangeID = (int)Db::getInstance()->Insert_ID();
|
||||
$range_id = (int)Db::getInstance()->Insert_ID();
|
||||
|
||||
$rangePriceID = ($range == 'range_price') ? $rangeID : 'NULL';
|
||||
$rangeWeightID = ($range == 'range_weight') ? $rangeID : 'NULL';
|
||||
$range_price_id = ($range == 'range_price') ? $range_id : 'NULL';
|
||||
$range_weight_id = ($range == 'range_weight') ? $range_id : 'NULL';
|
||||
$sql = 'INSERT INTO '._DB_PREFIX_.'delivery (id_carrier, id_range_price, id_range_weight, id_zone, price)
|
||||
SELECT '.$this->id.', '.$rangePriceID.', '.$rangeWeightID.', id_zone, price FROM '._DB_PREFIX_.'delivery
|
||||
WHERE id_carrier = '.(int)$oldId.' AND '.(($range == 'range_price') ? 'id_range_price' : 'id_range_weight').' = '.$val['id_range'];
|
||||
SELECT '.$this->id.', '.$range_price_id.', '.$range_weight_id.', id_zone, price FROM '._DB_PREFIX_.'delivery
|
||||
WHERE id_carrier = '.(int)$old_id.' AND '.(($range == 'range_price') ? 'id_range_price' : 'id_range_weight').' = '.$val['id_range'];
|
||||
|
||||
Db::getInstance()->execute($sql);
|
||||
}
|
||||
@@ -712,18 +718,18 @@ class CarrierCore extends ObjectModel
|
||||
|
||||
// Copy existing zones
|
||||
$res = Db::getInstance()->executeS('SELECT * FROM `'._DB_PREFIX_.'carrier_zone`
|
||||
WHERE id_carrier = '.(int)$oldId);
|
||||
WHERE id_carrier = '.(int)$old_id);
|
||||
foreach ($res as $val)
|
||||
Db::getInstance()->execute('
|
||||
INSERT INTO `'._DB_PREFIX_.'carrier_zone` (`id_carrier`, `id_zone`)
|
||||
VALUES ('.$this->id.','.(int)$val['id_zone'].')');
|
||||
|
||||
//Copy default carrier
|
||||
if ((int)(Configuration::get('PS_CARRIER_DEFAULT')) == $oldId)
|
||||
Configuration::updateValue('PS_CARRIER_DEFAULT', (int)($this->id));
|
||||
|
||||
if ((int)Configuration::get('PS_CARRIER_DEFAULT') == $old_id)
|
||||
Configuration::updateValue('PS_CARRIER_DEFAULT', (int)$this->id);
|
||||
|
||||
// Copy reference
|
||||
$id_reference = Db::getInstance()->getValue('SELECT `id_reference` FROM `'._DB_PREFIX_.$this->table.'` WHERE id_carrier = '.$oldId);
|
||||
$id_reference = Db::getInstance()->getValue('SELECT `id_reference` FROM `'._DB_PREFIX_.$this->table.'` WHERE id_carrier = '.$old_id);
|
||||
Db::getInstance()->execute('UPDATE `'._DB_PREFIX_.$this->table.'`
|
||||
SET `id_reference` = '.$id_reference.'
|
||||
WHERE `id_carrier` = '.$this->id);
|
||||
@@ -741,7 +747,7 @@ class CarrierCore extends ObjectModel
|
||||
return false;
|
||||
return new Carrier($id_carrier);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if carrier is used (at least one order placed)
|
||||
*
|
||||
@@ -752,9 +758,9 @@ class CarrierCore extends ObjectModel
|
||||
$row = Db::getInstance()->getRow('
|
||||
SELECT COUNT(`id_carrier`) AS total
|
||||
FROM `'._DB_PREFIX_.'orders`
|
||||
WHERE `id_carrier` = '.(int)($this->id));
|
||||
WHERE `id_carrier` = '.(int)$this->id);
|
||||
|
||||
return (int)($row['total']);
|
||||
return (int)$row['total'];
|
||||
}
|
||||
|
||||
public function getShippingMethod()
|
||||
@@ -778,20 +784,20 @@ class CarrierCore extends ObjectModel
|
||||
|
||||
public function getRangeTable()
|
||||
{
|
||||
$shippingMethod = $this->getShippingMethod();
|
||||
if ($shippingMethod == Carrier::SHIPPING_METHOD_WEIGHT)
|
||||
$shipping_method = $this->getShippingMethod();
|
||||
if ($shipping_method == Carrier::SHIPPING_METHOD_WEIGHT)
|
||||
return 'range_weight';
|
||||
else if ($shippingMethod == Carrier::SHIPPING_METHOD_PRICE)
|
||||
else if ($shipping_method == Carrier::SHIPPING_METHOD_PRICE)
|
||||
return 'range_price';
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getRangeObject()
|
||||
{
|
||||
$shippingMethod = $this->getShippingMethod();
|
||||
if ($shippingMethod == Carrier::SHIPPING_METHOD_WEIGHT)
|
||||
$shipping_method = $this->getShippingMethod();
|
||||
if ($shipping_method == Carrier::SHIPPING_METHOD_WEIGHT)
|
||||
return new RangeWeight();
|
||||
else if ($shippingMethod == Carrier::SHIPPING_METHOD_PRICE)
|
||||
else if ($shipping_method == Carrier::SHIPPING_METHOD_PRICE)
|
||||
return new RangePrice();
|
||||
return false;
|
||||
}
|
||||
@@ -808,15 +814,15 @@ class CarrierCore extends ObjectModel
|
||||
|
||||
public static function getIdTaxRulesGroupByIdCarrier($id_carrier)
|
||||
{
|
||||
if (!isset(self::$_cache_tax_rule[(int)$id_carrier]))
|
||||
if (!isset(self::$cache_tax_rule[(int)$id_carrier]))
|
||||
{
|
||||
self::$_cache_tax_rule[$id_carrier] = Db::getInstance()->getValue('
|
||||
self::$cache_tax_rule[$id_carrier] = Db::getInstance()->getValue('
|
||||
SELECT `id_tax_rules_group`
|
||||
FROM `'._DB_PREFIX_.'carrier`
|
||||
WHERE `id_carrier` = '.(int)$id_carrier);
|
||||
}
|
||||
|
||||
return self::$_cache_tax_rule[$id_carrier];
|
||||
return self::$cache_tax_rule[$id_carrier];
|
||||
}
|
||||
|
||||
|
||||
@@ -841,31 +847,113 @@ class CarrierCore extends ObjectModel
|
||||
* @param Shop $shop
|
||||
* @return string
|
||||
*/
|
||||
public static function sqlDeliveryRangeShop($rangeTable, Shop $shop = null, $alias = 'd')
|
||||
public static function sqlDeliveryRangeShop($range_table, Shop $shop = null, $alias = 'd')
|
||||
{
|
||||
if (!$shop)
|
||||
$shop = Context::getContext()->shop;
|
||||
$shopID = $shop->getID();
|
||||
$shopGroupID = $shop->getGroupID();
|
||||
$shop_id = $shop->getID();
|
||||
$shop_group_id = $shop->getGroupID();
|
||||
$where = '';
|
||||
if (!$shopID && !$shopGroupID)
|
||||
if (!$shop_id && !$shop_group_id)
|
||||
$where = 'AND d2.id_shop IS NULL AND d2.id_group_shop IS NULL';
|
||||
else if (!$shopID)
|
||||
$where = 'AND ((d2.id_group_shop IS NULL OR d2.id_group_shop = '.$shopGroupID.') AND d2.id_shop IS NULL)';
|
||||
else if (!$shop_id)
|
||||
$where = 'AND ((d2.id_group_shop IS NULL OR d2.id_group_shop = '.$shop_group_id.') AND d2.id_shop IS NULL)';
|
||||
else
|
||||
$where = 'AND (d2.id_shop = '.$shopID.' OR (d2.id_group_shop = '.$shopGroupID.' AND d2.id_shop IS NULL) OR (d2.id_group_shop IS NULL AND d2.id_shop IS NULL))';
|
||||
$where = 'AND (d2.id_shop = '.$shop_id.' OR (d2.id_group_shop = '.$shop_group_id.'
|
||||
AND d2.id_shop IS NULL) OR (d2.id_group_shop IS NULL AND d2.id_shop IS NULL))';
|
||||
|
||||
$sql = 'AND '.$alias.'.id_delivery = (
|
||||
SELECT d2.id_delivery
|
||||
FROM '._DB_PREFIX_.'delivery d2
|
||||
WHERE d2.id_carrier = '.$alias.'.id_carrier
|
||||
AND d2.id_zone = '.$alias.'.id_zone
|
||||
AND d2.id_'.$rangeTable.' = '.$alias.'.id_'.$rangeTable.'
|
||||
AND d2.id_'.$range_table.' = '.$alias.'.id_'.$range_table.'
|
||||
'.$where.'
|
||||
ORDER BY d2.id_shop DESC, d2.id_group_shop DESC
|
||||
LIMIT 1
|
||||
)';
|
||||
return $sql;
|
||||
}
|
||||
|
||||
/**
|
||||
* Move a carrier
|
||||
* @param boolean $way Up (1) or Down (0)
|
||||
* @param integer $position
|
||||
* @return boolean Update result
|
||||
*/
|
||||
public function updatePosition($way, $position)
|
||||
{
|
||||
if (!$res = Db::getInstance()->executeS('
|
||||
SELECT `id_carrier`, `position`
|
||||
FROM `'._DB_PREFIX_.'carrier`
|
||||
WHERE `deleted` = 0
|
||||
ORDER BY `position` ASC'
|
||||
))
|
||||
return false;
|
||||
|
||||
foreach ($res as $carrier)
|
||||
if ((int)$carrier['id_carrier'] == (int)$this->id)
|
||||
$moved_carrier = $carrier;
|
||||
|
||||
if (!isset($moved_carrier) || !isset($position))
|
||||
return false;
|
||||
|
||||
// < and > statements rather than BETWEEN operator
|
||||
// since BETWEEN is treated differently according to databases
|
||||
return (Db::getInstance()->execute('
|
||||
UPDATE `'._DB_PREFIX_.'carrier`
|
||||
SET `position`= `position` '.($way ? '- 1' : '+ 1').'
|
||||
WHERE `position`
|
||||
'.($way
|
||||
? '> '.(int)$moved_carrier['position'].' AND `position` <= '.(int)$position
|
||||
: '< '.(int)$moved_carrier['position'].' AND `position` >= '.(int)$position.'
|
||||
AND `deleted` = 0'))
|
||||
&& Db::getInstance()->execute('
|
||||
UPDATE `'._DB_PREFIX_.'carrier`
|
||||
SET `position` = '.(int)$position.'
|
||||
WHERE `id_carrier` = '.(int)$moved_carrier['id_carrier']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Reorder carrier position.
|
||||
* Call it after deleting a carrier.
|
||||
*
|
||||
* @return bool $return
|
||||
*/
|
||||
public static function cleanPositions()
|
||||
{
|
||||
$return = true;
|
||||
|
||||
$sql = '
|
||||
SELECT `id_carrier`
|
||||
FROM `'._DB_PREFIX_.'carrier`
|
||||
WHERE `deleted` = 0
|
||||
ORDER BY `position` ASC';
|
||||
$result = Db::getInstance()->executeS($sql);
|
||||
|
||||
$i = 0;
|
||||
foreach ($result as $value)
|
||||
$return = Db::getInstance()->execute('
|
||||
UPDATE `'._DB_PREFIX_.'carrier`
|
||||
SET `position` = '.(int)$i++.'
|
||||
WHERE `id_carrier` = '.(int)$value['id_carrier']);
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* getHigherPosition
|
||||
*
|
||||
* Get the higher carrier position
|
||||
*
|
||||
* @return integer $position
|
||||
*/
|
||||
public static function getHigherPosition()
|
||||
{
|
||||
$sql = 'SELECT MAX(`position`)
|
||||
FROM `'._DB_PREFIX_.'carrier`
|
||||
WHERE `deleted` = 0';
|
||||
$position = DB::getInstance()->getValue($sql);
|
||||
return ($position !== false) ? $position : -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+96
-96
@@ -315,7 +315,7 @@ class ProductCore extends ObjectModel
|
||||
if (!$context)
|
||||
$context = Context::getContext();
|
||||
|
||||
if ($full AND $this->id)
|
||||
if ($full && $this->id)
|
||||
{
|
||||
$this->isFullyLoaded = $full;
|
||||
$this->tax_name = 'deprecated'; // The applicable tax may be BOTH the product one AND the state one (moreover this variable is some deadcode)
|
||||
@@ -330,7 +330,7 @@ class ProductCore extends ObjectModel
|
||||
$this->tax_rate = $this->getTaxesRate(new Address($address));
|
||||
|
||||
$this->new = $this->isNew();
|
||||
$this->price = Product::getPriceStatic((int)($this->id), false, null, 6, null, false, true, 1, false, null, null, null, $this->specificPrice);
|
||||
$this->price = Product::getPriceStatic((int)$this->id, false, null, 6, null, false, true, 1, false, null, null, null, $this->specificPrice);
|
||||
$this->unit_price = ($this->unit_price_ratio != 0 ? $this->price / $this->unit_price_ratio : 0);
|
||||
if ($this->id)
|
||||
$this->tags = Tag::getProductTags((int)$this->id);
|
||||
@@ -346,45 +346,45 @@ class ProductCore extends ObjectModel
|
||||
{
|
||||
$this->validateFields();
|
||||
if (isset($this->id))
|
||||
$fields['id_product'] = (int)($this->id);
|
||||
$fields['id_tax_rules_group'] = (int)($this->id_tax_rules_group);
|
||||
$fields['id_manufacturer'] = (int)($this->id_manufacturer);
|
||||
$fields['id_supplier'] = (int)($this->id_supplier);
|
||||
$fields['id_category_default'] = (int)($this->id_category_default);
|
||||
$fields['quantity'] = (int)($this->quantity);
|
||||
$fields['minimal_quantity'] = (int)($this->minimal_quantity);
|
||||
$fields['price'] = (float)($this->price);
|
||||
$fields['additional_shipping_cost'] = (float)($this->additional_shipping_cost);
|
||||
$fields['wholesale_price'] = (float)($this->wholesale_price);
|
||||
$fields['on_sale'] = (int)($this->on_sale);
|
||||
$fields['online_only'] = (int)($this->online_only);
|
||||
$fields['ecotax'] = (float)($this->ecotax);
|
||||
$fields['id_product'] = (int)$this->id;
|
||||
$fields['id_tax_rules_group'] = (int)$this->id_tax_rules_group;
|
||||
$fields['id_manufacturer'] = (int)$this->id_manufacturer;
|
||||
$fields['id_supplier'] = (int)$this->id_supplier;
|
||||
$fields['id_category_default'] = (int)$this->id_category_default;
|
||||
$fields['quantity'] = (int)$this->quantity;
|
||||
$fields['minimal_quantity'] = (int)$this->minimal_quantity;
|
||||
$fields['price'] = (float)$this->price;
|
||||
$fields['additional_shipping_cost'] = (float)$this->additional_shipping_cost;
|
||||
$fields['wholesale_price'] = (float)$this->wholesale_price;
|
||||
$fields['on_sale'] = (int)$this->on_sale;
|
||||
$fields['online_only'] = (int)$this->online_only;
|
||||
$fields['ecotax'] = (float)$this->ecotax;
|
||||
$fields['unity'] = pSQL($this->unity);
|
||||
$fields['unit_price_ratio'] = (float)($this->unit_price > 0 ? $this->price / $this->unit_price : 0);
|
||||
$fields['unit_price_ratio'] = (float)$this->unit_price > 0 ? $this->price / $this->unit_price : 0;
|
||||
$fields['ean13'] = pSQL($this->ean13);
|
||||
$fields['upc'] = pSQL($this->upc);
|
||||
$fields['reference'] = pSQL($this->reference);
|
||||
$fields['supplier_reference'] = pSQL($this->supplier_reference);
|
||||
$fields['location'] = pSQL($this->location);
|
||||
$fields['width'] = (float)($this->width);
|
||||
$fields['height'] = (float)($this->height);
|
||||
$fields['depth'] = (float)($this->depth);
|
||||
$fields['weight'] = (float)($this->weight);
|
||||
$fields['width'] = (float)$this->width;
|
||||
$fields['height'] = (float)$this->height;
|
||||
$fields['depth'] = (float)$this->depth;
|
||||
$fields['weight'] = (float)$this->weight;
|
||||
$fields['out_of_stock'] = pSQL($this->out_of_stock);
|
||||
$fields['quantity_discount'] = (int)($this->quantity_discount);
|
||||
$fields['customizable'] = (int)($this->customizable);
|
||||
$fields['uploadable_files'] = (int)($this->uploadable_files);
|
||||
$fields['text_fields'] = (int)($this->text_fields);
|
||||
$fields['active'] = (int)($this->active);
|
||||
$fields['available_for_order'] = (int)($this->available_for_order);
|
||||
$fields['quantity_discount'] = (int)$this->quantity_discount;
|
||||
$fields['customizable'] = (int)$this->customizable;
|
||||
$fields['uploadable_files'] = (int)$this->uploadable_files;
|
||||
$fields['text_fields'] = (int)$this->text_fields;
|
||||
$fields['active'] = (int)$this->active;
|
||||
$fields['available_for_order'] = (int)$this->available_for_order;
|
||||
$fields['available_date'] = pSQL($this->available_date);
|
||||
$fields['condition'] = pSQL($this->condition);
|
||||
$fields['show_price'] = (int)($this->show_price);
|
||||
$fields['show_price'] = (int)$this->show_price;
|
||||
$fields['indexed'] = 0; // Reset indexation every times
|
||||
$fields['cache_is_pack'] = (int)($this->cache_is_pack);
|
||||
$fields['cache_has_attachments'] = (int)($this->cache_has_attachments);
|
||||
$fields['is_virtual'] = (int)($this->is_virtual);
|
||||
$fields['cache_default_attribute'] = (int)($this->cache_default_attribute);
|
||||
$fields['cache_is_pack'] = (int)$this->cache_is_pack;
|
||||
$fields['cache_has_attachments'] = (int)$this->cache_has_attachments;
|
||||
$fields['is_virtual'] = (int)$this->is_virtual;
|
||||
$fields['cache_default_attribute'] = (int)$this->cache_default_attribute;
|
||||
$fields['date_add'] = pSQL($this->date_add);
|
||||
$fields['date_upd'] = pSQL($this->date_upd);
|
||||
|
||||
@@ -432,10 +432,10 @@ class ProductCore extends ObjectModel
|
||||
{
|
||||
if ($id_customer)
|
||||
{
|
||||
$customer = new Customer((int)($id_customer));
|
||||
$customer = new Customer((int)$id_customer);
|
||||
if (!Validate::isLoadedObject($customer))
|
||||
die(Tools::displayError());
|
||||
self::$_taxCalculationMethod = Group::getPriceDisplayMethod((int)($customer->id_default_group));
|
||||
self::$_taxCalculationMethod = Group::getPriceDisplayMethod((int)$customer->id_default_group);
|
||||
}
|
||||
else if (Validate::isLoadedObject(Context::getContext()->customer))
|
||||
self::$_taxCalculationMethod = Group::getPriceDisplayMethod(Context::getContext()->customer->id_default_group);
|
||||
@@ -446,8 +446,8 @@ class ProductCore extends ObjectModel
|
||||
public static function getTaxCalculationMethod($id_customer = null)
|
||||
{
|
||||
if ($id_customer)
|
||||
self::initPricesComputation((int)($id_customer));
|
||||
return (int)(self::$_taxCalculationMethod);
|
||||
self::initPricesComputation((int)$id_customer);
|
||||
return (int)self::$_taxCalculationMethod;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -461,13 +461,13 @@ class ProductCore extends ObjectModel
|
||||
if (!$res = Db::getInstance()->executeS('
|
||||
SELECT cp.`id_product`, cp.`position`, cp.`id_category`
|
||||
FROM `'._DB_PREFIX_.'category_product` cp
|
||||
WHERE cp.`id_category` = '.(int)(Tools::getValue('id_category', 1)).'
|
||||
WHERE cp.`id_category` = '.(int)Tools::getValue('id_category', 1).'
|
||||
ORDER BY cp.`position` ASC'
|
||||
))
|
||||
return false;
|
||||
|
||||
foreach ($res as $product)
|
||||
if ((int)($product['id_product']) == (int)($this->id))
|
||||
if ((int)$product['id_product'] == (int)$this->id)
|
||||
$movedProduct = $product;
|
||||
|
||||
if (!isset($movedProduct) || !isset($position))
|
||||
@@ -480,14 +480,14 @@ class ProductCore extends ObjectModel
|
||||
SET `position`= `position` '.($way ? '- 1' : '+ 1').'
|
||||
WHERE `position`
|
||||
'.($way
|
||||
? '> '.(int)($movedProduct['position']).' AND `position` <= '.(int)($position)
|
||||
: '< '.(int)($movedProduct['position']).' AND `position` >= '.(int)($position)).'
|
||||
AND `id_category`='.(int)($movedProduct['id_category']))
|
||||
? '> '.(int)$movedProduct['position'].' AND `position` <= '.(int)$position
|
||||
: '< '.(int)$movedProduct['position'].' AND `position` >= '.(int)$position).'
|
||||
AND `id_category`='.(int)$movedProduct['id_category'])
|
||||
AND Db::getInstance()->execute('
|
||||
UPDATE `'._DB_PREFIX_.'category_product`
|
||||
SET `position` = '.(int)($position).'
|
||||
WHERE `id_product` = '.(int)($movedProduct['id_product']).'
|
||||
AND `id_category`='.(int)($movedProduct['id_category'])));
|
||||
SET `position` = '.(int)$position.'
|
||||
WHERE `id_product` = '.(int)$movedProduct['id_product'].'
|
||||
AND `id_category`='.(int)$movedProduct['id_category']));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -503,16 +503,16 @@ class ProductCore extends ObjectModel
|
||||
$result = Db::getInstance()->executeS('
|
||||
SELECT `id_product`
|
||||
FROM `'._DB_PREFIX_.'category_product`
|
||||
WHERE `id_category` = '.(int)($id_category).'
|
||||
WHERE `id_category` = '.(int)$id_category.'
|
||||
ORDER BY `position`');
|
||||
$sizeof = count($result);
|
||||
|
||||
for ($i = 0; $i < $sizeof; $i++)
|
||||
$return &= Db::getInstance()->execute('
|
||||
UPDATE `'._DB_PREFIX_.'category_product`
|
||||
SET `position` = '.(int)($i).'
|
||||
WHERE `id_category` = '.(int)($id_category).'
|
||||
AND `id_product` = '.(int)($result[$i]['id_product']));
|
||||
SET `position` = '.(int)$i.'
|
||||
WHERE `id_category` = '.(int)$id_category.'
|
||||
AND `id_product` = '.(int)$result[$i]['id_product']);
|
||||
return $return;
|
||||
}
|
||||
|
||||
@@ -566,7 +566,7 @@ class ProductCore extends ObjectModel
|
||||
public static function updateDefaultAttribute($id_product)
|
||||
{
|
||||
$id_product_attribute = self::getDefaultAttribute($id_product);
|
||||
Db::getInstance()->execute('UPDATE '._DB_PREFIX_.'product SET cache_default_attribute = '.(int)($id_product_attribute).' WHERE id_product = '.(int)($id_product).' LIMIT 1');
|
||||
Db::getInstance()->execute('UPDATE '._DB_PREFIX_.'product SET cache_default_attribute = '.(int)$id_product_attribute.' WHERE id_product = '.(int)$id_product.' LIMIT 1');
|
||||
}
|
||||
|
||||
public function validateFieldsLang($die = true, $errorReturn = false)
|
||||
@@ -601,7 +601,7 @@ class ProductCore extends ObjectModel
|
||||
!$this->deleteAttributesImpacts() OR
|
||||
!$this->deleteAttachments() OR
|
||||
!$this->deleteCustomization() OR
|
||||
!SpecificPrice::deleteByProductId((int)($this->id)) OR
|
||||
!SpecificPrice::deleteByProductId((int)$this->id) OR
|
||||
!$this->deletePack() OR
|
||||
!$this->deleteProductSale() OR
|
||||
!$this->deleteSceneProducts() OR
|
||||
@@ -620,7 +620,7 @@ class ProductCore extends ObjectModel
|
||||
$return = 1;
|
||||
foreach ($products as $id_product)
|
||||
{
|
||||
$product = new Product((int)($id_product));
|
||||
$product = new Product((int)$id_product);
|
||||
$return &= $product->delete();
|
||||
}
|
||||
return $return;
|
||||
@@ -712,8 +712,8 @@ class ProductCore extends ObjectModel
|
||||
*/
|
||||
public function deleteCategory($id_category, $cleanPositions = true)
|
||||
{
|
||||
$result = Db::getInstance()->executeS('SELECT `id_category` FROM `'._DB_PREFIX_.'category_product` WHERE `id_product` = '.(int)($this->id).' AND id_category = '.(int)$id_category.'');
|
||||
$return = Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'category_product` WHERE `id_product` = '.(int)($this->id).' AND id_category = '.(int)$id_category.'');
|
||||
$result = Db::getInstance()->executeS('SELECT `id_category` FROM `'._DB_PREFIX_.'category_product` WHERE `id_product` = '.(int)$this->id.' AND id_category = '.(int)$id_category.'');
|
||||
$return = Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'category_product` WHERE `id_product` = '.(int)$this->id.' AND id_category = '.(int)$id_category.'');
|
||||
if ($cleanPositions === true)
|
||||
foreach ($result as $row)
|
||||
$this->cleanPositions((int)$row['id_category']);
|
||||
@@ -728,12 +728,12 @@ class ProductCore extends ObjectModel
|
||||
*/
|
||||
public function deleteCategories($cleanPositions = false)
|
||||
{
|
||||
$return = Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'category_product` WHERE `id_product` = '.(int)($this->id));
|
||||
$return = Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'category_product` WHERE `id_product` = '.(int)$this->id);
|
||||
if ($cleanPositions === true)
|
||||
{
|
||||
$result = Db::getInstance()->executeS('SELECT `id_category` FROM `'._DB_PREFIX_.'category_product` WHERE `id_product` = '.(int)($this->id));
|
||||
$result = Db::getInstance()->executeS('SELECT `id_category` FROM `'._DB_PREFIX_.'category_product` WHERE `id_product` = '.(int)$this->id);
|
||||
foreach ($result as $row)
|
||||
$this->cleanPositions((int)($row['id_category']));
|
||||
$this->cleanPositions((int)$row['id_category']);
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
@@ -745,7 +745,7 @@ class ProductCore extends ObjectModel
|
||||
*/
|
||||
public function deleteTags()
|
||||
{
|
||||
return (Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'product_tag` WHERE `id_product` = '.(int)($this->id))
|
||||
return (Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'product_tag` WHERE `id_product` = '.(int)$this->id)
|
||||
AND Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'tag` WHERE `id_tag` NOT IN (SELECT `id_tag` FROM `'._DB_PREFIX_.'product_tag`)'));
|
||||
}
|
||||
|
||||
@@ -756,7 +756,7 @@ class ProductCore extends ObjectModel
|
||||
*/
|
||||
public function deleteCartProducts()
|
||||
{
|
||||
return Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'cart_product` WHERE `id_product` = '.(int)($this->id));
|
||||
return Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'cart_product` WHERE `id_product` = '.(int)$this->id);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -769,7 +769,7 @@ class ProductCore extends ObjectModel
|
||||
$result = Db::getInstance()->executeS('
|
||||
SELECT `id_image`
|
||||
FROM `'._DB_PREFIX_.'image`
|
||||
WHERE `id_product` = '.(int)($this->id));
|
||||
WHERE `id_product` = '.(int)$this->id);
|
||||
|
||||
$status = true;
|
||||
if ($result)
|
||||
@@ -786,7 +786,7 @@ class ProductCore extends ObjectModel
|
||||
$rq = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
|
||||
SELECT `price`
|
||||
FROM `'._DB_PREFIX_.'product_attribute`
|
||||
WHERE `id_product_attribute` = '.(int)($id_product_attribute));
|
||||
WHERE `id_product_attribute` = '.(int)$id_product_attribute);
|
||||
return $rq['price'];
|
||||
}
|
||||
|
||||
@@ -845,7 +845,7 @@ class ProductCore extends ObjectModel
|
||||
FROM `'._DB_PREFIX_.'product` p
|
||||
'.$context->shop->sqlAsso('product', 'p', false).'
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` '.$context->shop->sqlLang('pl').')
|
||||
WHERE pl.`id_lang` = '.(int)($id_lang).'
|
||||
WHERE pl.`id_lang` = '.(int)$id_lang.'
|
||||
ORDER BY pl.`name`';
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
|
||||
}
|
||||
@@ -855,7 +855,7 @@ class ProductCore extends ObjectModel
|
||||
$result = Db::getInstance()->executeS('
|
||||
SELECT id_product FROM `'._DB_PREFIX_.'product` p
|
||||
WHERE 1
|
||||
AND id_product = '.(int)($this->id).'
|
||||
AND id_product = '.(int)$this->id.'
|
||||
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
|
||||
');
|
||||
@@ -3000,9 +3000,9 @@ class ProductCore extends ObjectModel
|
||||
if (isset($customizedDatas[$productId][$productAttributeId]))
|
||||
foreach ($customizedDatas[$productId][$productAttributeId] as $customization)
|
||||
{
|
||||
$customizationQuantity += (int)($customization['quantity']);
|
||||
$customizationQuantityRefunded += (int)($customization['quantity_refunded']);
|
||||
$customizationQuantityReturned += (int)($customization['quantity_returned']);
|
||||
$customizationQuantity += (int)$customization['quantity'];
|
||||
$customizationQuantityRefunded += (int)$customization['quantity_refunded'];
|
||||
$customizationQuantityReturned += (int)$customization['quantity_returned'];
|
||||
}
|
||||
$productUpdate['customizationQuantityTotal'] = $customizationQuantity;
|
||||
$productUpdate['customizationQuantityRefunded'] = $customizationQuantityRefunded;
|
||||
@@ -3034,32 +3034,32 @@ class ProductCore extends ObjectModel
|
||||
|
||||
protected function _deleteOldLabels()
|
||||
{
|
||||
$max = array(Product::CUSTOMIZE_FILE => (int)(Tools::getValue('uploadable_files')), Product::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).'
|
||||
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(Product::CUSTOMIZE_FILE => array(), Product::CUSTOMIZE_TEXTFIELD => array());
|
||||
foreach ($result as $row)
|
||||
$customizationFields[(int)($row['type'])][] = (int)($row['id_customization_field']);
|
||||
$customizationFields[(int)$row['type']][] = (int)$row['id_customization_field'];
|
||||
$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 && count($customizationFields[Product::CUSTOMIZE_FILE]) - $extraFile >= 0 &&
|
||||
(!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]))
|
||||
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])
|
||||
|| !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 && count($customizationFields[Product::CUSTOMIZE_TEXTFIELD]) - $extraText >= 0 &&
|
||||
(!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]))
|
||||
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])
|
||||
|| !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;
|
||||
@@ -3075,14 +3075,14 @@ class ProductCore extends ObjectModel
|
||||
// Label insertion
|
||||
if (!Db::getInstance()->execute('
|
||||
INSERT INTO `'._DB_PREFIX_.'customization_field` (`id_product`, `type`, `required`)
|
||||
VALUES ('.(int)$this->id.', '.(int)($type).', 0)') ||
|
||||
!$id_customization_field = (int)(Db::getInstance()->Insert_ID()))
|
||||
VALUES ('.(int)$this->id.', '.(int)$type.', 0)') ||
|
||||
!$id_customization_field = (int)Db::getInstance()->Insert_ID())
|
||||
return false;
|
||||
|
||||
// Multilingual label name creation
|
||||
$values = '';
|
||||
foreach ($languages as $language)
|
||||
$values .= '('.(int)($id_customization_field).', '.(int)($language['id_lang']).', \'\'), ';
|
||||
$values .= '('.(int)$id_customization_field.', '.(int)$language['id_lang'].', \'\'), ';
|
||||
$values = rtrim($values, ', ');
|
||||
if (!Db::getInstance()->execute('
|
||||
INSERT INTO `'._DB_PREFIX_.'customization_field_lang` (`id_customization_field`, `id_lang`, `name`)
|
||||
@@ -3098,12 +3098,12 @@ class ProductCore extends ObjectModel
|
||||
public function createLabels($uploadableFiles, $textFields)
|
||||
{
|
||||
$languages = Language::getLanguages();
|
||||
if ((int)($uploadableFiles) > 0)
|
||||
for ($i = 0; $i < (int)($uploadableFiles); $i++)
|
||||
if ((int)$uploadableFiles > 0)
|
||||
for ($i = 0; $i < (int)$uploadableFiles; $i++)
|
||||
if (!$this->_createLabel($languages, Product::CUSTOMIZE_FILE))
|
||||
return false;
|
||||
if ((int)($textFields) > 0)
|
||||
for ($i = 0; $i < (int)($textFields); $i++)
|
||||
if ((int)$textFields > 0)
|
||||
for ($i = 0; $i < (int)$textFields; $i++)
|
||||
if (!$this->_createLabel($languages, Product::CUSTOMIZE_TEXTFIELD))
|
||||
return false;
|
||||
return true;
|
||||
@@ -3121,16 +3121,16 @@ class ProductCore extends ObjectModel
|
||||
/* Multilingual label name update */
|
||||
if (!Db::getInstance()->execute('
|
||||
INSERT INTO `'._DB_PREFIX_.'customization_field_lang`
|
||||
(`id_customization_field`, `id_lang`, `name`) VALUES ('.(int)($tmp[2]).', '.(int)($tmp[3]).', \''.pSQL($value).'\')
|
||||
(`id_customization_field`, `id_lang`, `name`) VALUES ('.(int)$tmp[2].', '.(int)$tmp[3].', \''.pSQL($value).'\')
|
||||
ON DUPLICATE KEY UPDATE `name` = \''.pSQL($value).'\''))
|
||||
return false;
|
||||
$isRequired = isset($_POST['require_'.(int)($tmp[1]).'_'.(int)($tmp[2])]) ? 1 : 0;
|
||||
$isRequired = isset($_POST['require_'.(int)$tmp[1].'_'.(int)$tmp[2]]) ? 1 : 0;
|
||||
$hasRequiredFields |= $isRequired;
|
||||
/* Require option update */
|
||||
if (!Db::getInstance()->execute('UPDATE `'._DB_PREFIX_.'customization_field` SET `required` = '.(int)($isRequired).' WHERE `id_customization_field` = '.(int)($tmp[2])))
|
||||
if (!Db::getInstance()->execute('UPDATE `'._DB_PREFIX_.'customization_field` SET `required` = '.(int)$isRequired.' WHERE `id_customization_field` = '.(int)$tmp[2]))
|
||||
return false;
|
||||
}
|
||||
if ($hasRequiredFields && !Db::getInstance()->execute('UPDATE `'._DB_PREFIX_.'product` SET `customizable` = 2 WHERE `id_product` = '.(int)($this->id)))
|
||||
if ($hasRequiredFields && !Db::getInstance()->execute('UPDATE `'._DB_PREFIX_.'product` SET `customizable` = 2 WHERE `id_product` = '.(int)$this->id))
|
||||
return false;
|
||||
if (!$this->_deleteOldLabels())
|
||||
return false;
|
||||
@@ -3145,14 +3145,14 @@ class ProductCore extends ObjectModel
|
||||
SELECT cf.`id_customization_field`, cf.`type`, cf.`required`, cfl.`name`, cfl.`id_lang`
|
||||
FROM `'._DB_PREFIX_.'customization_field` cf
|
||||
NATURAL JOIN `'._DB_PREFIX_.'customization_field_lang` cfl
|
||||
WHERE cf.`id_product` = '.(int)($this->id).($id_lang ? ' AND cfl.`id_lang` = '.(int)($id_lang) : '').'
|
||||
WHERE cf.`id_product` = '.(int)$this->id.($id_lang ? ' AND cfl.`id_lang` = '.(int)$id_lang : '').'
|
||||
ORDER BY cf.`id_customization_field`'))
|
||||
return false;
|
||||
if ($id_lang)
|
||||
return $result;
|
||||
$customizationFields = array();
|
||||
foreach ($result as $row)
|
||||
$customizationFields[(int)($row['type'])][(int)($row['id_customization_field'])][(int)($row['id_lang'])] = $row;
|
||||
$customizationFields[(int)$row['type']][(int)$row['id_customization_field']][(int)$row['id_lang']] = $row;
|
||||
return $customizationFields;
|
||||
}
|
||||
|
||||
@@ -3163,7 +3163,7 @@ class ProductCore extends ObjectModel
|
||||
return Db::getInstance()->executeS('
|
||||
SELECT `id_customization_field`, `type`
|
||||
FROM `'._DB_PREFIX_.'customization_field`
|
||||
WHERE `id_product` = '.(int)($this->id));
|
||||
WHERE `id_product` = '.(int)$this->id);
|
||||
}
|
||||
|
||||
public function getRequiredCustomizableFields()
|
||||
@@ -3173,7 +3173,7 @@ class ProductCore extends ObjectModel
|
||||
return Db::getInstance()->executeS('
|
||||
SELECT `id_customization_field`, `type`
|
||||
FROM `'._DB_PREFIX_.'customization_field`
|
||||
WHERE `id_product` = '.(int)($this->id).'
|
||||
WHERE `id_product` = '.(int)$this->id.'
|
||||
AND `required` = 1'
|
||||
);
|
||||
}
|
||||
@@ -3210,9 +3210,9 @@ class ProductCore extends ObjectModel
|
||||
{
|
||||
if (!((int)$id_product > 0) || !is_array($categories) || empty($categories))
|
||||
return false;
|
||||
$sql = 'SELECT id_product FROM `'._DB_PREFIX_.'category_product` WHERE `id_product`='.(int)($id_product).' AND `id_category` IN(';
|
||||
$sql = 'SELECT id_product FROM `'._DB_PREFIX_.'category_product` WHERE `id_product`='.(int)$id_product.' AND `id_category` IN(';
|
||||
foreach ($categories as $category)
|
||||
$sql .= (int)($category['id_category']).',';
|
||||
$sql .= (int)$category['id_category'].',';
|
||||
$sql = rtrim($sql, ',').')';
|
||||
|
||||
if (isset(self::$_incat[md5($sql)]))
|
||||
@@ -3451,7 +3451,7 @@ class ProductCore extends ObjectModel
|
||||
*/
|
||||
public function getWsCombinations()
|
||||
{
|
||||
$result = Db::getInstance()->executeS('SELECT `id_product_attribute` as id FROM `'._DB_PREFIX_.'product_attribute` WHERE `id_product` = '.(int)($this->id));
|
||||
$result = Db::getInstance()->executeS('SELECT `id_product_attribute` as id FROM `'._DB_PREFIX_.'product_attribute` WHERE `id_product` = '.(int)$this->id);
|
||||
return $result;
|
||||
}
|
||||
|
||||
@@ -3468,7 +3468,7 @@ class ProductCore extends ObjectModel
|
||||
$ids_new[] = (int)$combination['id'];
|
||||
|
||||
$ids_orig = array();
|
||||
$original = Db::getInstance()->executeS('SELECT `id_product_attribute` as id FROM `'._DB_PREFIX_.'product_attribute` WHERE `id_product` = '.(int)($this->id));
|
||||
$original = Db::getInstance()->executeS('SELECT `id_product_attribute` as id FROM `'._DB_PREFIX_.'product_attribute` WHERE `id_product` = '.(int)$this->id);
|
||||
if (is_array($original))
|
||||
foreach ($original as $id)
|
||||
$ids_orig[] = $id['id'];
|
||||
@@ -3527,8 +3527,8 @@ class ProductCore extends ObjectModel
|
||||
{
|
||||
$result = Db::getInstance()->executeS('SELECT position
|
||||
FROM `'._DB_PREFIX_.'category_product`
|
||||
WHERE id_category = '.(int)($this->id_category_default).'
|
||||
AND id_product = '.(int)($this->id));
|
||||
WHERE id_category = '.(int)$this->id_category_default.'
|
||||
AND id_product = '.(int)$this->id);
|
||||
if (count($result) > 0)
|
||||
return $result[0]['position'];
|
||||
return '';
|
||||
@@ -3553,10 +3553,10 @@ class ProductCore extends ObjectModel
|
||||
public function setCoverWs($id_image)
|
||||
{
|
||||
Db::getInstance()->execute('UPDATE `'._DB_PREFIX_.'image`
|
||||
SET `cover` = 0 WHERE `id_product` = '.(int)($this->id).'
|
||||
SET `cover` = 0 WHERE `id_product` = '.(int)$this->id.'
|
||||
');
|
||||
Db::getInstance()->execute('UPDATE `'._DB_PREFIX_.'image`
|
||||
SET `cover` = 1 WHERE `id_product` = '.(int)($this->id).' AND `id_image` = '.(int)$id_image);
|
||||
SET `cover` = 1 WHERE `id_product` = '.(int)$this->id.' AND `id_image` = '.(int)$id_image);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -3570,7 +3570,7 @@ class ProductCore extends ObjectModel
|
||||
return Db::getInstance()->executeS('
|
||||
SELECT `id_image` as id
|
||||
FROM `'._DB_PREFIX_.'image`
|
||||
WHERE `id_product` = '.(int)($this->id).'
|
||||
WHERE `id_product` = '.(int)$this->id.'
|
||||
ORDER BY `position`');
|
||||
}
|
||||
|
||||
@@ -3579,7 +3579,7 @@ class ProductCore extends ObjectModel
|
||||
return Db::getInstance()->executeS('
|
||||
SELECT `id_tag` as id
|
||||
FROM `'._DB_PREFIX_.'product_tag`
|
||||
WHERE `id_product` = '.(int)($this->id));
|
||||
WHERE `id_product` = '.(int)$this->id);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user