From 4fa9b62996797260873ad286a86abf1f75891230 Mon Sep 17 00:00:00 2001 From: MykolaMalovanets Date: Mon, 20 Nov 2023 13:32:20 +0200 Subject: [PATCH] Remove redundant plugins. --- Plugin/Product/AddWebsitePlugin.php | 63 -------------- Plugin/Product/RemoveWebsitePlugin.php | 62 ------------- Plugin/Product/UpdateAttributesPlugin.php | 84 ------------------ .../UpdateCartItemQtyPlugin.php | 87 ------------------- .../Model/Quote/RemoveCartItemPlugin.php | 86 ------------------ .../Quote/PersistQuoteCurrencyPlugin.php | 40 --------- etc/di.xml | 25 ------ etc/webapi_rest/di.xml | 3 - 8 files changed, 450 deletions(-) delete mode 100644 Plugin/Product/AddWebsitePlugin.php delete mode 100644 Plugin/Product/RemoveWebsitePlugin.php delete mode 100644 Plugin/Product/UpdateAttributesPlugin.php delete mode 100644 Plugin/Quote/Api/Data/CartItemInterface/UpdateCartItemQtyPlugin.php delete mode 100644 Plugin/Quote/Model/Quote/RemoveCartItemPlugin.php delete mode 100644 Plugin/Sales/Model/ResourceModel/Quote/PersistQuoteCurrencyPlugin.php diff --git a/Plugin/Product/AddWebsitePlugin.php b/Plugin/Product/AddWebsitePlugin.php deleted file mode 100644 index 64c616d..0000000 --- a/Plugin/Product/AddWebsitePlugin.php +++ /dev/null @@ -1,63 +0,0 @@ -publisher = $publisher; - $this->logger = $logger; - } - - /** - * Publish product ids after add product to website. - * - * @param Website $subject - * @param Website $result - * @param array $websiteIds - * @param array $productIds - * @return Website - */ - public function afterAddProducts(Website $subject, $result, $websiteIds, $productIds): Website - { - $websiteIds = array_map('intval', $websiteIds); - $productIds = array_map('intval', $productIds); - foreach ($websiteIds as $websiteId) { - try { - $this->publisher->publish(self::TOPIC_NAME, $websiteId, $productIds); - } catch (Exception $e) { - $this->logger->error($e->getMessage()); - } - } - - return $result; - } -} diff --git a/Plugin/Product/RemoveWebsitePlugin.php b/Plugin/Product/RemoveWebsitePlugin.php deleted file mode 100644 index d85d5ab..0000000 --- a/Plugin/Product/RemoveWebsitePlugin.php +++ /dev/null @@ -1,62 +0,0 @@ -publisher = $publisher; - $this->logger = $logger; - } - - /** - * Publish product ids after remove product from website. - * - * @param Website $subject - * @param Website $result - * @param array $websiteIds - * @param array $productIds - * @return Website - */ - public function afterRemoveProducts(Website $subject, $result, $websiteIds, $productIds): Website - { - $websiteIds = array_map('intval', $websiteIds); - $productIds = array_map('intval', $productIds); - foreach ($websiteIds as $websiteId) { - try { - $this->publisher->publish(self::TOPIC_NAME, $websiteId, $productIds); - } catch (\Exception $e) { - $this->logger->error($e->getMessage()); - } - } - - return $result; - } -} diff --git a/Plugin/Product/UpdateAttributesPlugin.php b/Plugin/Product/UpdateAttributesPlugin.php deleted file mode 100644 index ae5b0ed..0000000 --- a/Plugin/Product/UpdateAttributesPlugin.php +++ /dev/null @@ -1,84 +0,0 @@ -publisher = $publisher; - $this->storeManager = $storeManager; - $this->logger = $logger; - } - - /** - * Add updated Products ids to Bold Products synchronization queue. - * - * @param Action $subject - * @param Action $result - * @param array $productIds - * @param array $attrData - * @param int $storeId - * @return Action - */ - public function afterUpdateAttributes( - Action $subject, - Action $result, - array $productIds, - array $attrData, - $storeId - ): Action { - $websiteIds = array_map( - function (WebsiteInterface $website) { - return (int)$website->getId(); - }, - $this->storeManager->getWebsites() - ); - - $intIds = array_map('intval', $productIds); - foreach ($websiteIds as $websiteId) { - try { - $this->publisher->publish(self::TOPIC_NAME, $websiteId, $intIds); - } catch (\Exception $e) { - $this->logger->error($e->getMessage()); - } - } - - return $result; - } -} diff --git a/Plugin/Quote/Api/Data/CartItemInterface/UpdateCartItemQtyPlugin.php b/Plugin/Quote/Api/Data/CartItemInterface/UpdateCartItemQtyPlugin.php deleted file mode 100644 index 9e9c6f4..0000000 --- a/Plugin/Quote/Api/Data/CartItemInterface/UpdateCartItemQtyPlugin.php +++ /dev/null @@ -1,87 +0,0 @@ -checkoutSession = $checkoutSession; - $this->client = $client; - } - - /** - * Send update qty to Bold. - * - * @param CartItemInterface $subject - * @param CartItemInterface $result - * @param float $qty - * @return CartItemInterface - */ - public function afterSetQty(CartItemInterface $subject, CartItemInterface $result, $qty): CartItemInterface - { - if (!$this->checkoutSession->getBoldCheckoutData()) { - return $result; - } - try { - $lineItemQty = $this->getLineItemQty($subject); - if ($lineItemQty !== (int)$qty) { - $this->client->put( - (int)$subject->getQuote()->getStore()->getWebsiteId(), - 'items', - [ - 'platform_id' => (string)$subject->getProduct()->getId(), - 'line_item_key' => (string)$subject->getItemId(), - 'quantity' => (int)$qty, - ] - ); - } - } catch (\Exception $e) { - return $result; - } - return $result; - } - - /** - * Get line item qty from Bold Checkout data. - * - * @param CartItemInterface $cartItem - * @return int - * @throws LocalizedException - */ - private function getLineItemQty(CartItemInterface $cartItem): int - { - $boldCheckoutData = $this->checkoutSession->getBoldCheckoutData(); - $lineItems = $boldCheckoutData['data']['application_state']['line_items'] ?? []; - foreach ($lineItems as $lineItem) { - $lineItemKey = $lineItem['product_data']['line_item_key'] ?? null; - if ((string)$cartItem->getItemId() === $lineItemKey) { - return (int)$lineItem['product_data']['quantity']; - } - } - throw new LocalizedException(__('There is no line item with key: %1', $cartItem->getItemId())); - } -} diff --git a/Plugin/Quote/Model/Quote/RemoveCartItemPlugin.php b/Plugin/Quote/Model/Quote/RemoveCartItemPlugin.php deleted file mode 100644 index 2f9de38..0000000 --- a/Plugin/Quote/Model/Quote/RemoveCartItemPlugin.php +++ /dev/null @@ -1,86 +0,0 @@ -checkoutSession = $checkoutSession; - $this->client = $client; - } - - /** - * Send remove item request to Bold. - * - * @param Quote $subject - * @param Quote $result - * @param int $itemId - * @return Quote - */ - public function afterRemoveItem(Quote $subject, Quote $result, $itemId): Quote - { - if (!$this->checkoutSession->getBoldCheckoutData()) { - return $result; - } - try { - $lineItem = $this->getLineItem((int)$itemId); - $this->client->delete( - (int)$result->getStore()->getWebsiteId(), - 'items', - [ - 'platform_id' => $lineItem['product_data']['variant_id'], - 'line_item_key' => (string)$itemId, - 'quantity' => $lineItem['product_data']['quantity'], - ] - ); - } catch (\Exception $e) { - return $result; - } - return $result; - } - - /** - * Get line item qty from Bold Checkout data. - * - * @param int $cartItemId - * @return array - * @throws LocalizedException - */ - private function getLineItem(int $cartItemId): array - { - $boldCheckoutData = $this->checkoutSession->getBoldCheckoutData(); - $lineItems = $boldCheckoutData['data']['application_state']['line_items'] ?? []; - foreach ($lineItems as $lineItem) { - $lineItemKey = $lineItem['product_data']['line_item_key'] ?? null; - if ((string)$cartItemId === $lineItemKey) { - return $lineItem; - } - } - throw new LocalizedException(__('There is no line item with key: %1', $cartItemId)); - } -} diff --git a/Plugin/Sales/Model/ResourceModel/Quote/PersistQuoteCurrencyPlugin.php b/Plugin/Sales/Model/ResourceModel/Quote/PersistQuoteCurrencyPlugin.php deleted file mode 100644 index a5b7b9f..0000000 --- a/Plugin/Sales/Model/ResourceModel/Quote/PersistQuoteCurrencyPlugin.php +++ /dev/null @@ -1,40 +0,0 @@ -currency = $currency; - } - - /** - * Set quote currency as forced currency to prevent set one as base store currency for rest api. - * - * @param Quote $subject - * @param AbstractModel $quote - * @return void - */ - public function beforeSave(Quote $subject, AbstractModel $quote): void - { - $currency = $this->currency->load($quote->getQuoteCurrencyCode()); - $quote->setForcedCurrency($currency); - } -} diff --git a/etc/di.xml b/etc/di.xml index 46dd25a..379b44f 100644 --- a/etc/di.xml +++ b/etc/di.xml @@ -78,13 +78,6 @@ - - - - - - - Bold\Checkout\Model\Http\Client\RequestsLogger\Logger @@ -103,24 +96,6 @@ - - - - - - Bold\Checkout\Model\Http\BoldStorefrontClient - - - - - - - - - Bold\Checkout\Model\Http\BoldStorefrontClient - - - diff --git a/etc/webapi_rest/di.xml b/etc/webapi_rest/di.xml index 0ec52de..22eb1db 100644 --- a/etc/webapi_rest/di.xml +++ b/etc/webapi_rest/di.xml @@ -6,9 +6,6 @@ - - - \Bold\Checkout\Api\Data\PlaceOrder\Request\OrderDataInterface::PROPERTIES_REQUIRED