Skip to content

Commit

Permalink
opc improvements and added some styles
Browse files Browse the repository at this point in the history
  • Loading branch information
GytisZum committed Jul 3, 2024
1 parent 0ef1f07 commit 3d49649
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 6 deletions.
1 change: 1 addition & 0 deletions config/service.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ services:
- '@invertus.dpdbaltics.orm.entity_manager'
- '@invertus.dpdbaltics.repository.phone_prefix_repository'
- '@invertus.dpdbaltics.repository.order_repository'
- '@invertus.dpdbaltics.validator.opc_module_compatibility_validator'

invertus.dpdbaltics.service.carrier.update_carrier_service:
class: 'Invertus\dpdBaltics\Service\Carrier\UpdateCarrierService'
Expand Down
3 changes: 3 additions & 0 deletions config/validator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,6 @@ services:
arguments:
- '@dpdbaltics'
- '@invertus.dpdbaltics.repository.phone_repository'

invertus.dpdbaltics.validator.opc_module_compatibility_validator:
class: 'Invertus\dpdBaltics\Validate\Compatibility\OpcModuleCompatibilityValidator'
14 changes: 13 additions & 1 deletion dpdbaltics.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,10 @@ public function hookActionFrontControllerSetMedia()
);
}

if (in_array($currentController, $onePageCheckoutControllers, true) || Tools::getValue('module') === 'thecheckout') {
/** @var \Invertus\dpdBaltics\Validate\Compatibility\OpcModuleCompatibilityValidator $opcModuleCompatibilityValidator */
$opcModuleCompatibilityValidator = $this->getModuleContainer('invertus.dpdbaltics.validator.opc_module_compatibility_validator');

if (in_array($currentController, $onePageCheckoutControllers, true) || $opcModuleCompatibilityValidator->isOpcModuleInUse()) {
$this->context->controller->addJqueryPlugin('chosen');

$this->context->controller->registerJavascript(
Expand All @@ -202,6 +205,15 @@ public function hookActionFrontControllerSetMedia()
'priority' => 130
]
);

$this->context->controller->registerStylesheet(
'dpdbaltics-opc',
'modules/' . $this->name . '/views/css/front/onepagecheckout.css',
[
'position' => 'bottom',
'priority' => 130
]
);
}

/** @var \Invertus\dpdBaltics\Provider\CurrentCountryProvider $currentCountryProvider */
Expand Down
3 changes: 3 additions & 0 deletions src/Config/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,9 @@ class Config

const COUNTRY_ISO_CODES_WITH_MIXED_CHARACTERS = ['IE', 'GB', 'NL'];

// NOTE: Add OPC module tech name if payment option is compatible
public const DPD_OPC_MODULE_LIST = ['onepagecheckoutps', 'supercheckout', 'thecheckout'];

const PRODUCT_NAME_B2B = [
'LT' => 'Pristatymas privatiems asmenims',
'EE' => 'DPD kuller',
Expand Down
10 changes: 9 additions & 1 deletion src/Service/CarrierPhoneService.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Invertus\dpdBaltics\Repository\PhonePrefixRepository;
use Invertus\dpdBaltics\Config\Config;
use DPDOrderPhone;
use Invertus\dpdBaltics\Validate\Compatibility\OpcModuleCompatibilityValidator;

class CarrierPhoneService
{
Expand All @@ -45,19 +46,25 @@ class CarrierPhoneService
* @var OrderRepository
*/
private $orderRepository;
/**
* @var OpcModuleCompatibilityValidator
*/
private $opcModuleCompatibilityValidator;

public function __construct(
DPDBaltics $module,
Context $context,
EntityManager $entityManager,
PhonePrefixRepository $phonePrefixRepository,
OrderRepository $orderRepository
OrderRepository $orderRepository,
OpcModuleCompatibilityValidator $opcModuleCompatibilityValidator
) {
$this->module = $module;
$this->context = $context;
$this->entityManager = $entityManager;
$this->phonePrefixRepository = $phonePrefixRepository;
$this->orderRepository = $orderRepository;
$this->opcModuleCompatibilityValidator = $opcModuleCompatibilityValidator;
}

public function getCarrierPhoneTemplate($cartId, $carrierReference)
Expand Down Expand Up @@ -94,6 +101,7 @@ public function getCarrierPhoneTemplate($cartId, $carrierReference)
'dpdPhoneArea' => $phoneData['mobile_phone_code_list'],
'contextPrefix' => Config::PHONE_CODE_PREFIX . $phonePrefix,
'isAbove177' => Config::isPrestashopVersionAbove177(),
'isOpcCheckout' => $this->opcModuleCompatibilityValidator->isOpcModuleInUse(),
]
);

Expand Down
44 changes: 44 additions & 0 deletions src/Validate/Compatibility/OpcModuleCompatibilityValidator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <[email protected]>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/


namespace Invertus\dpdBaltics\Validate\Compatibility;

use DPDBaltics;
use Invertus\dpdBaltics\Config\Config;
use Invertus\dpdBaltics\Exception\DpdCarrierException;
use Invertus\dpdBaltics\Repository\PhoneRepository;
use Invertus\dpdBaltics\Util\NumberUtility;
use Invertus\dpdBaltics\Util\StringUtility;
use Module;

class OpcModuleCompatibilityValidator
{
public function isOpcModuleInUse(): bool
{
foreach (Config::DPD_OPC_MODULE_LIST as $opcModule){
if (Module::isInstalled($opcModule) && Module::isEnabled($opcModule)) {
return true;
}
}

return false;
}
}
22 changes: 22 additions & 0 deletions views/css/front/onepagecheckout.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#phone-block-wrapper {
display: flex;
flex-direction: column;
}

.points-container .list-inline .row {
margin-left: 15px;
margin-right: 15px;
}

.panel-body .points-container .dpd-services-block {
width: 100%;
}

.panel-body .points-container {
width: 340px;
margin-left: 18px;
}

.dpd-services-block .list-inline-item {
min-width: 370px;
}
8 changes: 4 additions & 4 deletions views/templates/hook/front/carrier-phone-number.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
{include file='module:dpdbaltics/views/templates/hook/front/partials/dpd-message.tpl' messageType='error'}
{/if}
<div id="phone-block-wrapper" class="row form-group">
<div class="col-lg-5 col-12 ">
<p class="form-control-label">{l s='This a phone number that will be used for deliveries' mod='dpdbaltics'}</p></div>
<div class="col-lg-3 col-4 col-sm-12 dpd-input-wrapper dpd-select-wrapper hasValue small-padding-sm-right css-dpd-phone-prefix">
<div class="{if !isOpcCheckout}col-lg-5 col-12{/if}">
<p class="form-control-label">{l s='This a phone number that will be used for deliveriessss' mod='dpdbaltics'}</p></div>
<div class="{if !isOpcCheckout}col-lg-3 col-4 col-sm-12{/if} dpd-input-wrapper dpd-select-wrapper hasValue small-padding-sm-right css-dpd-phone-prefix">
<select
class="chosen-select form-control form-control-chosen"
name="dpd-phone-area">
Expand All @@ -37,7 +37,7 @@
</div>
</div>

<div class="col-lg-4 col-8 col-sm-12 dpd-input-wrapper{if isset($dpdPhone) && $dpdPhone} hasValue{/if} small-padding-sm-left">
<div class="{if !isOpcCheckout}col-lg-4 col-8 col-sm-12{/if} dpd-input-wrapper{if isset($dpdPhone) && $dpdPhone} hasValue{/if} small-padding-sm-left">
<input name="dpd-phone" id="dpd-carrier-{$carrierReference}" type="text" class="form-control" {if isset($dpdPhone) && $dpdPhone}value="{$dpdPhone}"{/if}>
<div id="phone-input-placeholder" class="dpd-input-placeholder" for="dpd-phone">{l s='Phone' mod='dpdbaltics'}</div>
</div>
Expand Down

0 comments on commit 3d49649

Please sign in to comment.