From 7e3fe498477f65eacdae514db22a3169e924cd7e Mon Sep 17 00:00:00 2001 From: Marion Muszynski Date: Fri, 18 Mar 2016 17:06:08 +0100 Subject: [PATCH] fix price in socolissimo --- modules/socolissimo/socolissimo.php | 48 +++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 12 deletions(-) diff --git a/modules/socolissimo/socolissimo.php b/modules/socolissimo/socolissimo.php index 66b74ee0..770ff115 100755 --- a/modules/socolissimo/socolissimo.php +++ b/modules/socolissimo/socolissimo.php @@ -580,18 +580,13 @@ class Socolissimo extends CarrierModule (float) $this->seller_cost += (float) Configuration::get('PS_SHIPPING_HANDLING'); } - $product_cats = array(); - foreach($params['cart']->getProducts() as $product) { - $product_cats[] = (int) $product['id_category_default']; + // Fix du prix si vente consommable + if ($this->getOrderShippingCostConsummable($params['cart'])) { + $this->seller_cost = 5; + $tax_rate = 0; + $tax_rate_seller = 0; } - $sales = Db::getInstance()->ExecuteS(' - SELECT DISTINCT `id_sale` - FROM `'._DB_PREFIX_.'privatesale_category` - WHERE `id_category` IN ('.implode(', ', $product_cats).') - '); - - $cpt_sales = count($sales); if($cpt_sales == 2) { (float) $this->initial_cost += (float) Configuration::get('PS_SHIPPING_HANDLING_PS_1'); if($this->seller_cost) { @@ -619,8 +614,7 @@ class Socolissimo extends CarrierModule } } } - - + if ($tax_rate) $std_cost_with_taxes = number_format((float)$this->initial_cost * (1 + ($tax_rate / 100)), 2, ',', ' '); else @@ -1334,11 +1328,41 @@ class Socolissimo extends CarrierModule $carrier = new Carrier((int)Configuration::get('SOCOLISSIMO_CARRIER_ID')); $address = new Address((int)$this->context->cart->id_address_delivery); $id_zone = Address::getZoneById((int)$address->id); + + // Fix du prix si vente consommable + if ($this->getOrderShippingCostConsummable($this->context->cart)) { + $shipping_cost = 5; + return $shipping_cost; + } + return $this->getCostByShippingMethod($carrier, $id_zone); } return false; } + public function getOrderShippingCostConsummable($cart) { + // Fix du prix si vente consommable + $product_cats = array(); + foreach($cart->getProducts() as $product) { + $product_cats[] = (int) $product['id_category_default']; + } + $sales = Db::getInstance()->ExecuteS(' + SELECT DISTINCT `id_sale` + FROM `'._DB_PREFIX_.'privatesale_category` + WHERE `id_category` IN ('.implode(', ', $product_cats).') + '); + $cpt_sales = count($sales); + // si consommables forcer à 5euros + if ($cpt_sales==1) { + foreach ($sales as $key => $sale) { + if ((int) $sale['id_sale'] == (int) _SHOP_PRIVATESALES_CONSUMABLE) { + return true; + } + } + } + return false; + } + public function getOrderShippingCostExternal($params) { return;