Skip to content

Commit

Permalink
initial opc compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
GytisZum committed Mar 7, 2024
1 parent 220eb4e commit d8f0ffc
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 17 deletions.
38 changes: 21 additions & 17 deletions dpdbaltics.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public function getModuleContainer($id = false)
public function hookActionFrontControllerSetMedia()
{
//TODO fillup this array when more modules are compatible with OPC
$onePageCheckoutControllers = ['supercheckout'];
$onePageCheckoutControllers = ['supercheckout', 'onepagecheckoutps'];
$applicableControlelrs = ['order', 'order-opc', 'ShipmentReturn', 'supercheckout'];
$currentController = !empty($this->context->controller->php_self) ? $this->context->controller->php_self : Tools::getValue('controller');

Expand All @@ -183,7 +183,9 @@ public function hookActionFrontControllerSetMedia()
);
}

if (in_array($currentController, $onePageCheckoutControllers, true)) {
//todo for onepagecheckoutps module these are needed to be included as it handles phone number
// onepageps module controller is like in normal prestashop OrderController and some test are needed with normal flow
// if (in_array($currentController, $onePageCheckoutControllers, true)) {
$this->context->controller->addJqueryPlugin('chosen');

$this->context->controller->registerJavascript(
Expand All @@ -204,7 +206,7 @@ public function hookActionFrontControllerSetMedia()
]
);

}
// }

/** @var \Invertus\dpdBaltics\Provider\CurrentCountryProvider $currentCountryProvider */
$currentCountryProvider = $this->getModuleContainer('invertus.dpdbaltics.provider.current_country_provider');
Expand Down Expand Up @@ -348,21 +350,23 @@ public function hookActionValidateStepComplete(&$params)
return;
}
}
if (!Tools::getValue('dpd-phone')) {
$this->context->controller->errors[] =
$this->l('In order to use DPD Carrier you need to enter phone number');
$params['completed'] = false;

return;
}

if (!Tools::getValue('dpd-phone-area')) {
$this->context->controller->errors[] =
$this->l('In order to use DPD Carrier you need to enter phone area');
$params['completed'] = false;

return;
}
// todo thecheckout module triggers this hook when submiting the payment form
// if (!Tools::getValue('dpd-phone')) {
// $this->context->controller->errors[] =
// $this->l('In order to use DPD Carrier you need to enter phone number');
// $params['completed'] = false;
//
// return;
// }
//
// if (!Tools::getValue('dpd-phone-area')) {
// $this->context->controller->errors[] =
// $this->l('In order to use DPD Carrier you need to enter phone area');
// $params['completed'] = false;
//
// return;
// }

/** @var CarrierPhoneService $carrierPhoneService */
$carrierPhoneService = $this->getModuleContainer()->get('invertus.dpdbaltics.service.carrier_phone_service');
Expand Down
18 changes: 18 additions & 0 deletions views/js/front/order-opc.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ $(document).ready(function (){
handlePhoneNumber($(this));
});

// todo need event listener to trigger the checkout form and handle phone number
$('body').on('click', '#confirm_order', function(e) {
e.preventDefault();

if ($('.dpd-phone-block') !== undefined) {
if(!handlePhoneNumber($('.dpd-phone-block'))) {
return;
}
}

});

$(document).on('click','.payment_module a', function (e){
e.preventDefault();

Expand Down Expand Up @@ -82,3 +94,9 @@ function DPDdisplayMessageOpc(parent, template) {
var $messageContainer = parent.find('.dpd-message-container');
$messageContainer.html(template);
}

// Module "onepagecheckoutps" compatibility
$(document).on('opc-load-review:completed', function() {
$('.delivery-option.selected .carrier-extra-content').show();
});

0 comments on commit d8f0ffc

Please sign in to comment.