// Autoset id_carrier on the cart constructor + Replace a hookExec()

This commit is contained in:
mDeflotte
2011-11-22 14:09:52 +00:00
parent 927b869601
commit 95a749de8b
4 changed files with 35 additions and 11 deletions
+23 -5
View File
@@ -167,6 +167,18 @@ class CartCore extends ObjectModel
}
else
$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)
@@ -1509,15 +1521,21 @@ class CartCore extends ObjectModel
if (count($delivery_option) == 1)
{
$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)
$this->id_carrier = $delivery_option_list[$key][$value]['carrier_list'][0];
$this->id_carrier = $this->getIdCarrierFromDeliveryOption($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
* @return array delivery option
+1 -1
View File
@@ -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))
$this->context->cookie->id_cart = (int)Cart::lastNoneOrderedCart($this->context->customer->id);
// 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_invoice = Address::getFirstCustomerAddressId((int)($customer->id));
$this->context->cart->update();
+2 -2
View File
@@ -104,7 +104,7 @@ class CartControllerCore extends FrontController
{
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_message = '';
$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');
$result['carriers'] = Carrier::getCarriersForOrder(Country::getIdZone($id_country), $groups);
//$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['customizedDatas'] = Product::getAllCustomizedDatas($this->context->cart->id, null, true);
+9 -3
View File
@@ -218,7 +218,7 @@ class ParentOrderControllerCore extends FrontController
$id_zone = Country::getIdZone((int)Configuration::get('PS_COUNTRY_DEFAULT'));
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));
@@ -435,7 +435,7 @@ class ParentOrderControllerCore extends FrontController
*/
protected function setNoCarrier()
{
$this->context->cart->delivery_option = 0;
$this->context->cart->setDeliveryOption(null);
$this->context->cart->update();
}
@@ -445,6 +445,9 @@ class ParentOrderControllerCore extends FrontController
* @todo this function must be modified - id_carrier is now delivery_option
*
* @param array $carriers
*
* @deprecated since 1.5.0
*
* @return number the id of the default carrier
*/
protected function setDefaultCarrierSelection($carriers)
@@ -467,7 +470,7 @@ class ParentOrderControllerCore extends FrontController
$this->context->cart->id_carrier = (int)$carriers[0]['id_carrier'];
}
else
$this->context->cart->id_carrier = 0;
$this->context->cart->setDeliveryOption(null);
if ($this->context->cart->update())
return $this->context->cart->id_carrier;
return 0;
@@ -477,6 +480,9 @@ class ParentOrderControllerCore extends FrontController
* Decides what the default carrier is and update the cart with it
*
* @param array $carriers
*
* @deprecated since 1.5.0
*
* @return number the id of the default carrier
*/
protected function _setDefaultCarrierSelection($carriers)