Skip to content

Commit

Permalink
Add hooks actionDeliveryPriceByPrice and actionDeliveryPriceByWeight …
Browse files Browse the repository at this point in the history
…to customize delivery prices
  • Loading branch information
gandalfthegreydev committed Jan 19, 2015
1 parent 2b5dbaf commit 13a86f2
Showing 1 changed file with 29 additions and 5 deletions.
34 changes: 29 additions & 5 deletions classes/Carrier.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,8 @@ public function setConfiguration($id_old)
*/
public function getDeliveryPriceByWeight($total_weight, $id_zone)
{
$cache_key = $this->id.'_'.$total_weight.'_'.$id_zone;
$id_carrier = (int)$this->id;
$cache_key = $id_carrier.'_'.$total_weight.'_'.$id_zone;
if (!isset(self::$price_by_weight[$cache_key]))
{
$sql = 'SELECT d.`price`
Expand All @@ -243,7 +244,7 @@ public function getDeliveryPriceByWeight($total_weight, $id_zone)
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.'
AND d.`id_carrier` = '.$id_carrier.'
'.Carrier::sqlDeliveryRangeShop('range_weight').'
ORDER BY w.`delimiter1` ASC';
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql);
Expand All @@ -252,11 +253,17 @@ public function getDeliveryPriceByWeight($total_weight, $id_zone)
else
self::$price_by_weight[$cache_key] = $result['price'];
}

$price_by_weight = Hook::exec('actionDeliveryPriceByWeight', array('id_carrier' => $id_carrier, 'total_weight' => $total_weight, 'id_zone' => $id_zone));
if (is_numeric($price_by_weight))
self::$price_by_weight[$cache_key] = $price_by_weight;

return self::$price_by_weight[$cache_key];
}

public static function checkDeliveryPriceByWeight($id_carrier, $total_weight, $id_zone)
{
$id_carrier = (int)$id_carrier;
$cache_key = $id_carrier.'_'.$total_weight.'_'.$id_zone;
if (!isset(self::$price_by_weight2[$cache_key]))
{
Expand All @@ -266,12 +273,17 @@ public static function checkDeliveryPriceByWeight($id_carrier, $total_weight, $i
WHERE d.`id_zone` = '.(int)$id_zone.'
AND '.(float)$total_weight.' >= w.`delimiter1`
AND '.(float)$total_weight.' < w.`delimiter2`
AND d.`id_carrier` = '.(int)$id_carrier.'
AND d.`id_carrier` = '.$id_carrier.'
'.Carrier::sqlDeliveryRangeShop('range_weight').'
ORDER BY w.`delimiter1` ASC';
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql);
self::$price_by_weight2[$cache_key] = (isset($result['price']));
}

$price_by_weight = Hook::exec('actionDeliveryPriceByWeight', array('id_carrier' => $id_carrier, 'total_weight' => $total_weight, 'id_zone' => $id_zone));
if (is_numeric($price_by_weight))
self::$price_by_weight2[$cache_key] = $price_by_weight;

return self::$price_by_weight2[$cache_key];
}

Expand Down Expand Up @@ -302,6 +314,7 @@ public function getMaxDeliveryPriceByWeight($id_zone)
*/
public function getDeliveryPriceByPrice($order_total, $id_zone, $id_currency = null)
{
$id_carrier = (int)$this->id;
$cache_key = $this->id.'_'.$order_total.'_'.$id_zone.'_'.$id_currency;
if (!isset(self::$price_by_price[$cache_key]))
{
Expand All @@ -314,7 +327,7 @@ public function getDeliveryPriceByPrice($order_total, $id_zone, $id_currency = n
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.'
AND d.`id_carrier` = '.$id_carrier.'
'.Carrier::sqlDeliveryRangeShop('range_price').'
ORDER BY r.`delimiter1` ASC';
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql);
Expand All @@ -323,6 +336,11 @@ public function getDeliveryPriceByPrice($order_total, $id_zone, $id_currency = n
else
self::$price_by_price[$cache_key] = $result['price'];
}

$price_by_price = Hook::exec('actionDeliveryPriceByPrice', array('id_carrier' => $id_carrier, 'order_total' => $order_total, 'id_zone' => $id_zone));
if (is_numeric($price_by_price))
self::$price_by_price[$cache_key] = $price_by_price;

return self::$price_by_price[$cache_key];
}

Expand All @@ -337,6 +355,7 @@ public function getDeliveryPriceByPrice($order_total, $id_zone, $id_currency = n
*/
public static function checkDeliveryPriceByPrice($id_carrier, $order_total, $id_zone, $id_currency = null)
{
$id_carrier = (int)$id_carrier;
$cache_key = $id_carrier.'_'.$order_total.'_'.$id_zone.'_'.$id_currency;
if (!isset(self::$price_by_price2[$cache_key]))
{
Expand All @@ -349,12 +368,17 @@ public static function checkDeliveryPriceByPrice($id_carrier, $order_total, $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)$id_carrier.'
AND d.`id_carrier` = '.$id_carrier.'
'.Carrier::sqlDeliveryRangeShop('range_price').'
ORDER BY r.`delimiter1` ASC';
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql);
self::$price_by_price2[$cache_key] = (isset($result['price']));
}

$price_by_price = Hook::exec('actionDeliveryPriceByPrice', array('id_carrier' => $id_carrier, 'order_total' => $order_total, 'id_zone' => $id_zone));
if (is_numeric($price_by_price))
self::$price_by_price2[$cache_key] = $price_by_price;

return self::$price_by_price2[$cache_key];
}

Expand Down

0 comments on commit 13a86f2

Please sign in to comment.