Skip to content
Permalink
Browse files

Improved carrier error handling.

Added error propagation to frontend and they are now converted to
text representations, both for ajax on the checkout page and
checkout page load.

Related to #963.
  • Loading branch information...
Karlo Šimunović authored and Traumflug committed Jul 27, 2019
1 parent fc1c228 commit 819c09d7ae2e3ac81c48817d51b89b64b16439d4
Showing with 29 additions and 2 deletions.
  1. +25 −0 classes/Cart.php
  2. +2 −0 controllers/front/ParentOrderController.php
  3. +1 −1 themes/community-theme-default
  4. +1 −1 themes/niara
@@ -4108,6 +4108,7 @@ public function getSummaryDetails($idLang = null, $refresh = false)
}
}
$errors = [];
$summary = [
'delivery' => $delivery,
'delivery_state' => State::getNameById($delivery->id_state),
@@ -4132,8 +4133,32 @@ public function getSummaryDetails($idLang = null, $refresh = false)
'is_multi_address_delivery' => $this->isMultiAddressDelivery() || ((int) Tools::getValue('multi-shipping') == 1),
'free_ship' => !$totalShipping && !count($this->getDeliveryAddressesWithoutCarriers(true, $errors)),
'carrier' => new Carrier($this->id_carrier, $idLang),
'errors' => [],
];
if (count($errors)) {
$flagErrorMessage = false;
foreach ($errors as $error) {
if ($error == Carrier::SHIPPING_WEIGHT_EXCEPTION && !$flagErrorMessage) {
$summary['errors'][] = sprintf(Tools::displayError('The product selection cannot be delivered by the available carrier(s): it is too heavy. Please amend your cart to lower its weight.', !Tools::getValue('ajax')));
$flagErrorMessage = true;
} elseif ($error == Carrier::SHIPPING_PRICE_EXCEPTION && !$flagErrorMessage) {
$summary['errors'][] = sprintf(Tools::displayError('The product selection cannot be delivered by the available carrier(s). Please amend your cart.', !Tools::getValue('ajax')));
$flagErrorMessage = true;
} elseif ($error == Carrier::SHIPPING_SIZE_EXCEPTION && !$flagErrorMessage) {
$summary['errors'][] = sprintf(Tools::displayError('The product selection cannot be delivered by the available carrier(s): its size does not fit. Please amend your cart to reduce its size.', !Tools::getValue('ajax')));
$flagErrorMessage = true;
}
}
if (count($errors) > 1 && !$flagErrorMessage) {
$summary['errors'][] = sprintf(Tools::displayError('There are no carriers that deliver to some addresses you selected.', !Tools::getValue('ajax')));
} elseif ($this->isMultiAddressDelivery() && !$flagErrorMessage) {
$summary['errors'][] = sprintf(Tools::displayError('There are no carriers that deliver to one of the address you selected.', !Tools::getValue('ajax')));
} elseif (!$flagErrorMessage) {
$summary['errors'][] = sprintf(Tools::displayError('There are no carriers that deliver to the address you selected.', !Tools::getValue('ajax')));
}
}
$hook = Hook::exec('actionCartSummary', $summary, null, true);
if (is_array($hook)) {
$summary = array_merge($summary, array_shift($hook));
@@ -339,6 +339,8 @@ protected function validateDeliveryOption($deliveryOption)
protected function _assignSummaryInformations()
{
$summary = $this->context->cart->getSummaryDetails();
$this->errors = array_merge($this->errors, $summary['errors']);
$customizedDatas = Product::getAllCustomizedDatas($this->context->cart->id);
// override customization tax rate with real tax (tax rules)

0 comments on commit 819c09d

Please sign in to comment.
You can’t perform that action at this time.