Skip to content

Commit

Permalink
Clean created_at and updated_at from ps_eventbus (#196)
Browse files Browse the repository at this point in the history
Co-authored-by: Clément Désiles <[email protected]>
  • Loading branch information
guillaume60240 and jokesterfr authored Nov 20, 2023
1 parent 95e90a6 commit 68f2772
Show file tree
Hide file tree
Showing 7 changed files with 5 additions and 55 deletions.
7 changes: 2 additions & 5 deletions src/Builder/CarrierBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ public function buildCarriers(array $carriers, int $langId, \Currency $currency,
new \Carrier($carrier['id_carrier'], $langId),
$currency->iso_code,
$weightUnit,
$carrier['update_date']
);
}

Expand All @@ -90,14 +89,13 @@ public function buildCarriers(array $carriers, int $langId, \Currency $currency,
* @param \Carrier $carrier
* @param string $currencyIsoCode
* @param string $weightUnit
* @param string $updateDate
*
* @return EventBusCarrier
*
* @throws \PrestaShopDatabaseException
* @throws \PrestaShopException
*/
public function buildCarrier(\Carrier $carrier, $currencyIsoCode, $weightUnit, $updateDate)
public function buildCarrier(\Carrier $carrier, $currencyIsoCode, $weightUnit)
{
$eventBusCarrier = new EventBusCarrier();
$freeShippingStartsAtPrice = (float) $this->configurationRepository->get('PS_SHIPPING_FREE_PRICE');
Expand Down Expand Up @@ -128,8 +126,7 @@ public function buildCarrier(\Carrier $carrier, $currencyIsoCode, $weightUnit, $
->setGrade($carrier->grade)
->setDelay($carrier->delay)
->setCurrency($currencyIsoCode)
->setWeightUnit($weightUnit)
->setUpdateAt($updateDate);
->setWeightUnit($weightUnit);

$deliveryPriceByRanges = $this->carrierRepository->getDeliveryPriceByRange($carrier);

Expand Down
26 changes: 0 additions & 26 deletions src/DTO/Carrier.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,6 @@ class Carrier implements \JsonSerializable
*/
private $carrierTaxes = [];

/**
* @var string
*/
private $updateAt;

/**
* @return string
*/
Expand Down Expand Up @@ -672,26 +667,6 @@ public function setCarrierTaxes($carrierTaxes)
return $this;
}

/**
* @return string
*/
public function getUpdateAt()
{
return $this->updateAt;
}

/**
* @param string $updateAt
*
* @return Carrier
*/
public function setUpdateAt($updateAt)
{
$this->updateAt = $updateAt;

return $this;
}

public function jsonSerialize()
{
/*
Expand Down Expand Up @@ -738,7 +713,6 @@ public function jsonSerialize()
'delay' => (string) $this->getDelay(),
'currency' => (string) $this->getCurrency(),
'weight_unit' => (string) $this->getWeightUnit(),
'updated_at' => (string) $this->getUpdateAt(),
],
];

Expand Down
1 change: 0 additions & 1 deletion src/Decorator/ProductSupplierDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,5 @@ private function castProductSupplierPropertyValues(array &$productSupplier)
$productSupplier['product_supplier_price_te'] = (float) $productSupplier['product_supplier_price_te'];
$productSupplier['id_currency'] = (int) $productSupplier['id_currency'];
$productSupplier['created_at'] = (new \DateTime($productSupplier['created_at'], new \DateTimeZone($this->timezone)))->format('Y-m-d\TH:i:sO');
$productSupplier['updated_at'] = (new \DateTime($productSupplier['updated_at'], new \DateTimeZone($this->timezone)))->format('Y-m-d\TH:i:sO');
}
}
2 changes: 0 additions & 2 deletions src/Decorator/StockDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ private function castStockPropertyValues(array &$stock)
$stock['reserved_quantity'] = (int) $stock['reserved_quantity'];
$stock['depends_on_stock'] = (bool) $stock['depends_on_stock'];
$stock['out_of_stock'] = (bool) $stock['out_of_stock'];
$stock['created_at'] = (new \DateTime($stock['created_at'], new \DateTimeZone($this->timezone)))->format('Y-m-d\TH:i:sO');
$stock['updated_at'] = (new \DateTime($stock['updated_at'], new \DateTimeZone($this->timezone)))->format('Y-m-d\TH:i:sO');
}

/**
Expand Down
16 changes: 2 additions & 14 deletions src/Repository/CarrierRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace PrestaShop\Module\PsEventbus\Repository;

use PrestaShop\Module\PsEventbus\Config\Config;

class CarrierRepository
{
/**
Expand Down Expand Up @@ -141,14 +139,9 @@ public function getCarrierProperties($carrierIds, $langId)
}
$query = new \DbQuery();
$query->from('carrier', 'c');
$query->select('c.*, cl.delay, eis.created_at as update_date');
$query->select('c.*, cl.delay');
$query->leftJoin('carrier_lang', 'cl', 'cl.id_carrier = c.id_carrier AND cl.id_lang = ' . (int) $langId);
$query->leftJoin('carrier_shop', 'cs', 'cs.id_carrier = c.id_carrier');
$query->leftJoin(
'eventbus_incremental_sync',
'eis',
'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('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 ' . _DB_PREFIX_ . 'carrier c2 WHERE c2.id_reference=c.id_reference)');
Expand All @@ -169,14 +162,9 @@ public function getAllCarrierProperties($offset, $limit, $langId)
{
$query = new \DbQuery();
$query->from('carrier', 'c');
$query->select('c.id_carrier, IFNULL(eis.created_at, CURRENT_DATE()) as update_date');
$query->select('c.id_carrier');
$query->leftJoin('carrier_lang', 'cl', 'cl.id_carrier = c.id_carrier AND cl.id_lang = ' . (int) $langId);
$query->leftJoin('carrier_shop', 'cs', 'cs.id_carrier = c.id_carrier');
$query->leftJoin(
'eventbus_incremental_sync',
'eis',
'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->where('deleted=0');
$query->limit($limit, $offset);
Expand Down
1 change: 0 additions & 1 deletion src/Repository/StockRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public function getBaseQuery($shopId)
{
$query = new \DbQuery();
$query->from('stock_available', 'sa')
->innerJoin('product', 'p', 'p.id_product = sa.id_product')
->where('sa.id_shop = ' . (int) $shopId);

return $query;
Expand Down
7 changes: 1 addition & 6 deletions tests/e2e/Carrier/CarrierBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
*/
class CarrierBuilderTest extends BaseTestCase
{
public const UPDATE_DATE = '2020-10-10 10:00:00';

/**
* @Stories("carrier builder")
*
Expand Down Expand Up @@ -69,7 +67,7 @@ public function testBuildCarrier(
$configurationRepository = $this->createConfigurationRepositoryMock($freeShippingAtPrice, $freeShippingAtWeight);

$carrierBuilder = new CarrierBuilder($carrierRepo, $countryRepo, $stateRepo, $taxRepository, $configurationRepository);
$carrierLine = $carrierBuilder->buildCarrier($carrier, $currency, $weightUnit, self::UPDATE_DATE);
$carrierLine = $carrierBuilder->buildCarrier($carrier, $currency, $weightUnit);

$this->assertEquals($expected, $carrierLine->jsonSerialize());
}
Expand Down Expand Up @@ -241,7 +239,6 @@ public function buildCarrierDataProvider()
'delay' => $freeCarrierDelay,
'currency' => $currency,
'weight_unit' => $weightUnit,
'updated_at' => self::UPDATE_DATE,
],
],
],
Expand Down Expand Up @@ -303,7 +300,6 @@ public function buildCarrierDataProvider()
'delay' => $carrierDelay,
'currency' => $currency,
'weight_unit' => $weightUnit,
'updated_at' => self::UPDATE_DATE,
],
],
[
Expand Down Expand Up @@ -394,7 +390,6 @@ public function buildCarrierDataProvider()
'delay' => $carrierDelay,
'currency' => $currency,
'weight_unit' => $weightUnit,
'updated_at' => self::UPDATE_DATE,
],
],
[
Expand Down

0 comments on commit 68f2772

Please sign in to comment.