From c8b204e35d3800bd4381861c12e35bb63da190de Mon Sep 17 00:00:00 2001 From: Rodney Figaro Date: Fri, 17 Mar 2017 10:57:46 +0100 Subject: [PATCH] 12615 - remove automatically ups product from cart, change text displayed in delivery step --- classes/Cart.php | 10 +- override/classes/Cart.php | 16 ++- .../controllers/front/OrderController.php | 104 +++++++++++------- themes/default/js/order-address.js | 20 +++- themes/default/order-address.tpl | 2 +- themes/default/order-carrier-simple.tpl | 39 ++++--- themes/default/order-carrier.tpl | 38 ++++--- 7 files changed, 151 insertions(+), 78 deletions(-) diff --git a/classes/Cart.php b/classes/Cart.php index 0e703b3..fcdb8fe 100755 --- a/classes/Cart.php +++ b/classes/Cart.php @@ -1670,6 +1670,7 @@ class CartCore extends ObjectModel $warehouse_count_by_address[$product['id_address_delivery']][$warehouse['id_warehouse']]++; } } + unset($product); arsort($warehouse_count_by_address); @@ -1879,13 +1880,14 @@ class CartCore extends ObjectModel public function getDeliveryOptionList(Country $default_country = null, $flush = false) { static $cache = null; - if ($cache !== null && !$flush) + if ($cache !== null && !$flush){ return $cache; + } $delivery_option_list = array(); $carriers_price = array(); $carrier_collection = array(); - $package_list = $this->getPackageList(); + $package_list = $this->getPackageList($flush); // Foreach addresses foreach ($package_list as $id_address => $packages) @@ -2093,8 +2095,10 @@ class CartCore extends ObjectModel } // Sort delivery option list - foreach ($delivery_option_list as &$array) + foreach ($delivery_option_list as &$array){ uasort ($array, array('Cart', 'sortDeliveryOptionList')); + } + unset($array); $cache = $delivery_option_list; return $delivery_option_list; diff --git a/override/classes/Cart.php b/override/classes/Cart.php index a1852e6..4161547 100755 --- a/override/classes/Cart.php +++ b/override/classes/Cart.php @@ -579,11 +579,23 @@ class Cart extends CartCore { $UPS_ids_reference = array('34', '49'); + $current_id_address_delivery = $this->id_address_delivery; + + // in case tho delivery is already selected, check for the default adress of the customer + if (empty($current_id_address_delivery)) { + $current_id_address_delivery = Address::getFirstCustomerAddressId($this->id_customer); + } + + // in case no adresse has been specified + if (empty($current_id_address_delivery)) { + return ''; + } + // get all carrier reference for the current select address' zone delivery $sql = 'SELECT `id_reference` FROM `'._DB_PREFIX_.'carrier` c JOIN `'._DB_PREFIX_.'carrier_zone` cz ON cz.`id_carrier` = c.`id_carrier` - WHERE cz.`id_zone` = '.(int)Address::getZoneById($this->id_address_delivery).' + WHERE cz.`id_zone` = '.(int)Address::getZoneById($current_id_address_delivery).' AND c.`active` = 1 AND c.`deleted` = 0'; $rows = Db::getInstance()->executeS($sql); @@ -608,7 +620,7 @@ class Cart extends CartCore // we exclude this product when UPS is not in its limited list of carriers if (0 == count(array_intersect($UPS_ids_reference, array_column($rows, 'id_carrier_reference')))) { - return trim($product['name']); + return $product; } } } diff --git a/override/controllers/front/OrderController.php b/override/controllers/front/OrderController.php index 4b2b7e9..739f7e3 100755 --- a/override/controllers/front/OrderController.php +++ b/override/controllers/front/OrderController.php @@ -26,32 +26,73 @@ class OrderController extends OrderControllerCore { + private function updateCartWhenContainProductToExclude() + { + $restricted_product = $this->context->cart->getExcludedUPSProductNameForUPSDelivery(); + if (is_array($restricted_product)) { + if ($this->context->language->id == 1) { + $txt = sprintf('"%s" est un soin qui ne peut malheureusement pas être transporté par voie aérienne. Afin de poursuivre votre commande, nous l\'avons retiré de votre panier.', trim($restricted_product['name'])); + } + else { + $txt = sprintf('"%s" cannot be carried by plane. We remove the product from your cart so that you can resume your order.', trim($restricted_product['name'])); + } + $this->addCookieRestrictedProductText($txt); + $this->context->smarty->assign('restricted_product_txt', $txt); + $this->context->cart->deleteProduct($restricted_product['id_product']); + } + } + + private function getCookieRestrictedProductText() + { + if (isset($this->context->cookie->restricted_product_txt)) { + return $this->context->cookie->restricted_product_txt; + } + return ''; + } + + private function addCookieRestrictedProductText($txt) + { + $this->context->cookie->restricted_product_txt = $txt; + } + + private function removeCookieRestrictedProductText() + { + if (isset($this->context->cookie->restricted_product_txt)) { + unset($this->context->cookie->restricted_product_txt); + } + } + public function postProcess() { // Update carrier selected on preProccess in order to fix a bug of // block cart when it's hooked on leftcolumn - if(Tools::isSubmit('submitPanier')){ + if(Tools::isSubmit('submitPanier')) { $echantillons_ids_product=$_POST['echantillon']; // Rajouter les échantillons dans le panier if (!$this->context->cart->saveEchantillons($echantillons_ids_product)) { - Tools::redirect('index.php?controller=order&step=0&error_echantillons=1'); } } - if ((int)(Tools::getValue('gift'))) - { + + if ((int)(Tools::getValue('gift'))) { $this->context->cart->gift = (int)(Tools::getValue('gift')); } - if (Tools::getValue('message')) - { + + if (Tools::getValue('message')) { $this->context->cart->gift_message = strip_tags($_POST['message']); // die(); } + + if (Tools::getValue('step')=='1') { + $this->updateCartWhenContainProductToExclude(); + // force option list to be refreshed + $this->context->smarty->assign('delivery_option_list', $this->context->cart->getDeliveryOptionList(null, true)); + } // if ($this->step == 2 && Tools::isSubmit('processCarrier')) // if ($this->step == 1 || ($this->step == 2 && Tools::isSubmit('processAddress'))) - $this->processCarrier(); + //$this->processCarrier(); } /** @@ -89,6 +130,9 @@ class OrderController extends OrderControllerCore { global $isVirtualCart; + ParentOrderController::initContent(); + + $this->context->smarty->assign('step', Tools::getValue('step',-2)); $this->context->cart->checkProductForEchantillon(); @@ -193,13 +237,17 @@ class OrderController extends OrderControllerCore // Wrapping fees $wrapping_fees = $this->context->cart->getGiftWrappingPrice(false); $wrapping_fees_tax_inc = $wrapping_fees = $this->context->cart->getGiftWrappingPrice(); + $result = array_merge($result, array( + 'restricted_product_txt' => $this->getCookieRestrictedProductText(), 'HOOK_TOP_PAYMENT' => Hook::exec('displayPaymentTop'), 'HOOK_PAYMENT' => $this->_getPaymentMethods(), 'gift_price' => Tools::displayPrice(Tools::convertPrice(Product::getTaxCalculationMethod() == 1 ? $wrapping_fees : $wrapping_fees_tax_inc, new Currency((int)($this->context->cookie->id_currency)))), 'carrier_data' => $this->_getCarrierList()), $this->getFormatedSummaryDetail() ); + + $this->removeCookieRestrictedProductText(); die(Tools::jsonEncode($result)); } } @@ -225,8 +273,6 @@ class OrderController extends OrderControllerCore $this->_assignEchantillons(); $this->_assignCarrier(); // $this->processCarrier(); - // echo $this->step; - // die(); $this->setTemplate(_PS_THEME_DIR_.'shopping-cart.tpl'); break; @@ -235,11 +281,8 @@ class OrderController extends OrderControllerCore Tools::redirect('index.php?controller=order&step=0&error_echantillons=1'); } - // echo "test"; - // die(); - // $this->processCarrier(); $this->_assignSummaryInformations(); - $this->_assignCarrier(); + //$this->_assignCarrier(); $this->_assignAddress(); $this->autoStep(); $this->processAddressFormat(); @@ -250,17 +293,17 @@ class OrderController extends OrderControllerCore // $this->context->smarty->assign('product_list', $this->context->cart->getProducts()); // $this->setTemplate(_PS_THEME_DIR_.'order-address-multishipping.tpl'); // } - // else - // echo "test"; - // die(); - $this->setTemplate(_PS_THEME_DIR_.'order-address.tpl'); + $this->setTemplate(_PS_THEME_DIR_.'order-address.tpl'); + break; case 2: - if (count($this->context->cart->getDeliveryAddressesWithoutCarriers(true))>0) { + if (is_array($this->context->cart->getExcludedUPSProductNameForUPSDelivery())) { Tools::redirect('index.php?controller=order&step=1'); } +// if (count($this->context->cart->getDeliveryAddressesWithoutCarriers(true))>0) { +// } if (!$this->context->cart->isNbEchantillonsInCartAllowed()) { Tools::redirect('index.php?controller=order&step=0&error_echantillons=1'); @@ -272,7 +315,7 @@ class OrderController extends OrderControllerCore // $this->processAddress(); $this->_assignAddress(); $this->autoStep(); - $this->_assignCarrier(); + //$this->_assignCarrier(); // $this->setTemplate(_PS_THEME_DIR_.'order-carrier.tpl'); // break; @@ -388,7 +431,7 @@ class OrderController extends OrderControllerCore 'currencyFormat' => $this->context->currency->format, 'currencyBlank' => $this->context->currency->blank, )); - parent::initContent(); + //parent::initContent(); } protected function _getCarrierList() @@ -566,9 +609,6 @@ class OrderController extends OrderControllerCore if ($delivery->deleted || $invoice->deleted) { -// echo $delivery->deleted; -// echo $invoice->deleted; - // die(); if ($delivery->deleted) unset($this->context->cart->id_address_delivery); if ($invoice->deleted) @@ -716,17 +756,8 @@ class OrderController extends OrderControllerCore // return true; - if (count($this->errors)) - { - // print_r($this->errors); + if (count($this->errors)) { $this->context->smarty->assign('errors', $this->errors); - // $this->_assignCarrier(); - // $this->step = 2; - // echo $this->step; - // die(); - // $this->displayContent(); - // include(dirname(__FILE__).'/../footer.php'); - // exit; } $orderTotal = $this->context->cart->getOrderTotal(); } @@ -742,7 +773,8 @@ class OrderController extends OrderControllerCore $this->context->cart->autosetProductAddress(); $this->context->smarty->assign('cart', $this->context->cart); - parent::_assignCarrier(); + //parent::_assignCarrier(); + $this->_assignCarrier(); // Assign wrapping and TOS $this->_assignWrappingAndTOS(); @@ -760,10 +792,8 @@ class OrderController extends OrderControllerCore $list_ids_carrier_mondial_relay[] = $row['id_carrier']; } - // if (!isset($this->context->customer->id)) - // die(Tools::displayError('Fatal error: No customer')); // Assign carrier - // parent::_assignCarrier(); + //parent::_assignCarrier(); // Assign wrapping and TOS $this->_assignWrappingAndTOS(); diff --git a/themes/default/js/order-address.js b/themes/default/js/order-address.js index 2a30c63..11c507c 100755 --- a/themes/default/js/order-address.js +++ b/themes/default/js/order-address.js @@ -61,9 +61,13 @@ $(document).ready(function() }); //update the display of the addresses +var is_from_clicked = false; function updateAddressesDisplay(first_view) { - // alert(first_view); + if (first_view!=true) { + is_from_clicked = true; + } + //alert(first_view); // alert('test'); // update content of delivery address // updateAddressDisplay('delivery'); @@ -199,6 +203,10 @@ function updateCarrierList(json) function updateAddressSelection(deliveryAddress) { + if (is_from_clicked==true) { + $('#restricted_product_txt').removeClass('restricted_initial'); + } + var idAddress_delivery = $('#id_address_delivery').val(); var idAddress_invoice = ($('#id_address_invoice').length == 1 ? $('#id_address_invoice').val() : ($('#addressesAreEquals:checked').length == 1 ? idAddress_delivery : ($('#id_address_invoice').length == 1 ? $('#id_address_invoice').val() : deliveryAddress))); // alert(refreshAddress); @@ -232,6 +240,16 @@ function updateAddressSelection(deliveryAddress) } else { + if (!$('#restricted_product_txt').hasClass('restricted_initial')){ + $('#restricted_product_txt').html(jsonData.restricted_product_txt); + if (jsonData.restricted_product_txt == '') { + $('#restricted_product_txt').hide(); + } + else { + $('#restricted_product_txt').show(); + } + } + // Update all product keys with the new address id $('#cart_summary .address_'+deliveryAddress).each(function() { $(this) diff --git a/themes/default/order-address.tpl b/themes/default/order-address.tpl index d52f0d5..7677c8c 100755 --- a/themes/default/order-address.tpl +++ b/themes/default/order-address.tpl @@ -242,7 +242,7 @@

- {foreach from=$addresses key=k item=address} diff --git a/themes/default/order-carrier-simple.tpl b/themes/default/order-carrier-simple.tpl index 9bfe567..e20fc57 100755 --- a/themes/default/order-carrier-simple.tpl +++ b/themes/default/order-carrier-simple.tpl @@ -87,6 +87,16 @@

{/if} +
+{if isset($restricted_product_txt) && $restricted_product_txt!=''} +

+ {$restricted_product_txt} +

+{else} + +{/if} +
+
{if isset($carriers) && isset($HOOK_BEFORECARRIER)} @@ -132,26 +142,21 @@ {/foreach}
{if isset($HOOK_EXTRACARRIER_ADDR) && isset($HOOK_EXTRACARRIER_ADDR.$id_address)}{$HOOK_EXTRACARRIER_ADDR.$id_address}{/if}
- {foreachelse} + {foreachelse} + {if !isset($restricted_product_name)}

- {$restricted_product_name = $cart->getExcludedUPSProductNameForUPSDelivery()} - {if $restricted_product_name!=''} - {l s='"%s" est un soin qui ne peut malheureusement pas être transporté par voie aérienne.' sprintf=$restricted_product_name} + {foreach $cart->getDeliveryAddressesWithoutCarriers(true) as $address} + {if empty($address->alias)} + {l s='No carriers available.'} + {else} + {l s='No carriers available for the address "%s".' sprintf=$address->alias} + {/if} + {if !$address@last}
- {l s='Afin de poursuivre votre commande, nous vous conseillons de le retirer de votre panier ou de choisir une autre adresse de livraison.'} - {else} - {foreach $cart->getDeliveryAddressesWithoutCarriers(true) as $address} - {if empty($address->alias)} - {l s='No carriers available.'} - {else} - {l s='No carriers available for the address "%s".' sprintf=$address->alias} - {/if} - {if !$address@last} -
- {/if} - {/foreach} - {/if} + {/if} + {/foreach}

+ {/if} {/foreach} {/if} diff --git a/themes/default/order-carrier.tpl b/themes/default/order-carrier.tpl index c4cc5ef..8c00d10 100755 --- a/themes/default/order-carrier.tpl +++ b/themes/default/order-carrier.tpl @@ -86,6 +86,15 @@
{/if} +
+{if isset($restricted_product_txt) && $restricted_product_txt!=''} +

+ {$restricted_product_txt} +

+{else} + +{/if} +
@@ -132,26 +141,21 @@ {/foreach}
{if isset($HOOK_EXTRACARRIER_ADDR) && isset($HOOK_EXTRACARRIER_ADDR.$id_address)}{$HOOK_EXTRACARRIER_ADDR.$id_address}{/if}
- {foreachelse} + {foreachelse} + {if !isset($restricted_product_name)}

- {$restricted_product_name = $cart->getExcludedUPSProductNameForUPSDelivery()} - {if $restricted_product_name!=''} - {l s='"%s" est un soin qui ne peut malheureusement pas être transporté par voie aérienne.' sprintf=$restricted_product_name} + {foreach $cart->getDeliveryAddressesWithoutCarriers(true) as $address} + {if empty($address->alias)} + {l s='No carriers available.'} + {else} + {l s='No carriers available for the address "%s".' sprintf=$address->alias} + {/if} + {if !$address@last}
- {l s='Afin de poursuivre votre commande, nous vous conseillons de le retirer de votre panier ou de choisir une autre adresse de livraison.'} - {else} - {foreach $cart->getDeliveryAddressesWithoutCarriers(true) as $address} - {if empty($address->alias)} - {l s='No carriers available.'} - {else} - {l s='No carriers available for the test address "%s".' sprintf=$address->alias} - {/if} - {if !$address@last} -
- {/if} - {/foreach} - {/if} + {/if} + {/foreach}

+ {/if} {/foreach} {/if}