Skip to content

Commit

Permalink
Merge branch 'main' of github.com:Invertus/dpdbaltics17 into hide-lab…
Browse files Browse the repository at this point in the history
…el-print-feature
  • Loading branch information
GytisZum committed Dec 11, 2023
2 parents 4a0c404 + b48590a commit 0c3f384
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 16 deletions.
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,14 @@

## [3.2.15]
- Added possibility to change carrier for shipment from BO Order page before printing label even if Carrier is inactive in module.

## [3.2.16]
- Shipping tab improvements.
- Improved PUDO orders with incorrect post code.
- Fixed BO bug then changing terminal.
- Improved module code base.

## [3.2.16]
- Improved performance
- Added additional validation

## [3.2.17]
- Label printing after changing shipment product bug fix
2 changes: 1 addition & 1 deletion dpdbaltics.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function __construct()
$this->author = 'Invertus';
$this->tab = 'shipping_logistics';
$this->description = 'DPD Baltics shipping integration';
$this->version = '3.2.16';
$this->version = '3.2.17';
$this->ps_versions_compliancy = ['min' => '1.7.1.0', 'max' => _PS_VERSION_];
$this->need_instance = 0;
parent::__construct();
Expand Down
2 changes: 1 addition & 1 deletion src/Entity/DPDPriceRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ public function isApplicableByAddress(Address $address)
$module = Module::getInstanceByName('dpdbaltics');

/** @var ZoneRepository $zoneRepo */
$zoneRepo = $module->getModuleContainer()->get('invertus.dpdbaltics.repository.dpdzone_repository');
$zoneRepo = $module->getModuleContainer()->get('invertus.dpdbaltics.repository.zone_repository');

return $zoneRepo->findZoneInRangeByAddress($address);
}
Expand Down
1 change: 1 addition & 0 deletions src/Factory/ShipmentDataFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ public function getShipmentDataByIdOrder($orderId)
$shipmentData->setDpdCountry($dpdPudo->country_code);
$shipmentData->setSelectedPudoIsoCode($dpdPudo->country_code);
$shipmentData->setDpdZipCode($address->postcode);
$shipmentData->setDpdStreet($dpdPudo->street);
$shipmentData->setSelectedPudoId($dpdPudo->pudo_id);
}

Expand Down
4 changes: 3 additions & 1 deletion src/Service/API/ShipmentApiService.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ public function __construct(
public function createShipment($addressId, ShipmentData $shipmentData, $orderId)
{
$address = new Address($addressId);
$isCompany = $shipmentData->getCompany() ? true : false;

$isCompany = trim($shipmentData->getCompany()) ? true : false;
$firstName = $shipmentData->getName();
if ($isCompany) {
$firstName = $shipmentData->getCompany();
Expand All @@ -107,6 +108,7 @@ public function createShipment($addressId, ShipmentData $shipmentData, $orderId)
$parcel = $this->parcelShopService->getParcelShopByShopId($shipmentData->getSelectedPudoId());
$selectedParcel = is_array($parcel) ? reset($parcel) : $parcel;
$postCode = $selectedParcel->getPCode();
$address->address1 = $selectedParcel->getStreet();
}

// IF prestashop allows, we take selected parcel terminal address in case information is missing in checkout address in specific cases.
Expand Down
22 changes: 21 additions & 1 deletion src/Service/PriceRuleService.php
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,12 @@ public function applyPriceRuleForCarrier(Cart $cart, $priceRulesIds, $shopId)
{
$availablePriceRules = $this->priceRuleRepository->findAllAvailableInShop($shopId);

if (!$availablePriceRules) {
return false;
}

foreach ($priceRulesIds as $priceRuleId) {
if (!in_array($priceRuleId, $availablePriceRules)) {
if (!$this->ensureCarrierHasPriceRule($priceRuleId, $availablePriceRules)) {
return false;
}

Expand Down Expand Up @@ -429,4 +433,20 @@ private function duplicatePriceRuleTablesData($tables, $priceRuleTablesData, $ne

return true;
}

/**
* @param string $priceRuleId
* @param array|false $availablePriceRules
* @return bool
*/
private function ensureCarrierHasPriceRule($priceRuleId, $availablePriceRules)
{
foreach ($availablePriceRules as $rule) {
if (isset($rule['id_dpd_price_rule']) && (int) $rule['id_dpd_price_rule'] === (int) $priceRuleId) {
return true;
}
}

return false;
}
}
3 changes: 2 additions & 1 deletion src/Service/PudoService.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ public function searchPudoServices($city, $carrierId, $cartId)
];
}

public function savePudoOrder($productId, $pudoId, $isoCode, $cartId, $city, $street)
public function savePudoOrder($productId, $pudoId, $isoCode, $cartId, $city, $street, $zipCode)
{
$pudoOrderId = $this->pudoRepository->getIdByCart($cartId);
$product = new DPDProduct($productId);
Expand All @@ -254,6 +254,7 @@ public function savePudoOrder($productId, $pudoId, $isoCode, $cartId, $city, $st
$pudoOrder->id_cart = $cartId;
$pudoOrder->city = $city;
$pudoOrder->street = $street;
$pudoOrder->post_code = $zipCode;
$pudoOrder->save();
}

Expand Down
3 changes: 2 additions & 1 deletion src/Service/ShipmentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -415,9 +415,10 @@ public function saveShipment(Order $order, ShipmentData $shipmentData, $print =
$isoCode = $shipmentData->getSelectedPudoIsoCode();
$city = $shipmentData->getCity();
$street = $shipmentData->getDpdStreet();
$zipCode = $shipmentData->getDpdZipCode();

try {
$this->pudoService->savePudoOrder($productId, $pudoId, $isoCode, $cartId, $city, $street);
$this->pudoService->savePudoOrder($productId, $pudoId, $isoCode, $cartId, $city, $street, $zipCode);
} catch (Exception $e) {
$response['message'] = $this->module->l(
sprintf('Failed to save pudo order to database Error: %s', $e->getMessage(). 'ID cart: '. $order->id_cart)
Expand Down
2 changes: 1 addition & 1 deletion upgrade/Upgrade-3.2.16.php → upgrade/Upgrade-3.2.15.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* @throws PrestaShopDatabaseException
* @throws PrestaShopException
*/
function upgrade_module_3_2_16(DPDBaltics $module)
function upgrade_module_3_2_15(DPDBaltics $module)
{
$result = true;

Expand Down
16 changes: 9 additions & 7 deletions views/templates/hook/admin/partials/pudo-info.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,34 @@
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*}
<div class="col-lg-12 pudo-info-container">
<input class="hidden d-none form-control" name="selected-pudo-id" value="{$selectedPudo->getParcelShopId()}">
<input class="hidden d-none form-control" name="selected_pudo_iso_code" value="{$selectedPudo->getCountry()}">
<input class="hidden d-none form-control" name="selected-pudo-id" value="{$selectedPudo->getParcelShopId()|escape:'htmlall':'UTF-8'}">
<input class="hidden d-none form-control" name="selected_pudo_iso_code" value="{$selectedPudo->getCountry()|escape:'htmlall':'UTF-8'}">
<div class="card-body">
<div class="form-horizontal form-group">
<div class="form-row row dpd-form-group">
<label class="control-label col-lg-3 dpd-no-padding">{l s='Address: ' mod='dpdbaltics'}</label>
<div class="address col-lg-9">
{$selectedPudo->getStreet()}
{$selectedPudo->getStreet()|escape:'htmlall':'UTF-8'}
</div>
<input name="dpd-street" type="hidden" value="{$selectedPudo->getStreet()|escape:'htmlall':'UTF-8'}">
</div>
<div class="form-row row dpd-form-group">
<label class="control-label col-lg-3 dpd-no-padding">{l s='Post code: ' mod='dpdbaltics'}</label>
<div class="zip-code col-lg-9">
{$selectedPudo->getPCode()}
{$selectedPudo->getPCode()|escape:'htmlall':'UTF-8'}
</div>
<input name="dpd-zip-code" type="hidden" value="{$selectedPudo->getPCode()|escape:'htmlall':'UTF-8'}">
</div>
<div class="form-row row dpd-form-group">
<label class="control-label col-lg-3 dpd-no-padding">{l s='City: ' mod='dpdbaltics'}</label>
<div class="city col-lg-9">
{$selectedPudo->getCity()}
{$selectedPudo->getCity()|escape:'htmlall':'UTF-8'}
</div>
</div>
<div class="form-row row dpd-form-group">
<label class="control-label col-lg-3 dpd-no-padding ">{l s='Country: ' mod='dpdbaltics'}</label>
<div class="country col-lg-9">
{$selectedPudo->getCountry()}
{$selectedPudo->getCountry()|escape:'htmlall':'UTF-8'}
</div>
</div>
<div class="form-row row dpd-form-group">
Expand All @@ -59,7 +61,7 @@
<ul class="work-hours d-none hidden">
{l s='Working hours:' mod='dpdbaltics'}
{foreach $selectedPudo->getOpeningHours() as $workHours}
<li>{$workHours->getWorkHoursFormatted()}</li>
<li>{$workHours->getWorkHoursFormatted()|escape:'htmlall':'UTF-8'}</li>
{/foreach}
</ul>
</div>
Expand Down

0 comments on commit 0c3f384

Please sign in to comment.