// Autoset id_carrier on the cart constructor + Replace a hookExec()
This commit is contained in:
+23
-5
@@ -167,6 +167,18 @@ class CartCore extends ObjectModel
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
$this->_taxCalculationMethod = Group::getDefaultPriceDisplayMethod();
|
$this->_taxCalculationMethod = Group::getDefaultPriceDisplayMethod();
|
||||||
|
|
||||||
|
// id_carrier is not setted since 1.5.0
|
||||||
|
// Need to set it virtualy by using the delivery_option_list
|
||||||
|
if (!empty($this->delivery_option))
|
||||||
|
{
|
||||||
|
$delivery_option = unserialize($this->delivery_option);
|
||||||
|
if (count($delivery_option) == 1)
|
||||||
|
{
|
||||||
|
$delivery_option_list = $this->getDeliveryOptionList();
|
||||||
|
$this->id_carrier = $this->getIdCarrierFromDeliveryOption($delivery_option);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function add($autodate = true, $nullValues = false)
|
public function add($autodate = true, $nullValues = false)
|
||||||
@@ -1509,15 +1521,21 @@ class CartCore extends ObjectModel
|
|||||||
|
|
||||||
if (count($delivery_option) == 1)
|
if (count($delivery_option) == 1)
|
||||||
{
|
{
|
||||||
$delivery_option_list = $this->getDeliveryOptionList();
|
$this->id_carrier = $this->getIdCarrierFromDeliveryOption($delivery_option);
|
||||||
foreach ($delivery_option as $key => $value)
|
|
||||||
if (isset($delivery_option_list[$key]) && isset($delivery_option_list[$key][$value]))
|
|
||||||
if (count($delivery_option_list[$key][$value]['carrier_list']) == 1)
|
|
||||||
$this->id_carrier = $delivery_option_list[$key][$value]['carrier_list'][0];
|
|
||||||
$this->delivery_option = serialize($delivery_option);
|
$this->delivery_option = serialize($delivery_option);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function getIdCarrierFromDeliveryOption($delivery_option)
|
||||||
|
{
|
||||||
|
$delivery_option_list = $this->getDeliveryOptionList();
|
||||||
|
foreach ($delivery_option as $key => $value)
|
||||||
|
if (isset($delivery_option_list[$key]) && isset($delivery_option_list[$key][$value]))
|
||||||
|
if (count($delivery_option_list[$key][$value]['carrier_list']) == 1)
|
||||||
|
return $delivery_option_list[$key][$value]['carrier_list'][0];
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the delivery option seleted, or if no delivery option was selected, the cheapest option for each address
|
* Get the delivery option seleted, or if no delivery option was selected, the cheapest option for each address
|
||||||
* @return array delivery option
|
* @return array delivery option
|
||||||
|
|||||||
@@ -274,7 +274,7 @@ class AuthControllerCore extends FrontController
|
|||||||
if (Configuration::get('PS_CART_FOLLOWING') && (empty($this->context->cookie->id_cart) || Cart::getNbProducts($this->context->cookie->id_cart) == 0))
|
if (Configuration::get('PS_CART_FOLLOWING') && (empty($this->context->cookie->id_cart) || Cart::getNbProducts($this->context->cookie->id_cart) == 0))
|
||||||
$this->context->cookie->id_cart = (int)Cart::lastNoneOrderedCart($this->context->customer->id);
|
$this->context->cookie->id_cart = (int)Cart::lastNoneOrderedCart($this->context->customer->id);
|
||||||
// Update cart address
|
// Update cart address
|
||||||
$this->context->cart->delivery_option = '';
|
$this->context->cart->setDeliveryOption(null);
|
||||||
$this->context->cart->id_address_delivery = Address::getFirstCustomerAddressId((int)($customer->id));
|
$this->context->cart->id_address_delivery = Address::getFirstCustomerAddressId((int)($customer->id));
|
||||||
$this->context->cart->id_address_invoice = Address::getFirstCustomerAddressId((int)($customer->id));
|
$this->context->cart->id_address_invoice = Address::getFirstCustomerAddressId((int)($customer->id));
|
||||||
$this->context->cart->update();
|
$this->context->cart->update();
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ class CartControllerCore extends FrontController
|
|||||||
{
|
{
|
||||||
if (!Cart::getNbProducts((int)($this->context->cart->id)))
|
if (!Cart::getNbProducts((int)($this->context->cart->id)))
|
||||||
{
|
{
|
||||||
$this->context->cart->delivery_option = '';
|
$this->context->cart->setDeliveryOption(null);
|
||||||
$this->context->cart->gift = 0;
|
$this->context->cart->gift = 0;
|
||||||
$this->context->cart->gift_message = '';
|
$this->context->cart->gift_message = '';
|
||||||
$this->context->cart->update();
|
$this->context->cart->update();
|
||||||
@@ -249,7 +249,7 @@ class CartControllerCore extends FrontController
|
|||||||
$id_country = (isset($deliveryAddress) && $deliveryAddress->id) ? $deliveryAddress->id_country : Configuration::get('PS_COUNTRY_DEFAULT');
|
$id_country = (isset($deliveryAddress) && $deliveryAddress->id) ? $deliveryAddress->id_country : Configuration::get('PS_COUNTRY_DEFAULT');
|
||||||
$result['carriers'] = Carrier::getCarriersForOrder(Country::getIdZone($id_country), $groups);
|
$result['carriers'] = Carrier::getCarriersForOrder(Country::getIdZone($id_country), $groups);
|
||||||
//$result['checked'] = Carrier::getDefaultCarrierSelection($result['carriers'], (int)$this->cart->id_carrier);
|
//$result['checked'] = Carrier::getDefaultCarrierSelection($result['carriers'], (int)$this->cart->id_carrier);
|
||||||
$result['HOOK_EXTRACARRIER'] = Module::hookExec('extraCarrier', array('address' => (isset($deliveryAddress) && (int)$deliveryAddress->id) ? $deliveryAddress : null));
|
$result['HOOK_EXTRACARRIER'] = Hook::exec('extraCarrier', array('address' => (isset($deliveryAddress) && (int)$deliveryAddress->id) ? $deliveryAddress : null));
|
||||||
}
|
}
|
||||||
$result['summary'] = $this->context->cart->getSummaryDetails();
|
$result['summary'] = $this->context->cart->getSummaryDetails();
|
||||||
$result['customizedDatas'] = Product::getAllCustomizedDatas($this->context->cart->id, null, true);
|
$result['customizedDatas'] = Product::getAllCustomizedDatas($this->context->cart->id, null, true);
|
||||||
|
|||||||
@@ -218,7 +218,7 @@ class ParentOrderControllerCore extends FrontController
|
|||||||
$id_zone = Country::getIdZone((int)Configuration::get('PS_COUNTRY_DEFAULT'));
|
$id_zone = Country::getIdZone((int)Configuration::get('PS_COUNTRY_DEFAULT'));
|
||||||
|
|
||||||
if (Tools::getIsset('delivery_option') && $this->validateDeliveryOption(Tools::getValue('delivery_option')))
|
if (Tools::getIsset('delivery_option') && $this->validateDeliveryOption(Tools::getValue('delivery_option')))
|
||||||
$this->context->cart->delivery_option = serialize(Tools::getValue('delivery_option'));
|
$this->context->cart->setDeliveryOption(Tools::getValue('delivery_option'));
|
||||||
|
|
||||||
Hook::exec('processCarrier', array('cart' => $this->context->cart));
|
Hook::exec('processCarrier', array('cart' => $this->context->cart));
|
||||||
|
|
||||||
@@ -435,7 +435,7 @@ class ParentOrderControllerCore extends FrontController
|
|||||||
*/
|
*/
|
||||||
protected function setNoCarrier()
|
protected function setNoCarrier()
|
||||||
{
|
{
|
||||||
$this->context->cart->delivery_option = 0;
|
$this->context->cart->setDeliveryOption(null);
|
||||||
$this->context->cart->update();
|
$this->context->cart->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -445,6 +445,9 @@ class ParentOrderControllerCore extends FrontController
|
|||||||
* @todo this function must be modified - id_carrier is now delivery_option
|
* @todo this function must be modified - id_carrier is now delivery_option
|
||||||
*
|
*
|
||||||
* @param array $carriers
|
* @param array $carriers
|
||||||
|
*
|
||||||
|
* @deprecated since 1.5.0
|
||||||
|
*
|
||||||
* @return number the id of the default carrier
|
* @return number the id of the default carrier
|
||||||
*/
|
*/
|
||||||
protected function setDefaultCarrierSelection($carriers)
|
protected function setDefaultCarrierSelection($carriers)
|
||||||
@@ -467,7 +470,7 @@ class ParentOrderControllerCore extends FrontController
|
|||||||
$this->context->cart->id_carrier = (int)$carriers[0]['id_carrier'];
|
$this->context->cart->id_carrier = (int)$carriers[0]['id_carrier'];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
$this->context->cart->id_carrier = 0;
|
$this->context->cart->setDeliveryOption(null);
|
||||||
if ($this->context->cart->update())
|
if ($this->context->cart->update())
|
||||||
return $this->context->cart->id_carrier;
|
return $this->context->cart->id_carrier;
|
||||||
return 0;
|
return 0;
|
||||||
@@ -477,6 +480,9 @@ class ParentOrderControllerCore extends FrontController
|
|||||||
* Decides what the default carrier is and update the cart with it
|
* Decides what the default carrier is and update the cart with it
|
||||||
*
|
*
|
||||||
* @param array $carriers
|
* @param array $carriers
|
||||||
|
*
|
||||||
|
* @deprecated since 1.5.0
|
||||||
|
*
|
||||||
* @return number the id of the default carrier
|
* @return number the id of the default carrier
|
||||||
*/
|
*/
|
||||||
protected function _setDefaultCarrierSelection($carriers)
|
protected function _setDefaultCarrierSelection($carriers)
|
||||||
|
|||||||
Reference in New Issue
Block a user