From 68f27727e953be33b0a464951154bca8283b4a30 Mon Sep 17 00:00:00 2001 From: guillaume60240 <77913074+guillaume60240@users.noreply.github.com> Date: Mon, 20 Nov 2023 11:40:49 +0100 Subject: [PATCH] Clean created_at and updated_at from ps_eventbus (#196) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Clément Désiles <1536672+jokesterfr@users.noreply.github.com> --- src/Builder/CarrierBuilder.php | 7 ++---- src/DTO/Carrier.php | 26 ---------------------- src/Decorator/ProductSupplierDecorator.php | 1 - src/Decorator/StockDecorator.php | 2 -- src/Repository/CarrierRepository.php | 16 ++----------- src/Repository/StockRepository.php | 1 - tests/e2e/Carrier/CarrierBuilderTest.php | 7 +----- 7 files changed, 5 insertions(+), 55 deletions(-) diff --git a/src/Builder/CarrierBuilder.php b/src/Builder/CarrierBuilder.php index a5e47a34..f0244e51 100755 --- a/src/Builder/CarrierBuilder.php +++ b/src/Builder/CarrierBuilder.php @@ -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'] ); } @@ -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'); @@ -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); diff --git a/src/DTO/Carrier.php b/src/DTO/Carrier.php index 4d83516b..7f8e5976 100755 --- a/src/DTO/Carrier.php +++ b/src/DTO/Carrier.php @@ -139,11 +139,6 @@ class Carrier implements \JsonSerializable */ private $carrierTaxes = []; - /** - * @var string - */ - private $updateAt; - /** * @return string */ @@ -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() { /* @@ -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(), ], ]; diff --git a/src/Decorator/ProductSupplierDecorator.php b/src/Decorator/ProductSupplierDecorator.php index cb79604f..b965aed5 100755 --- a/src/Decorator/ProductSupplierDecorator.php +++ b/src/Decorator/ProductSupplierDecorator.php @@ -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'); } } diff --git a/src/Decorator/StockDecorator.php b/src/Decorator/StockDecorator.php index 6c1d77f1..c778f11d 100755 --- a/src/Decorator/StockDecorator.php +++ b/src/Decorator/StockDecorator.php @@ -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'); } /** diff --git a/src/Repository/CarrierRepository.php b/src/Repository/CarrierRepository.php index 3a1d1c33..8411b4f6 100755 --- a/src/Repository/CarrierRepository.php +++ b/src/Repository/CarrierRepository.php @@ -2,8 +2,6 @@ namespace PrestaShop\Module\PsEventbus\Repository; -use PrestaShop\Module\PsEventbus\Config\Config; - class CarrierRepository { /** @@ -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)'); @@ -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); diff --git a/src/Repository/StockRepository.php b/src/Repository/StockRepository.php index 532fbffd..c6cc2d5d 100755 --- a/src/Repository/StockRepository.php +++ b/src/Repository/StockRepository.php @@ -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; diff --git a/tests/e2e/Carrier/CarrierBuilderTest.php b/tests/e2e/Carrier/CarrierBuilderTest.php index 56bb05e1..c9ee3f34 100755 --- a/tests/e2e/Carrier/CarrierBuilderTest.php +++ b/tests/e2e/Carrier/CarrierBuilderTest.php @@ -21,8 +21,6 @@ */ class CarrierBuilderTest extends BaseTestCase { - public const UPDATE_DATE = '2020-10-10 10:00:00'; - /** * @Stories("carrier builder") * @@ -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()); } @@ -241,7 +239,6 @@ public function buildCarrierDataProvider() 'delay' => $freeCarrierDelay, 'currency' => $currency, 'weight_unit' => $weightUnit, - 'updated_at' => self::UPDATE_DATE, ], ], ], @@ -303,7 +300,6 @@ public function buildCarrierDataProvider() 'delay' => $carrierDelay, 'currency' => $currency, 'weight_unit' => $weightUnit, - 'updated_at' => self::UPDATE_DATE, ], ], [ @@ -394,7 +390,6 @@ public function buildCarrierDataProvider() 'delay' => $carrierDelay, 'currency' => $currency, 'weight_unit' => $weightUnit, - 'updated_at' => self::UPDATE_DATE, ], ], [