Skip to content

Commit

Permalink
Merge pull request #8435 from LittleBigDev/BOOM-2989
Browse files Browse the repository at this point in the history
Fixed bug where invalid address message is displayed only for billing address even if both are invalid
  • Loading branch information
Quetzacoalt91 committed Nov 2, 2017
2 parents 62b6ff2 + 62b9720 commit aeba453
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 46 deletions.
4 changes: 4 additions & 0 deletions classes/checkout/AbstractCheckoutStep.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ abstract class AbstractCheckoutStepCore implements CheckoutStepInterface
{
private $smarty;
private $translator;

/**
* @var CheckoutProcess
*/
private $checkoutProcess;

private $title;
Expand Down
122 changes: 83 additions & 39 deletions classes/checkout/CheckoutAddressesStep.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,26 @@ public function handleRequest(array $requestParams = array())
Tools::getToken(true, $this->context)
);

if ($addressPersister->delete(new Address((int) Tools::getValue('id_address'), $this->context->language->id), Tools::getValue('token'))) {
$this->context->controller->success[] = $this->getTranslator()->trans('Address successfully deleted!', array(), 'Shop.Notifications.Success');
$deletionResult = (bool)$addressPersister->delete(
new Address((int) Tools::getValue('id_address'), $this->context->language->id),
Tools::getValue('token')
);
if ($deletionResult) {
$this->context->controller->success[] = $this->getTranslator()->trans(
'Address successfully deleted!',
array(),
'Shop.Notifications.Success'
);
$this->context->controller->redirectWithNotifications(
$this->getCheckoutSession()->getCheckoutURL()
);
} else {
$this->getCheckoutProcess()->setHasErrors(true);
$this->context->controller->errors[] = $this->getTranslator()->trans('Could not delete address.', array(), 'Shop.Notifications.Error');
$this->context->controller->errors[] = $this->getTranslator()->trans(
'Could not delete address.',
array(),
'Shop.Notifications.Error'
);
}
}

Expand Down Expand Up @@ -202,51 +214,83 @@ public function handleRequest(array $requestParams = array())

public function getTemplateParameters()
{
$idAddressDelivery = (int) $this->getCheckoutSession()->getIdAddressDelivery();
$idAddressInvoice = (int) $this->getCheckoutSession()->getIdAddressInvoice();
$addressWarning = false;
$errorKey = 'address_error';
$checkoutWarning = isset($this->context->controller->checkoutWarning['address'])
? $this->context->controller->checkoutWarning['address']
: false;
$invalidAddresses = isset($this->context->controller->checkoutWarning['invalid_addresses'])
? $this->context->controller->checkoutWarning['invalid_addresses']
: array();

if (!empty($checkoutWarning)) {
if ($idAddressDelivery === (int)$checkoutWarning['id_address']) {
$addressWarning = $checkoutWarning;
$errorKey = 'delivery_address_error';
} elseif ($idAddressInvoice === (int)$checkoutWarning['id_address']) {
$addressWarning = $checkoutWarning;
$errorKey = 'invoice_address_error';
$idAddressDelivery = (int)$this->getCheckoutSession()->getIdAddressDelivery();
$idAddressInvoice = (int)$this->getCheckoutSession()->getIdAddressInvoice();
$params = array(
'address_form' => $this->addressForm->getProxy(),
'use_same_address' => $this->use_same_address,
'use_different_address_url' => $this->context->link->getPageLink(
'order',
true,
null,
array('use_same_address' => 0)
),
'new_address_delivery_url' => $this->context->link->getPageLink(
'order',
true,
null,
array('newAddress' => 'delivery')
),
'new_address_invoice_url' => $this->context->link->getPageLink(
'order',
true,
null,
array('newAddress' => 'invoice')
),
'id_address_delivery' => $idAddressDelivery,
'id_address_invoice' => $idAddressInvoice,
'show_delivery_address_form' => $this->show_delivery_address_form,
'show_invoice_address_form' => $this->show_invoice_address_form,
'form_has_continue_button' => $this->form_has_continue_button,
);

/** @var OrderControllerCore $controller */
$controller = $this->context->controller;
if (isset($controller)) {
$warnings = $controller->checkoutWarning;
$addressWarning = isset($warnings['address'])
? $warnings['address']
: false;
$invalidAddresses = isset($warnings['invalid_addresses'])
? $warnings['invalid_addresses']
: array();

$errors = array();
if (in_array($idAddressDelivery, $invalidAddresses)) {
$errors['delivery_address_error'] = $addressWarning;
}

if (in_array($idAddressInvoice, $invalidAddresses)) {
$errors['invoice_address_error'] = $addressWarning;
}

if ($this->show_invoice_address_form
|| $idAddressInvoice != $idAddressDelivery
|| !empty($errors['invoice_address_error'])
) {
$this->use_same_address = false;
}
}

if ($this->use_same_address && ($idAddressInvoice != $idAddressDelivery || $this->show_invoice_address_form)) {
$this->use_same_address = false;
// Add specific parameters
$params = array_replace(
$params,
array(
'not_valid_addresses' => implode(",", $invalidAddresses),
'use_same_address' => $this->use_same_address,
),
$errors
);
}
return array(
'address_form' => $this->addressForm->getProxy(),
'use_same_address' => $this->use_same_address,
'use_different_address_url' => $this->context->link->getPageLink('order', true, null, array('use_same_address' => 0)),
'new_address_delivery_url' => $this->context->link->getPageLink('order', true, null, array('newAddress' => 'delivery')),
'new_address_invoice_url' => $this->context->link->getPageLink('order', true, null, array('newAddress' => 'invoice')),
'id_address_delivery' => $idAddressDelivery,
'id_address_invoice' => $idAddressInvoice,
'show_delivery_address_form' => $this->show_delivery_address_form,
'show_invoice_address_form' => $this->show_invoice_address_form,
'form_has_continue_button' => $this->form_has_continue_button,
$errorKey => $addressWarning,
'not_valid_addesses' => implode(",", $invalidAddresses),
);

return $params;
}

public function render(array $extraParams = array())
{
return $this->renderTemplate(
$this->getTemplate(), $extraParams, $this->getTemplateParameters()
$this->getTemplate(),
$extraParams,
$this->getTemplateParameters()
);
}
}
4 changes: 4 additions & 0 deletions classes/checkout/CheckoutProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
class CheckoutProcessCore implements RenderableInterface
{
private $smarty;

/**
* @var CheckoutSession
*/
private $checkoutSession;
private $steps = array();
private $has_errors;
Expand Down
10 changes: 7 additions & 3 deletions controllers/front/OrderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ class OrderControllerCore extends FrontController
public $page_name = 'checkout';
public $checkoutWarning = false;

/**
* @var CheckoutProcess
*/
protected $checkoutProcess;

/**
* @var CartChecksum
*/
Expand Down Expand Up @@ -300,6 +304,7 @@ public function displayAjaxAddressForm()
$addressForm->fillWith(array('id_country' => Tools::getValue('id_country')));
}

$stepTemplateParameters = array();
foreach ($this->checkoutProcess->getSteps() as $step) {
if ($step instanceof CheckoutAddressesStep) {
$stepTemplateParameters = $step->getTemplateParameters();
Expand All @@ -309,9 +314,8 @@ public function displayAjaxAddressForm()
$templateParams = array_merge(
$addressForm->getTemplateVariables(),
$stepTemplateParameters,
array(
'type' => 'delivery',
));
array('type' => 'delivery')
);

ob_end_clean();
header('Content-Type: application/json');
Expand Down
3 changes: 2 additions & 1 deletion themes/_core/js/checkout-address.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ $(window).load(() => {
switchEditAddressButtonColor(true, idFailureAddress, $(this).attr('name').split('-').pop());
});
}
$visibleAddressError = $('.js-address-error:visible'); // Refresh after possible hide
switchConfirmAddressesButtonState($visibleAddressError.length <= 0);
});

Expand All @@ -105,5 +106,5 @@ const switchEditAddressButtonColor = function switchEditAddressButtonColor(enabl
* Enable/disable the continue address button
*/
const switchConfirmAddressesButtonState = function switchConfirmAddressesButtonState(enable) {
$('button[name=confirm-addresses]').prop("disabled", enable ? "" : "disabled");
$('button[name=confirm-addresses]').prop("disabled", !enable);
};
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
<button type="submit" class="btn btn-primary continue float-xs-right" name="confirm-addresses" value="1">
{l s='Continue' d='Shop.Theme.Actions'}
</button>
<input type="hidden" id="not-valid-addresses" value="{$not_valid_addesses}">
<input type="hidden" id="not-valid-addresses" value="{$not_valid_addresses}">
</div>
{/if}

Expand Down
3 changes: 2 additions & 1 deletion themes/core.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion themes/core.js.map

Large diffs are not rendered by default.

0 comments on commit aeba453

Please sign in to comment.