Skip to content

Commit

Permalink
Merge pull request #9 from Invertus/main
Browse files Browse the repository at this point in the history
Merge version 3.1.5 to main
  • Loading branch information
arturas-bes authored Apr 15, 2021
2 parents 7aab860 + 1308995 commit fe219aa
Show file tree
Hide file tree
Showing 16 changed files with 358 additions and 34 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,10 @@
- Set parcels from different countries functionality added
- Bugfix when no idcart in order page to select parcel

## [3.1.5] - 2021-03-25
### Changed
- Added shipping cost to dpd shipment
- Translations added for carriers on webservice change
- Module tab install/uninstall dublication on module tab titles, all invisible titles are showing bug fixes added
- Maps loading sequence fixed

1 change: 1 addition & 0 deletions config/provider.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@ services:
- '@Invertus\dpdBaltics\Repository\ProductAvailabilityRepository'

Invertus\dpdBaltics\Provider\CurrentCountryProvider:
class: 'Invertus\dpdBaltics\Provider\CurrentCountryProvider'
arguments:
- '@context'
7 changes: 7 additions & 0 deletions config/service.yml
Original file line number Diff line number Diff line change
Expand Up @@ -236,3 +236,10 @@ services:
class: 'Invertus\dpdBaltics\Grid\Row\PrintAccessibilityChecker'
arguments:
- '@Invertus\dpdBaltics\Repository\ShipmentRepository'

Invertus\dpdBaltics\Service\Carrier\CarrierUpdateHandler:
class: 'Invertus\dpdBaltics\Service\Carrier\CarrierUpdateHandler'
arguments:
- '@Invertus\dpdBaltics\Repository\ProductRepository'
- '@Invertus\dpdBaltics\Service\Carrier\UpdateCarrierService'
- '@Invertus\dpdBaltics\Service\Product\ProductService'
5 changes: 5 additions & 0 deletions controllers/admin/AdminDPDBalticsSettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use Invertus\dpdBaltics\DTO\DPDProductInstall;
use Invertus\dpdBaltics\Repository\ProductRepository;
use Invertus\dpdBaltics\Service\Carrier\CreateCarrierService;
use Invertus\dpdBaltics\Service\Carrier\CarrierUpdateHandler;
use Invertus\dpdBaltics\Service\Carrier\UpdateCarrierService;
use Invertus\dpdBaltics\Service\LogsService;
use Invertus\dpdBaltics\Service\Product\ProductService;
use Invertus\dpdBaltics\Templating\InfoBlockRender;
Expand Down Expand Up @@ -149,10 +151,13 @@ public function postProcess()
if (Tools::isSubmit('submitOptionsconfiguration')) {
/** @var ProductService $productService */
$productService = $this->module->getModuleContainer()->get(ProductService::class);
/** @var CarrierUpdateHandler $carrierService */
$carrierService = $this->module->getModuleContainer()->get(CarrierUpdateHandler::class);

$newCountry = Tools::getValue(Config::WEB_SERVICE_COUNTRY);
Configuration::updateValue(Config::DPD_PARCEL_IMPORT_COUNTRY_SELECTOR, Country::getByIso($newCountry));
$productService->updateCarriersOnCountryChange($newCountry);
$carrierService->updateCarrierName($newCountry);
}

$parentReturn = parent::postProcess();
Expand Down
13 changes: 12 additions & 1 deletion dpdbaltics.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function __construct()
$this->displayName = $this->l('DPDBaltics');
$this->author = 'Invertus';
$this->tab = 'shipping_logistics';
$this->version = '3.1.4';
$this->version = '3.1.5';
$this->ps_versions_compliancy = ['min' => '1.7.1.0', 'max' => _PS_VERSION_];
$this->need_instance = 0;
parent::__construct();
Expand Down Expand Up @@ -663,6 +663,17 @@ public function hookActionAdminControllerSetMedia($params)
{
$currentController = Tools::getValue('controller');

if (Config::isPrestashopVersionBelow174()) {
/** @var $tabs TabService*/
$tabs = $this->getModuleContainer()->get(TabService::class);
$visibleClasses = $tabs->getTabsClassNames(false);

if (in_array($currentController, $visibleClasses, true)) {
Media::addJsDef(['visibleTabs' => $tabs->getTabsClassNames(true)]);
$this->context->controller->addJS($this->getPathUri() . 'views/js/admin/tabsHandlerBelowPs174.js');
}
}

if ('AdminOrders' === $currentController) {
$this->handleLabelPrintService();

Expand Down
5 changes: 5 additions & 0 deletions src/Builder/Template/Admin/ProductBlockBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ public function renderProducts()
}

$carrier = Carrier::getCarrierByReference($product->id_reference);

if (!$carrier) {
continue;
}

$delays = [];
foreach ($carrier->delay as $key => $item) {
$delays[Language::getIsoById($key)] = $item;
Expand Down
100 changes: 85 additions & 15 deletions src/Config/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,24 +227,85 @@ class Config
const PRODUCT_TYPE_SAME_DAY_DELIVERY = '274';
const PS_VERSION_1_7_7 = '1.7.7.0';

const PRODUCT_NAME_B2B = [
'LT' => 'Pristatymas privatiems asmenims',
'EE' => 'DPD kuller',
'LV' => 'Kurjerpiegādes Privātpersonām',
'EN' => 'DPD courier',
];

const PRODUCT_NAME_PUDO = [
'LT' => 'Pristatymas į paštomatą',
'EE' => 'DPD pakiautomaat lunamaksega',
'LV' => 'Piegādes uz Paku Skapjiem un Paku Bodēm',
'EN' => 'DPD Pickup points',
];

const PRODUCT_NAME_B2B_COD = [
'LT' => 'Atsiskaitymas pristatymo metu',
'EE' => 'DPD kuller lunamaksega',
'LV' => 'Naudas iekasēšana piegādes brīdī',
'EN' => 'Cash on Delivery',
];


const PRODUCT_NAME_PUDO_COD = [
'LT' => 'DPD Paštomatas, atsiskaitymas grynaisiais',
'EE' => 'DPD pakiautomaat lunamaksega',
'LV' => 'DPD Pickup COD',
'EN' => 'DPD Pickup COD',
];

const PRODUCT_NAME_SATURDAY_DELIVERY = [
'LT' => 'Pristatymas šeštadienį',
'EE' => 'DPD kuller laupäeval',
'LV' => 'Sestdienas piegāde',
'EN' => 'DPD Saturday',
];

const PRODUCT_NAME_SATURDAY_DELIVERY_COD = [
'LT' => 'Pristatymas Šestadienį, atsiskaitymas grynaisiais',
'EE' => 'DPD kuller laupäeval lunamaksega',
'LV' => 'Saturday Delivery COD',
'EN' => 'Saturday Delivery COD',
];

public static function getProducts()
const PRODUCT_NAME_SAME_DAY_DELIVERY = [
'LT' => 'Pristatymas tą pačią dieną',
'EE' => 'Samal päeval kohaletoimetamine',
'LV' => 'Same day Delivery',
'EN' => 'Same day Delivery',
];

public static function getProducts($webServiceCountry = 'EN')
{
$collection = new DPDProductInstallCollection();

$product = self::getProductByReference(self::PRODUCT_TYPE_B2B);
$product = self::getProductByReference(self::PRODUCT_TYPE_B2B, $webServiceCountry);
$collection->add($product);

$product = self::getProductByReference(self::PRODUCT_TYPE_PUDO, $webServiceCountry);
$collection->add($product);

$product = self::getProductByReference(self::PRODUCT_TYPE_PUDO);
$product = self::getProductByReference(self::PRODUCT_TYPE_B2B_COD, $webServiceCountry);
$collection->add($product);

$product = self::getProductByReference(self::PRODUCT_TYPE_B2B_COD);
$product = self::getProductByReference(
self::PRODUCT_TYPE_SATURDAY_DELIVERY,
$webServiceCountry
);
$collection->add($product);

$product = self::getProductByReference(self::PRODUCT_TYPE_SATURDAY_DELIVERY);
$product = self::getProductByReference(
self::PRODUCT_TYPE_PUDO_COD,
$webServiceCountry
);
$collection->add($product);

$product = self::getProductByReference(self::PRODUCT_TYPE_SATURDAY_DELIVERY_COD);
$product = self::getProductByReference(
self::PRODUCT_TYPE_SATURDAY_DELIVERY_COD,
$webServiceCountry
);
$collection->add($product);

return $collection;
Expand All @@ -259,7 +320,7 @@ public static function getPsAndModuleVersion()
{
$module = Module::getInstanceByName('dpdbaltics');

return 'PS_'._PS_VERSION_.';'. $module->version;
return 'PS_'._PS_VERSION_.'|'. $module->version;
}


Expand Down Expand Up @@ -304,12 +365,13 @@ public static function getOnBoardImportTypes()
];
}

public static function getProductByReference($productReference)
public static function getProductByReference($productReference, $countryCode = 'EN')
{

switch ($productReference) {
case self::PRODUCT_TYPE_B2B:
$product = new DPDProductInstall();
$product->setName('DPD B2C');
$product->setName(self::PRODUCT_NAME_B2B[$countryCode]);
$product->setId(self::PRODUCT_TYPE_B2B);
$product->setDelay('Your delivery experts');
$product->setIsPudo(0);
Expand All @@ -318,7 +380,7 @@ public static function getProductByReference($productReference)
break;
case self::PRODUCT_TYPE_PUDO:
$product = new DPDProductInstall();
$product->setName('DPD Pickup');
$product->setName(self::PRODUCT_NAME_PUDO[$countryCode]);
$product->setId(self::PRODUCT_TYPE_PUDO);
$product->setDelay('Your delivery experts');
$product->setIsPudo(1);
Expand All @@ -327,7 +389,7 @@ public static function getProductByReference($productReference)
break;
case self::PRODUCT_TYPE_B2B_COD:
$product = new DPDProductInstall();
$product->setName('DPD B2C COD');
$product->setName(self::PRODUCT_NAME_B2B_COD[$countryCode]);
$product->setId(self::PRODUCT_TYPE_B2B_COD);
$product->setDelay('Your delivery experts');
$product->setIsPudo(0);
Expand All @@ -336,7 +398,7 @@ public static function getProductByReference($productReference)
break;
case self::PRODUCT_TYPE_PUDO_COD:
$product = new DPDProductInstall();
$product->setName('DPD Pickup COD');
$product->setName(self::PRODUCT_NAME_PUDO_COD[$countryCode]);
$product->setId(Config::PRODUCT_TYPE_PUDO_COD);
$product->setDelay('Your delivery experts');
$product->setIsPudo(1);
Expand All @@ -345,7 +407,7 @@ public static function getProductByReference($productReference)
break;
case self::PRODUCT_TYPE_SATURDAY_DELIVERY:
$product = new DPDProductInstall();
$product->setName('Saturday Delivery');
$product->setName(self::PRODUCT_NAME_SATURDAY_DELIVERY[$countryCode]);
$product->setId(self::PRODUCT_TYPE_SATURDAY_DELIVERY);
$product->setDelay('Your delivery experts');
$product->setIsPudo(0);
Expand All @@ -354,7 +416,7 @@ public static function getProductByReference($productReference)
break;
case self::PRODUCT_TYPE_SATURDAY_DELIVERY_COD:
$product = new DPDProductInstall();
$product->setName('Saturday Delivery COD');
$product->setName(self::PRODUCT_NAME_SATURDAY_DELIVERY_COD[$countryCode]);
$product->setId(self::PRODUCT_TYPE_SATURDAY_DELIVERY_COD);
$product->setDelay('Your delivery experts');
$product->setIsPudo(0);
Expand All @@ -363,7 +425,7 @@ public static function getProductByReference($productReference)
break;
case self::PRODUCT_TYPE_SAME_DAY_DELIVERY:
$product = new DPDProductInstall();
$product->setName('Same day Delivery');
$product->setName(self::PRODUCT_NAME_SAME_DAY_DELIVERY[$countryCode]);
$product->setId(self::PRODUCT_TYPE_SAME_DAY_DELIVERY);
$product->setDelay('Your delivery experts');
$product->setIsPudo(1);
Expand Down Expand Up @@ -513,4 +575,12 @@ public static function isPrestashopVersionAbove177()

return false;
}

/**
* @return bool
*/
public static function isPrestashopVersionBelow174()
{
return (bool) version_compare(_PS_VERSION_, '1.7.4', '<');
}
}
20 changes: 16 additions & 4 deletions src/Install/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
use Invertus\dpdBaltics\Service\Carrier\CreateCarrierService;
use Invertus\dpdBaltics\Factory\TabFactory;
use Invertus\dpdBaltics\Service\Label\LabelPositionService;
use Invertus\dpdBaltics\Uninstaller\ModuleTabs\ModuleTabsUninstaller;
use Invertus\psModuleTabs\Object\TabsCollection;
use Invertus\psModuleTabs\Service\TabsInitializer;
use Invertus\psModuleTabs\Service\TabsUninstaller;
use Symfony\Component\Validator\Constraints\Count;
use Tools;
use Validate;
Expand Down Expand Up @@ -120,7 +122,7 @@ public function uninstall()
}

if (!$this->uninstallTabs()) {
$this->errors[] = $this->module->l('Failed to install tabs', self::FILE_NAME);
$this->errors[] = $this->module->l('Failed to uninstall tabs', self::FILE_NAME);
return false;
}

Expand Down Expand Up @@ -288,18 +290,28 @@ private function uninstallConfiguration()

private function installTabs()
{
if (!Config::isPrestashopVersionBelow174()) {
return true;
}
/** @var TabsCollection $tabCollection */
$tabCollection = $this->tabFactory->getTabsCollection();

$tabsInitializer = new TabsInitializer(_PS_VERSION_, $tabCollection);

return $tabsInitializer->initializeTabsByPsVersion();
}

private function uninstallTabs()
{
//TODO uninstall tabs
return true;
if (!Config::isPrestashopVersionBelow174()) {
return true;
}

/** @var TabsCollection $tabCollection */
$tabCollection = $this->tabFactory->getTabsCollection()->getTabsCollection();

$tabsUninstaller = new ModuleTabsUninstaller($tabCollection);

return $tabsUninstaller->uninstallTabs();
}
private function processDeleteCarriers()
{
Expand Down
50 changes: 50 additions & 0 deletions src/Service/Carrier/CarrierUpdateHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace Invertus\dpdBaltics\Service\Carrier;


use Invertus\dpdBaltics\Config\Config;
use Invertus\dpdBaltics\Repository\ProductRepository;
use Invertus\dpdBaltics\Service\Product\ProductService;

class CarrierUpdateHandler
{
/**
* @var ProductRepository
*/
private $productRepository;
/**
* @var UpdateCarrierService
*/
private $updateCarrierService;
/**
* @var ProductService
*/
private $productService;

public function __construct(
ProductRepository $productRepository,
UpdateCarrierService $updateCarrierService,
ProductService $productService
) {
$this->productRepository = $productRepository;
$this->updateCarrierService = $updateCarrierService;
$this->productService = $productService;
}

/**
* @param $webServiceCountry
*
* @throws \Invertus\dpdBaltics\Exception\ProductUpdateException
*/
public function updateCarrierName($webServiceCountry)
{
$products = Config::getProducts($webServiceCountry);

foreach ($products as $product) {
$productId = $this->productRepository->getProductIdByProductReference($product->getId());
$this->updateCarrierService->updateCarrierName($productId, $product->getName());
$this->productService->updateProductName($productId, $product->getName());
}
}
}
Loading

0 comments on commit fe219aa

Please sign in to comment.