Skip to content

Commit

Permalink
Correction carriers (#147)
Browse files Browse the repository at this point in the history
  • Loading branch information
synicko authored Feb 15, 2023
1 parent 57de45d commit 9caa6d0
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
3 changes: 2 additions & 1 deletion src/DTO/Carrier.php
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,8 @@ public function getDelay()
*/
public function setDelay($delay)
{
$this->delay = $delay;
// data come as an array with one element at index 1 !?!
$this->delay = $delay[1];

return $this;
}
Expand Down
12 changes: 8 additions & 4 deletions src/Provider/CarrierDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@ public function __construct(
public function getFormattedData($offset, $limit, $langIso)
{
$language = new \Language();
$currency = new \Currency();
$currency = new \Currency((int) $this->configurationRepository->get('PS_CURRENCY_DEFAULT'));

$langId = $this->languageRepository->getLanguageIdByIsoCode($langIso);
/** @var array $carriers */
$carriers = $this->carrierRepository->getAllCarrierProperties($offset, $limit, $language->id);
$carriers = $this->carrierRepository->getAllCarrierProperties($offset, $limit, $langId);

/** @var string $configurationPsWeightUnit */
$configurationPsWeightUnit = $this->configurationRepository->get('PS_WEIGHT_UNIT');
Expand All @@ -83,10 +84,13 @@ public function getFormattedDataIncremental($limit, $langIso, $objectIds)
}

$language = new \Language();
$currency = new \Currency();
$currency = new \Currency((int) $this->configurationRepository->get('PS_CURRENCY_DEFAULT'));

$langId = $this->languageRepository->getLanguageIdByIsoCode($langIso);

$carrierIds = array_column($shippingIncremental, 'id_object');
/** @var array $carriers */
$carriers = $this->carrierRepository->getCarrierProperties($carrierIds, $language->id);
$carriers = $this->carrierRepository->getCarrierProperties($carrierIds, $langId);

/** @var string $configurationPsWeightUnit */
$configurationPsWeightUnit = $this->configurationRepository->get('PS_WEIGHT_UNIT');
Expand Down
5 changes: 0 additions & 5 deletions src/Provider/CurrencyDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ public function getFormattedData($offset, $limit, $langIso)
}
$this->currencyDecorator->decorateCurrencies($currencies);

// echo "FullSync";
// var_dump($currencies);
return array_map(function ($currency) {
return [
'id' => $currency['id_currency'],
Expand Down Expand Up @@ -82,9 +80,6 @@ public function getFormattedDataIncremental($limit, $langIso, $objectIds)
}
$this->currencyDecorator->decorateCurrencies($currencies);

// echo "Incremental sync";
// var_dump($currencies);

return array_map(function ($currency) {
return [
'id' => $currency['id_currency'],
Expand Down
3 changes: 2 additions & 1 deletion src/Repository/CarrierRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ public function getCarrierProperties($carrierIds, $langId)
);
$query->where('c.id_carrier IN (' . implode(',', array_map('intval', $carrierIds)) . ')');
$query->where('cs.id_shop = ' . (int) $this->context->shop->id);
$query->groupBy('c.id_reference, c.id_carrier HAVING c.id_carrier=(select max(id_carrier) from ps_carrier c2 WHERE c2.id_reference=c.id_reference)');

return $this->db->executeS($query);
}
Expand All @@ -177,7 +178,7 @@ public function getAllCarrierProperties($offset, $limit, $langId)
'eis.id_object = c.id_carrier AND eis.type = "' . Config::COLLECTION_CARRIERS . '" AND eis.id_shop = cs.id_shop AND eis.lang_iso = cl.id_lang'
);
$query->where('cs.id_shop = ' . (int) $this->context->shop->id);
$query->orderBy('c.id_carrier');
$query->where('deleted=0');
$query->limit($limit, $offset);

return $this->db->executeS($query);
Expand Down

0 comments on commit 9caa6d0

Please sign in to comment.