// Carrier range price / weight for multishop + fix duplicate of carrier_lang when a new shop is created
This commit is contained in:
@@ -46,7 +46,7 @@ class AdminShipping extends AdminTab
|
|||||||
public function postProcess()
|
public function postProcess()
|
||||||
{
|
{
|
||||||
/* Handling settings */
|
/* Handling settings */
|
||||||
if (isset($_POST['submitHandling'.$this->table]))
|
if (Tools::isSubmit('submitHandling'.$this->table))
|
||||||
{
|
{
|
||||||
if ($this->tabAccess['edit'] === '1')
|
if ($this->tabAccess['edit'] === '1')
|
||||||
{
|
{
|
||||||
@@ -81,7 +81,7 @@ class AdminShipping extends AdminTab
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Shipping fees */
|
/* Shipping fees */
|
||||||
elseif (isset($_POST['submitFees'.$this->table]))
|
elseif (Tools::isSubmit('submitFees'.$this->table))
|
||||||
{
|
{
|
||||||
if ($this->tabAccess['edit'] === '1')
|
if ($this->tabAccess['edit'] === '1')
|
||||||
{
|
{
|
||||||
@@ -93,24 +93,36 @@ class AdminShipping extends AdminTab
|
|||||||
/* Get configuration values */
|
/* Get configuration values */
|
||||||
$shipping_method = $carrier->getShippingMethod();
|
$shipping_method = $carrier->getShippingMethod();
|
||||||
$rangeTable = $carrier->getRangeTable();
|
$rangeTable = $carrier->getRangeTable();
|
||||||
|
|
||||||
$carrier->deleteDeliveryPrice($rangeTable);
|
$carrier->deleteDeliveryPrice($rangeTable);
|
||||||
|
$currentList = Carrier::getDeliveryPriceByRanges($rangeTable, $id_carrier);
|
||||||
|
|
||||||
/* Build prices list */
|
/* Build prices list */
|
||||||
$priceList = '';
|
$priceList = array();
|
||||||
foreach ($_POST AS $key => $value)
|
foreach ($_POST AS $key => $value)
|
||||||
if (strstr($key, 'fees_'))
|
if (strstr($key, 'fees_'))
|
||||||
{
|
{
|
||||||
$tmpArray = explode('_', $key);
|
$tmpArray = explode('_', $key);
|
||||||
$priceList .= '('.($shipping_method == Carrier::SHIPPING_METHOD_PRICE ? (int)($tmpArray[2]) : 'NULL').',
|
|
||||||
'.($shipping_method == Carrier::SHIPPING_METHOD_WEIGHT ? (int)($tmpArray[2]) : 'NULL').', '.$carrier->id.',
|
$price = number_format(abs(str_replace(',', '.', $value)), 2, '.', '');
|
||||||
'.(int)($tmpArray[1]).', '.number_format(abs(preg_replace("#,#", '.', $value)), 2, '.', '').'),';
|
$current = 0;
|
||||||
unset($tmpArray);
|
foreach ($currentList as $item)
|
||||||
|
if ($item['id_zone'] == $tmpArray[1] && $item['id_'.$rangeTable] == $tmpArray[2])
|
||||||
|
$current = $item;
|
||||||
|
if ($current && $price == $current['price'])
|
||||||
|
continue;
|
||||||
|
|
||||||
|
$priceList[] = array(
|
||||||
|
'id_range_price' => ($shipping_method == Carrier::SHIPPING_METHOD_PRICE) ? (int)$tmpArray[2] : null,
|
||||||
|
'id_range_weight' => ($shipping_method == Carrier::SHIPPING_METHOD_WEIGHT) ? (int)$tmpArray[2] : null,
|
||||||
|
'id_carrier' => (int)$carrier->id,
|
||||||
|
'id_zone' => (int)$tmpArray[1],
|
||||||
|
'price' => $price,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
$priceList = rtrim($priceList, ',');
|
|
||||||
/* Update delivery prices */
|
/* Update delivery prices */
|
||||||
$carrier->addDeliveryPrice($priceList);
|
$carrier->addDeliveryPrice($priceList);
|
||||||
Tools::redirectAdmin(self::$currentIndex.'&conf=6'.'&token='.$this->token);
|
Tools::redirectAdmin(self::$currentIndex.'&conf=6&id_carrier='.$carrier->id.'&token='.$this->token);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
$this->_errors[] = Tools::displayError('An error occurred while updating fees (cannot load carrier object).');
|
$this->_errors[] = Tools::displayError('An error occurred while updating fees (cannot load carrier object).');
|
||||||
@@ -218,7 +230,7 @@ class AdminShipping extends AdminTab
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
echo '<b>'.$this->l('Carrier:').' </b>
|
echo '<b>'.$this->l('Carrier:').' </b>
|
||||||
<select name="id_carrier2" onchange="document.fees.submit();">';
|
<select name="id_carrier2" onchange="$(\'#fees\').attr(\'action\', $(\'#fees\').attr(\'action\')+\'&id_carrier=\'+$(this).attr(\'value\')); $(\'#fees\').submit();">';
|
||||||
foreach ($carrierArray AS $carrierOption)
|
foreach ($carrierArray AS $carrierOption)
|
||||||
echo $carrierOption['display'];
|
echo $carrierOption['display'];
|
||||||
echo '
|
echo '
|
||||||
|
|||||||
+187
-114
@@ -169,20 +169,21 @@ class CarrierCore extends ObjectModel
|
|||||||
* @param integer $id_zone Zone id (for customer delivery address)
|
* @param integer $id_zone Zone id (for customer delivery address)
|
||||||
* @return float Delivery price
|
* @return float Delivery price
|
||||||
*/
|
*/
|
||||||
public function getDeliveryPriceByWeight($totalWeight, $id_zone)
|
public function getDeliveryPriceByWeight($totalWeight, $id_zone, Shop $shop = null)
|
||||||
{
|
{
|
||||||
$cache_key = $this->id.'_'.$totalWeight.'_'.$id_zone;
|
$cache_key = $this->id.'_'.$totalWeight.'_'.$id_zone;
|
||||||
if (!isset(self::$priceByWeight[$cache_key]))
|
if (!isset(self::$priceByWeight[$cache_key]))
|
||||||
{
|
{
|
||||||
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
|
$sql = 'SELECT d.`price`
|
||||||
SELECT d.`price`
|
FROM `'._DB_PREFIX_.'delivery` d
|
||||||
FROM `'._DB_PREFIX_.'delivery` d
|
LEFT JOIN `'._DB_PREFIX_.'range_weight` w ON (d.`id_range_weight` = w.`id_range_weight`)
|
||||||
LEFT JOIN `'._DB_PREFIX_.'range_weight` w ON (d.`id_range_weight` = w.`id_range_weight`)
|
WHERE d.`id_zone` = '.(int)($id_zone).'
|
||||||
WHERE d.`id_zone` = '.(int)($id_zone).'
|
AND '.(float)$totalWeight.' >= w.`delimiter1`
|
||||||
AND '.(float)($totalWeight).' >= w.`delimiter1`
|
AND '.(float)$totalWeight.' < w.`delimiter2`
|
||||||
AND '.(float)($totalWeight).' < w.`delimiter2`
|
AND d.`id_carrier` = '.(int)$this->id.'
|
||||||
AND d.`id_carrier` = '.(int)($this->id).'
|
'.Carrier::sqlDeliveryRangeShop('range_weight', $shop).'
|
||||||
ORDER BY w.`delimiter1` ASC');
|
ORDER BY w.`delimiter1` ASC';
|
||||||
|
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql);
|
||||||
if (!isset($result['price']))
|
if (!isset($result['price']))
|
||||||
self::$priceByWeight[$cache_key] = $this->getMaxDeliveryPriceByWeight($id_zone);
|
self::$priceByWeight[$cache_key] = $this->getMaxDeliveryPriceByWeight($id_zone);
|
||||||
else
|
else
|
||||||
@@ -191,34 +192,36 @@ class CarrierCore extends ObjectModel
|
|||||||
return self::$priceByWeight[$cache_key];
|
return self::$priceByWeight[$cache_key];
|
||||||
}
|
}
|
||||||
|
|
||||||
static public function checkDeliveryPriceByWeight($id_carrier, $totalWeight, $id_zone)
|
static public function checkDeliveryPriceByWeight($id_carrier, $totalWeight, $id_zone, Shop $shop = null)
|
||||||
{
|
{
|
||||||
$cache_key = $id_carrier.'_'.$totalWeight.'_'.$id_zone;
|
$cache_key = $id_carrier.'_'.$totalWeight.'_'.$id_zone;
|
||||||
if (!isset(self::$priceByWeight2[$cache_key]))
|
if (!isset(self::$priceByWeight2[$cache_key]))
|
||||||
{
|
{
|
||||||
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
|
$sql = 'SELECT d.`price`
|
||||||
SELECT d.`price`
|
FROM `'._DB_PREFIX_.'delivery` d
|
||||||
FROM `'._DB_PREFIX_.'delivery` d
|
LEFT JOIN `'._DB_PREFIX_.'range_weight` w ON d.`id_range_weight` = w.`id_range_weight`
|
||||||
LEFT JOIN `'._DB_PREFIX_.'range_weight` w ON d.`id_range_weight` = w.`id_range_weight`
|
WHERE d.`id_zone` = '.(int)$id_zone.'
|
||||||
WHERE d.`id_zone` = '.(int)($id_zone).'
|
AND '.(float)$totalWeight.' >= w.`delimiter1`
|
||||||
AND '.(float)($totalWeight).' >= w.`delimiter1`
|
AND '.(float)$totalWeight.' < w.`delimiter2`
|
||||||
AND '.(float)($totalWeight).' < w.`delimiter2`
|
AND d.`id_carrier` = '.(int)$id_carrier.'
|
||||||
AND d.`id_carrier` = '.(int)($id_carrier).'
|
'.Carrier::sqlDeliveryRangeShop('range_weight', $shop).'
|
||||||
ORDER BY w.`delimiter1` ASC');
|
ORDER BY w.`delimiter1` ASC';
|
||||||
|
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql);
|
||||||
self::$priceByWeight2[$cache_key] = (isset($result['price']));
|
self::$priceByWeight2[$cache_key] = (isset($result['price']));
|
||||||
}
|
}
|
||||||
return self::$priceByWeight2[$cache_key];
|
return self::$priceByWeight2[$cache_key];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getMaxDeliveryPriceByWeight($id_zone)
|
public function getMaxDeliveryPriceByWeight($id_zone, Shop $shop = null)
|
||||||
{
|
{
|
||||||
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
|
$sql = 'SELECT d.`price`
|
||||||
SELECT d.`price`
|
FROM `'._DB_PREFIX_.'delivery` d
|
||||||
FROM `'._DB_PREFIX_.'delivery` d
|
INNER JOIN `'._DB_PREFIX_.'range_weight` w ON d.`id_range_weight` = w.`id_range_weight`
|
||||||
INNER JOIN `'._DB_PREFIX_.'range_weight` w ON d.`id_range_weight` = w.`id_range_weight`
|
WHERE d.`id_zone` = '.(int)$id_zone.'
|
||||||
WHERE d.`id_zone` = '.(int)($id_zone).'
|
AND d.`id_carrier` = '.(int)$this->id.'
|
||||||
AND d.`id_carrier` = '.(int)($this->id).'
|
'.Carrier::sqlDeliveryRangeShop('range_weight', $shop).'
|
||||||
ORDER BY w.`delimiter2` DESC LIMIT 1');
|
ORDER BY w.`delimiter2` DESC LIMIT 1';
|
||||||
|
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($sql);
|
||||||
if (!isset($result[0]['price']))
|
if (!isset($result[0]['price']))
|
||||||
return false;
|
return false;
|
||||||
return $result[0]['price'];
|
return $result[0]['price'];
|
||||||
@@ -231,7 +234,7 @@ class CarrierCore extends ObjectModel
|
|||||||
* @param integer $id_zone Zone id (for customer delivery address)
|
* @param integer $id_zone Zone id (for customer delivery address)
|
||||||
* @return float Delivery price
|
* @return float Delivery price
|
||||||
*/
|
*/
|
||||||
public function getDeliveryPriceByPrice($orderTotal, $id_zone, $id_currency = NULL)
|
public function getDeliveryPriceByPrice($orderTotal, $id_zone, $id_currency = NULL, Shop $shop = null)
|
||||||
{
|
{
|
||||||
$cache_key = $this->id.'_'.$orderTotal.'_'.$id_zone.'_'.$id_currency;
|
$cache_key = $this->id.'_'.$orderTotal.'_'.$id_zone.'_'.$id_currency;
|
||||||
if (!isset(self::$priceByPrice[$cache_key]))
|
if (!isset(self::$priceByPrice[$cache_key]))
|
||||||
@@ -239,15 +242,16 @@ class CarrierCore extends ObjectModel
|
|||||||
if (!empty($id_currency))
|
if (!empty($id_currency))
|
||||||
$orderTotal = Tools::convertPrice($orderTotal, $id_currency, false);
|
$orderTotal = Tools::convertPrice($orderTotal, $id_currency, false);
|
||||||
|
|
||||||
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
|
$sql = 'SELECT d.`price`
|
||||||
SELECT d.`price`
|
FROM `'._DB_PREFIX_.'delivery` d
|
||||||
FROM `'._DB_PREFIX_.'delivery` d
|
LEFT JOIN `'._DB_PREFIX_.'range_price` r ON d.`id_range_price` = r.`id_range_price`
|
||||||
LEFT JOIN `'._DB_PREFIX_.'range_price` r ON d.`id_range_price` = r.`id_range_price`
|
WHERE d.`id_zone` = '.(int)($id_zone).'
|
||||||
WHERE d.`id_zone` = '.(int)($id_zone).'
|
AND '.(float)$orderTotal.' >= r.`delimiter1`
|
||||||
AND '.(float)($orderTotal).' >= r.`delimiter1`
|
AND '.(float)$orderTotal.' < r.`delimiter2`
|
||||||
AND '.(float)($orderTotal).' < r.`delimiter2`
|
AND d.`id_carrier` = '.(int)($this->id).'
|
||||||
AND d.`id_carrier` = '.(int)($this->id).'
|
'.Carrier::sqlDeliveryRangeShop('range_price', $shop).'
|
||||||
ORDER BY r.`delimiter1` ASC');
|
ORDER BY r.`delimiter1` ASC';
|
||||||
|
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql);
|
||||||
if (!isset($result['price']))
|
if (!isset($result['price']))
|
||||||
self::$priceByPrice[$cache_key] = $this->getMaxDeliveryPriceByPrice($id_zone);
|
self::$priceByPrice[$cache_key] = $this->getMaxDeliveryPriceByPrice($id_zone);
|
||||||
else
|
else
|
||||||
@@ -265,7 +269,7 @@ class CarrierCore extends ObjectModel
|
|||||||
* @param integer $id_currency
|
* @param integer $id_currency
|
||||||
* @return float Delivery price
|
* @return float Delivery price
|
||||||
*/
|
*/
|
||||||
static public function checkDeliveryPriceByPrice($id_carrier, $orderTotal, $id_zone, $id_currency = NULL)
|
static public function checkDeliveryPriceByPrice($id_carrier, $orderTotal, $id_zone, $id_currency = NULL, Shop $shop = null)
|
||||||
{
|
{
|
||||||
$cache_key = $id_carrier.'_'.$orderTotal.'_'.$id_zone.'_'.$id_currency;
|
$cache_key = $id_carrier.'_'.$orderTotal.'_'.$id_zone.'_'.$id_currency;
|
||||||
if (!isset(self::$priceByPrice2[$cache_key]))
|
if (!isset(self::$priceByPrice2[$cache_key]))
|
||||||
@@ -273,29 +277,31 @@ class CarrierCore extends ObjectModel
|
|||||||
if (!empty($id_currency))
|
if (!empty($id_currency))
|
||||||
$orderTotal = Tools::convertPrice($orderTotal, $id_currency, false);
|
$orderTotal = Tools::convertPrice($orderTotal, $id_currency, false);
|
||||||
|
|
||||||
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
|
$sql = 'SELECT d.`price`
|
||||||
SELECT d.`price`
|
FROM `'._DB_PREFIX_.'delivery` d
|
||||||
FROM `'._DB_PREFIX_.'delivery` d
|
LEFT JOIN `'._DB_PREFIX_.'range_price` r ON d.`id_range_price` = r.`id_range_price`
|
||||||
LEFT JOIN `'._DB_PREFIX_.'range_price` r ON d.`id_range_price` = r.`id_range_price`
|
WHERE d.`id_zone` = '.(int)($id_zone).'
|
||||||
WHERE d.`id_zone` = '.(int)($id_zone).'
|
AND '.(float)$orderTotal.' >= r.`delimiter1`
|
||||||
AND '.(float)($orderTotal).' >= r.`delimiter1`
|
AND '.(float)$orderTotal.' < r.`delimiter2`
|
||||||
AND '.(float)($orderTotal).' < r.`delimiter2`
|
AND d.`id_carrier` = '.(int)$id_carrier.'
|
||||||
AND d.`id_carrier` = '.(int)($id_carrier).'
|
'.Carrier::sqlDeliveryRangeShop('range_price', $shop).'
|
||||||
ORDER BY r.`delimiter1` ASC');
|
ORDER BY r.`delimiter1` ASC';
|
||||||
|
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql);
|
||||||
self::$priceByPrice2[$cache_key] = (isset($result['price']));
|
self::$priceByPrice2[$cache_key] = (isset($result['price']));
|
||||||
}
|
}
|
||||||
return self::$priceByPrice2[$cache_key];
|
return self::$priceByPrice2[$cache_key];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getMaxDeliveryPriceByPrice($id_zone)
|
public function getMaxDeliveryPriceByPrice($id_zone, Shop $shop = null)
|
||||||
{
|
{
|
||||||
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
|
$sql = 'SELECT d.`price`
|
||||||
SELECT d.`price`
|
FROM `'._DB_PREFIX_.'delivery` d
|
||||||
FROM `'._DB_PREFIX_.'delivery` d
|
INNER JOIN `'._DB_PREFIX_.'range_price` r ON d.`id_range_price` = r.`id_range_price`
|
||||||
INNER JOIN `'._DB_PREFIX_.'range_price` r ON d.`id_range_price` = r.`id_range_price`
|
WHERE d.`id_zone` = '.(int)$id_zone.'
|
||||||
WHERE d.`id_zone` = '.(int)($id_zone).'
|
AND d.`id_carrier` = '.(int)$this->id.'
|
||||||
AND d.`id_carrier` = '.(int)($this->id).'
|
'.Carrier::sqlDeliveryRangeShop('range_price', $shop).'
|
||||||
ORDER BY r.`delimiter2` DESC LIMIT 1');
|
ORDER BY r.`delimiter2` DESC LIMIT 1';
|
||||||
|
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($sql);
|
||||||
if (!isset($result[0]['price']))
|
if (!isset($result[0]['price']))
|
||||||
return false;
|
return false;
|
||||||
return $result[0]['price'];
|
return $result[0]['price'];
|
||||||
@@ -307,15 +313,18 @@ class CarrierCore extends ObjectModel
|
|||||||
* @param string $rangeTable Table name (price or weight)
|
* @param string $rangeTable Table name (price or weight)
|
||||||
* @return array Delivery prices
|
* @return array Delivery prices
|
||||||
*/
|
*/
|
||||||
public static function getDeliveryPriceByRanges($rangeTable, $id_carrier)
|
public static function getDeliveryPriceByRanges($rangeTable, $id_carrier, Shop $shop = null)
|
||||||
{
|
{
|
||||||
$rangeTable = pSQL($rangeTable);
|
$rangeTable = pSQL($rangeTable);
|
||||||
return Db::getInstance()->ExecuteS('
|
$sql = 'SELECT d.id_'.$rangeTable.', d.id_carrier, d.id_zone, d.price
|
||||||
SELECT d.`id_'.$rangeTable.'`, d.`id_carrier`, d.`id_zone`, d.`price`
|
FROM '._DB_PREFIX_.'delivery d
|
||||||
FROM `'._DB_PREFIX_.'delivery` d
|
LEFT JOIN '._DB_PREFIX_.$rangeTable.' r ON r.id_'.$rangeTable.' = d.id_'.$rangeTable.'
|
||||||
LEFT JOIN `'._DB_PREFIX_.$rangeTable.'` r ON r.`id_'.$rangeTable.'` = d.`id_'.$rangeTable.'`
|
WHERE d.id_carrier = '.(int)$id_carrier.'
|
||||||
WHERE (d.`id_'.$rangeTable.'` IS NOT NULL AND d.`id_'.$rangeTable.'` != 0 AND d.`id_carrier` = '.(int)($id_carrier).')
|
AND d.id_'.$rangeTable.' IS NOT NULL
|
||||||
ORDER BY r.`delimiter1` ASC');
|
AND d.id_'.$rangeTable.' != 0
|
||||||
|
'.Carrier::sqlDeliveryRangeShop($rangeTable, $shop).'
|
||||||
|
ORDER BY r.delimiter1';
|
||||||
|
return Db::getInstance()->ExecuteS($sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -531,24 +540,69 @@ class CarrierCore extends ObjectModel
|
|||||||
* @param string $rangeTable Table name to clean (weight or price according to shipping method)
|
* @param string $rangeTable Table name to clean (weight or price according to shipping method)
|
||||||
* @return boolean Deletion result
|
* @return boolean Deletion result
|
||||||
*/
|
*/
|
||||||
public function deleteDeliveryPrice($rangeTable)
|
public function deleteDeliveryPrice($rangeTable, Shop $shop = null)
|
||||||
{
|
{
|
||||||
return Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'delivery` WHERE `id_carrier` = '.(int)($this->id).' AND (`id_'.$rangeTable.'` IS NOT NULL OR `id_'.$rangeTable.'` = 0)');
|
$where = '`id_carrier` = '.(int)$this->id.' AND (`id_'.$rangeTable.'` IS NOT NULL OR `id_'.$rangeTable.'` = 0) ';
|
||||||
|
|
||||||
|
if (!$shop)
|
||||||
|
$shop = Context::getContext()->shop;
|
||||||
|
$shopID = $shop->getID();
|
||||||
|
$shopGroupID = $shop->getGroupID();
|
||||||
|
if (!$shopID && !$shopGroupID)
|
||||||
|
$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
|
||||||
|
$where .= 'AND id_shop = '.$shopID;
|
||||||
|
|
||||||
|
return Db::getInstance()->delete(_DB_PREFIX_.'delivery', $where);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add new delivery prices
|
* Add new delivery prices
|
||||||
*
|
*
|
||||||
* @param string $priceList Prices list separated by commas
|
* @param array $priceList Prices list in multiple arrays (changed to array since 1.5.0)
|
||||||
* @return boolean Insertion result
|
* @return boolean Insertion result
|
||||||
*/
|
*/
|
||||||
public function addDeliveryPrice($priceList)
|
public function addDeliveryPrice($priceList, Shop $shop = null)
|
||||||
{
|
{
|
||||||
if (!Validate::isValuesList($priceList))
|
if (!$priceList)
|
||||||
die(Tools::displayError());
|
return false;
|
||||||
return Db::getInstance()->Execute('
|
|
||||||
INSERT INTO `'._DB_PREFIX_.'delivery` (`id_range_price`, `id_range_weight`, `id_carrier`, `id_zone`, `price`)
|
$keys = array_keys($priceList[0]);
|
||||||
VALUES '.$priceList);
|
if (!in_array('id_shop', $keys))
|
||||||
|
$keys[] = 'id_shop';
|
||||||
|
if (!in_array('id_group_shop', $keys))
|
||||||
|
$keys[] = 'id_group_shop';
|
||||||
|
|
||||||
|
if (!$shop)
|
||||||
|
$shop = Context::getContext()->shop;
|
||||||
|
$shopID = $shop->getID();
|
||||||
|
$shopGroupID = $shop->getGroupID();
|
||||||
|
|
||||||
|
$sql = 'INSERT INTO `'._DB_PREFIX_.'delivery` ('.implode(', ', $keys).') VALUES ';
|
||||||
|
foreach ($priceList as $values)
|
||||||
|
{
|
||||||
|
if (!isset($values['id_shop']))
|
||||||
|
$values['id_shop'] = ($shopID) ? $shopID : null;
|
||||||
|
if (!isset($values['id_group_shop']))
|
||||||
|
$values['id_group_shop'] = ($shopGroupID) ? $shopGroupID : null;
|
||||||
|
|
||||||
|
$sql .= '(';
|
||||||
|
foreach ($values as $v)
|
||||||
|
{
|
||||||
|
if (is_null($v))
|
||||||
|
$sql .= 'NULL';
|
||||||
|
else if (is_int($v) || is_float($v))
|
||||||
|
$sql .= $v;
|
||||||
|
else
|
||||||
|
$sql .= "'$v'";
|
||||||
|
$sql .= ', ';
|
||||||
|
}
|
||||||
|
$sql = rtrim($sql, ', ').'), ';
|
||||||
|
}
|
||||||
|
$sql = rtrim($sql, ', ');
|
||||||
|
return Db::getInstance()->Execute($sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -560,59 +614,43 @@ class CarrierCore extends ObjectModel
|
|||||||
{
|
{
|
||||||
if (!Validate::isUnsignedId($oldId))
|
if (!Validate::isUnsignedId($oldId))
|
||||||
die(Tools::displayError());
|
die(Tools::displayError());
|
||||||
|
|
||||||
|
if (!$this->id)
|
||||||
|
return false;
|
||||||
|
|
||||||
$oldLogo = _PS_SHIP_IMG_DIR_.'/'.(int)($oldId).'.jpg';
|
$oldLogo = _PS_SHIP_IMG_DIR_.'/'.(int)$oldId.'.jpg';
|
||||||
if (file_exists($oldLogo))
|
if (file_exists($oldLogo))
|
||||||
copy($oldLogo, _PS_SHIP_IMG_DIR_.'/'.(int)($this->id).'.jpg');
|
copy($oldLogo, _PS_SHIP_IMG_DIR_.'/'.$this->id.'.jpg');
|
||||||
|
|
||||||
// Copy existing ranges price
|
// Copy existing ranges price
|
||||||
$res = Db::getInstance()->ExecuteS('
|
foreach (array('range_price', 'range_weight') as $range)
|
||||||
SELECT * FROM `'._DB_PREFIX_.'range_price`
|
|
||||||
WHERE id_carrier = '.(int)($oldId));
|
|
||||||
foreach ($res AS $val)
|
|
||||||
{
|
{
|
||||||
Db::getInstance()->Execute('
|
$sql = 'SELECT * FROM `'._DB_PREFIX_.$range.'`
|
||||||
INSERT INTO `'._DB_PREFIX_.'range_price` (`id_carrier`, `delimiter1`, `delimiter2`)
|
WHERE id_carrier = '.(int)$oldId;
|
||||||
VALUES ('.(int)($this->id).','.(float)($val['delimiter1']).','.(float)($val['delimiter2']).')');
|
$res = Db::getInstance()->ExecuteS($sql);
|
||||||
$maxRangePrice = Db::getInstance()->Insert_ID();
|
foreach ($res AS $val)
|
||||||
$res2 = Db::getInstance()->ExecuteS('
|
{
|
||||||
SELECT * FROM `'._DB_PREFIX_.'delivery`
|
$sql = 'INSERT INTO `'._DB_PREFIX_.$range.'` (`id_carrier`, `delimiter1`, `delimiter2`)
|
||||||
WHERE id_carrier = '.(int)($oldId).'
|
VALUES ('.$this->id.','.(float)$val['delimiter1'].','.(float)$val['delimiter2'].')';
|
||||||
AND id_range_price = '.(int)($val['id_range_price']));
|
Db::getInstance()->Execute($sql);
|
||||||
foreach ($res2 AS $val2)
|
$rangeID = (int)Db::getInstance()->Insert_ID();
|
||||||
Db::getInstance()->Execute('
|
|
||||||
INSERT INTO `'._DB_PREFIX_.'delivery` (`id_carrier`,`id_range_price`,`id_range_weight`,`id_zone`, `price`)
|
$rangePriceID = ($range == 'range_price') ? $rangeID : 'NULL';
|
||||||
VALUES ('.(int)($this->id).','.(int)($maxRangePrice).',NULL,'.(int)($val2['id_zone']).','.(float)($val2['price']).')');
|
$rangeWeightID = ($range == 'range_weight') ? $rangeID : 'NULL';
|
||||||
}
|
$sql = 'INSERT INTO '._DB_PREFIX_.$range.' (id_carrier, id_shop, id_group_shop, id_range_price, id_range_weight, id_zone, price)
|
||||||
|
SELECT '.$this->id.', id_shop, id_group_shop, '.$rangePriceID.', '.$rangeWeightID.', id_zone, price FROM '._DB_PREFIX_.$range;
|
||||||
// Copy existing ranges weight
|
Db::getInstance()->Execute($sql);
|
||||||
$res = Db::getInstance()->ExecuteS('
|
}
|
||||||
SELECT * FROM `'._DB_PREFIX_.'range_weight`
|
|
||||||
WHERE id_carrier = '.(int)($oldId));
|
|
||||||
foreach ($res as $val)
|
|
||||||
{
|
|
||||||
Db::getInstance()->Execute('
|
|
||||||
INSERT INTO `'._DB_PREFIX_.'range_weight` (`id_carrier`, `delimiter1`, `delimiter2`)
|
|
||||||
VALUES ('.(int)($this->id).','.(float)($val['delimiter1']).','.(float)($val['delimiter2']).')');
|
|
||||||
$maxRangeWeight = Db::getInstance()->Insert_ID();
|
|
||||||
$res2 = Db::getInstance()->ExecuteS('
|
|
||||||
SELECT * FROM `'._DB_PREFIX_.'delivery`
|
|
||||||
WHERE id_carrier = '.(int)($oldId).'
|
|
||||||
AND id_range_weight = '.(int)($val['id_range_weight']));
|
|
||||||
foreach ($res2 as $val2)
|
|
||||||
Db::getInstance()->Execute('
|
|
||||||
INSERT INTO `'._DB_PREFIX_.'delivery` (`id_carrier`,`id_range_price`,`id_range_weight`,`id_zone`, `price`)
|
|
||||||
VALUES ('.(int)($this->id).',NULL,'.(int)($maxRangeWeight).','.(int)($val2['id_zone']).','.(float)($val2['price']).')');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy existing zones
|
// Copy existing zones
|
||||||
$res = Db::getInstance()->ExecuteS('
|
$sql = 'SELECT * FROM `'._DB_PREFIX_.'carrier_zone`
|
||||||
SELECT * FROM `'._DB_PREFIX_.'carrier_zone`
|
WHERE id_carrier = '.(int)$oldId;
|
||||||
WHERE id_carrier = '.(int)($oldId));
|
$res = Db::getInstance()->ExecuteS($sql);
|
||||||
foreach ($res as $val)
|
foreach ($res as $val)
|
||||||
Db::getInstance()->Execute('
|
Db::getInstance()->Execute('
|
||||||
INSERT INTO `'._DB_PREFIX_.'carrier_zone` (`id_carrier`, `id_zone`)
|
INSERT INTO `'._DB_PREFIX_.'carrier_zone` (`id_carrier`, `id_zone`)
|
||||||
VALUES ('.(int)($this->id).','.(int)($val['id_zone']).')');
|
VALUES ('.$this->id.','.(int)$val['id_zone'].')');
|
||||||
|
|
||||||
//Copy default carrier
|
//Copy default carrier
|
||||||
if ((int)(Configuration::get('PS_CARRIER_DEFAULT')) == $oldId)
|
if ((int)(Configuration::get('PS_CARRIER_DEFAULT')) == $oldId)
|
||||||
@@ -708,5 +746,40 @@ class CarrierCore extends ObjectModel
|
|||||||
|
|
||||||
return self::$_cache_tax_rule[$id_carrier];
|
return self::$_cache_tax_rule[$id_carrier];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This tricky method generate a sql clause to check if ranged data are overloaded by multishop
|
||||||
|
*
|
||||||
|
* @since 1.5.0
|
||||||
|
* @param string $rangeTable
|
||||||
|
* @param Shop $shop
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function sqlDeliveryRangeShop($rangeTable, Shop $shop = null, $alias = 'd')
|
||||||
|
{
|
||||||
|
if (!$shop)
|
||||||
|
$shop = Context::getContext()->shop;
|
||||||
|
$shopID = $shop->getID();
|
||||||
|
$shopGroupID = $shop->getGroupID();
|
||||||
|
$where = '';
|
||||||
|
if (!$shopID && !$shopGroupID)
|
||||||
|
$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
|
||||||
|
$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))';
|
||||||
|
|
||||||
|
$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.'
|
||||||
|
'.$where.'
|
||||||
|
ORDER BY d2.id_shop DESC, d2.id_group_shop DESC
|
||||||
|
LIMIT 1
|
||||||
|
)';
|
||||||
|
return $sql;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+4
-4
@@ -289,10 +289,10 @@ abstract class DbCore
|
|||||||
/**
|
/**
|
||||||
* Execute a DELETE query
|
* Execute a DELETE query
|
||||||
*
|
*
|
||||||
* @param unknown_type $table Name of the table to delete
|
* @param string $table Name of the table to delete
|
||||||
* @param unknown_type $where WHERE clause on query
|
* @param string $where WHERE clause on query
|
||||||
* @param unknown_type $limit Number max of rows to delete
|
* @param int $limit Number max of rows to delete
|
||||||
* @param unknown_type $use_cache Use cache or not
|
* @param bool $use_cache Use cache or not
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function delete($table, $where = false, $limit = false, $use_cache = 1)
|
public function delete($table, $where = false, $limit = false, $use_cache = 1)
|
||||||
|
|||||||
+15
-5
@@ -30,6 +30,12 @@ class DeliveryCore extends ObjectModel
|
|||||||
/** @var integer */
|
/** @var integer */
|
||||||
public $id_delivery;
|
public $id_delivery;
|
||||||
|
|
||||||
|
/** @var int **/
|
||||||
|
public $id_shop;
|
||||||
|
|
||||||
|
/** @var int **/
|
||||||
|
public $id_group_shop;
|
||||||
|
|
||||||
/** @var integer */
|
/** @var integer */
|
||||||
public $id_carrier;
|
public $id_carrier;
|
||||||
|
|
||||||
@@ -66,11 +72,15 @@ class DeliveryCore extends ObjectModel
|
|||||||
{
|
{
|
||||||
parent::validateFields();
|
parent::validateFields();
|
||||||
|
|
||||||
$fields['id_carrier'] = (int)($this->id_carrier);
|
if ($this->id_shop)
|
||||||
$fields['id_range_price'] = (int)($this->id_range_price);
|
$fields['id_shop'] = (int)$this->id_shop;
|
||||||
$fields['id_range_weight'] = (int)($this->id_range_weight);
|
if ($this->id_group_shop)
|
||||||
$fields['id_zone'] = (int)($this->id_zone);
|
$fields['id_group_shop'] = (int)$this->id_group_shop;
|
||||||
$fields['price'] = (float)($this->price);
|
$fields['id_carrier'] = (int)$this->id_carrier;
|
||||||
|
$fields['id_range_price'] = (int)$this->id_range_price;
|
||||||
|
$fields['id_range_weight'] = (int)$this->id_range_weight;
|
||||||
|
$fields['id_zone'] = (int)$this->id_zone;
|
||||||
|
$fields['price'] = (float)$this->price;
|
||||||
|
|
||||||
return $fields;
|
return $fields;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,6 +58,7 @@ class ShopCore extends ObjectModel
|
|||||||
|
|
||||||
private static $assoTables = array(
|
private static $assoTables = array(
|
||||||
'carrier' => array('type' => 'shop'),
|
'carrier' => array('type' => 'shop'),
|
||||||
|
'carrier_lang' => array('type' => 'fk_shop'),
|
||||||
'category_lang' => array('type' => 'fk_shop'),
|
'category_lang' => array('type' => 'fk_shop'),
|
||||||
'cms' => array('type' => 'shop'),
|
'cms' => array('type' => 'shop'),
|
||||||
'contact' => array('type' => 'shop'),
|
'contact' => array('type' => 'shop'),
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ class CompareControllerCore extends FrontController
|
|||||||
foreach ($curProduct->getFrontFeatures(self::$cookie->id_lang) AS $feature)
|
foreach ($curProduct->getFrontFeatures(self::$cookie->id_lang) AS $feature)
|
||||||
$listFeatures[$curProduct->id][$feature['id_feature']] = $feature['value'];
|
$listFeatures[$curProduct->id][$feature['id_feature']] = $feature['value'];
|
||||||
|
|
||||||
$cover = Product::getCover((int)$id, (int)$this->id_current_shop);
|
$cover = Product::getCover((int)$id);
|
||||||
|
|
||||||
$curProduct->id_image = Tools::htmlentitiesUTF8(Product::defineProductImage(array('id_image' => $cover['id_image'], 'id_product' => $id), self::$cookie->id_lang));
|
$curProduct->id_image = Tools::htmlentitiesUTF8(Product::defineProductImage(array('id_image' => $cover['id_image'], 'id_product' => $id), self::$cookie->id_lang));
|
||||||
$curProduct->allow_oosp = Product::isAvailableWhenOutOfStock($curProduct->out_of_stock);
|
$curProduct->allow_oosp = Product::isAvailableWhenOutOfStock($curProduct->out_of_stock);
|
||||||
|
|||||||
@@ -527,6 +527,8 @@ CREATE TABLE `PREFIX_date_range` (
|
|||||||
|
|
||||||
CREATE TABLE `PREFIX_delivery` (
|
CREATE TABLE `PREFIX_delivery` (
|
||||||
`id_delivery` int(10) unsigned NOT NULL auto_increment,
|
`id_delivery` int(10) unsigned NOT NULL auto_increment,
|
||||||
|
`id_shop` INT UNSIGNED NULL DEFAULT NULL,
|
||||||
|
`id_group_shop` INT UNSIGNED NULL DEFAULT NULL;
|
||||||
`id_carrier` int(10) unsigned NOT NULL,
|
`id_carrier` int(10) unsigned NOT NULL,
|
||||||
`id_range_price` int(10) unsigned default NULL,
|
`id_range_price` int(10) unsigned default NULL,
|
||||||
`id_range_weight` int(10) unsigned default NULL,
|
`id_range_weight` int(10) unsigned default NULL,
|
||||||
|
|||||||
@@ -319,5 +319,6 @@ PRIMARY KEY (`id_discount`, `id_shop`),
|
|||||||
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
|
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
|
||||||
INSERT INTO `PREFIX_discount_shop` (id_shop, id_discount) (SELECT 1, id_discount FROM PREFIX_discount);
|
INSERT INTO `PREFIX_discount_shop` (id_shop, id_discount) (SELECT 1, id_discount FROM PREFIX_discount);
|
||||||
|
|
||||||
|
ALTER TABLE `PREFIX_delivery` ADD `id_shop` INT UNSIGNED NULL DEFAULT NULL AFTER `id_delivery`, ADD `id_group_shop` INT UNSIGNED NULL DEFAULT NULL AFTER `id_shop`;
|
||||||
|
|
||||||
/* PHP:create_multistore(); */
|
/* PHP:create_multistore(); */
|
||||||
|
|||||||
Reference in New Issue
Block a user