From e14a0fe207b9717debc1244d7dbb343b413e1b96 Mon Sep 17 00:00:00 2001 From: Hayder Sharhan Date: Tue, 19 Jan 2016 22:08:20 -0600 Subject: [PATCH 1/9] MAGETWO-47767: Update sample module with new changes - Updated sample module with new configuration specifications. --- .../Model/AddToCartPlugin.php | 9 +++------ .../Model/Handler/Async/GitCardAddedSuccess.php | 8 ++++---- .../Model/Handler/Async/SendCustomerNotification.php | 3 ++- .../Model/Handler/Sync/AddGiftCardAccount.php | 4 ++-- sample-module-sample-message-queue/etc/communication.xml | 6 ++---- sample-module-sample-message-queue/etc/queue.xml | 8 +++----- 6 files changed, 16 insertions(+), 22 deletions(-) diff --git a/sample-module-sample-message-queue/Model/AddToCartPlugin.php b/sample-module-sample-message-queue/Model/AddToCartPlugin.php index 7851a78..675eb3c 100644 --- a/sample-module-sample-message-queue/Model/AddToCartPlugin.php +++ b/sample-module-sample-message-queue/Model/AddToCartPlugin.php @@ -65,7 +65,6 @@ public function aroundSave( try { $customer = $subject->getQuote()->getCustomer(); $giftCardAccountCode = $this->publisherPool - ->getByTopicType('add.to.cart.product.added') ->publish('add.to.cart.product.added', $subject->getQuote()->getId()); /** @var \Magento\GiftCardAccount\Model\Giftcardaccount $giftCard */ @@ -82,12 +81,10 @@ public function aroundSave( ]; $this->publisherPool - ->getByTopicType('add.to.cart.giftcard.added') - ->publish('add.to.cart.giftcard.added', $payload); + ->publish('add.to.cart.giftcard.added', json_encode($payload)); $this->publisherPool - ->getByTopicType('add.to.cart.giftcard.added.success') - ->publish('add.to.cart.giftcard.added.success', $payload); + ->publish('add.to.cart.giftcard.added.success', json_encode($payload)); } catch (\Exception $e) { $this->logger->debug('Plugin Error: ' . $e->getMessage()); @@ -99,4 +96,4 @@ public function aroundSave( } return $result; } -} \ No newline at end of file +} diff --git a/sample-module-sample-message-queue/Model/Handler/Async/GitCardAddedSuccess.php b/sample-module-sample-message-queue/Model/Handler/Async/GitCardAddedSuccess.php index 3f48724..e7d3262 100644 --- a/sample-module-sample-message-queue/Model/Handler/Async/GitCardAddedSuccess.php +++ b/sample-module-sample-message-queue/Model/Handler/Async/GitCardAddedSuccess.php @@ -28,10 +28,10 @@ public function __construct(LoggerInterface $logger) /** * Log information about added gift card * - * @param string[] $data + * @param $data */ - public function log(array $data) + public function log($data) { - $this->logger->debug('ASYNC Handler: Git Card Added Successfully: ' . serialize($data)); + $this->logger->debug('ASYNC Handler: Gift Card Added Successfully: ' . $data); } -} \ No newline at end of file +} diff --git a/sample-module-sample-message-queue/Model/Handler/Async/SendCustomerNotification.php b/sample-module-sample-message-queue/Model/Handler/Async/SendCustomerNotification.php index 2cd6b5b..7099094 100644 --- a/sample-module-sample-message-queue/Model/Handler/Async/SendCustomerNotification.php +++ b/sample-module-sample-message-queue/Model/Handler/Async/SendCustomerNotification.php @@ -60,6 +60,7 @@ public function __construct( */ public function send($payload) { + $payload = json_decode($payload, true); $quoteId = $payload['cart_id']; $quote = $this->cartRepository->get($quoteId); $store = $this->storeManager->getStore($quote->getStoreId()); @@ -78,4 +79,4 @@ public function send($payload) $transport->sendMessage(); $this->logger->debug('ASYNC Handler: Sent customer notification email to: ' . $payload['customer_email']); } -} \ No newline at end of file +} diff --git a/sample-module-sample-message-queue/Model/Handler/Sync/AddGiftCardAccount.php b/sample-module-sample-message-queue/Model/Handler/Sync/AddGiftCardAccount.php index d941c7a..243c9e5 100644 --- a/sample-module-sample-message-queue/Model/Handler/Sync/AddGiftCardAccount.php +++ b/sample-module-sample-message-queue/Model/Handler/Sync/AddGiftCardAccount.php @@ -56,7 +56,7 @@ public function __construct( /** * Add Gift Card Account to Shopping Card - * + * * @param int $quoteId * @return string * @throws \Exception @@ -89,4 +89,4 @@ public function add($quoteId) } return $giftCardCode; } -} \ No newline at end of file +} diff --git a/sample-module-sample-message-queue/etc/communication.xml b/sample-module-sample-message-queue/etc/communication.xml index 2f1666e..f13f6e6 100644 --- a/sample-module-sample-message-queue/etc/communication.xml +++ b/sample-module-sample-message-queue/etc/communication.xml @@ -9,12 +9,10 @@ - - + - - \ No newline at end of file + diff --git a/sample-module-sample-message-queue/etc/queue.xml b/sample-module-sample-message-queue/etc/queue.xml index d1484ad..9c49678 100644 --- a/sample-module-sample-message-queue/etc/queue.xml +++ b/sample-module-sample-message-queue/etc/queue.xml @@ -7,14 +7,12 @@ --> - - + - + - + - From 7c176fc7f3c043f46e0fe12bc38e0c3792dfbe54 Mon Sep 17 00:00:00 2001 From: Hayder Sharhan Date: Wed, 20 Jan 2016 12:21:24 -0600 Subject: [PATCH 2/9] MAGETWO-47767: Update sample module with new changes - Added support for 1 to many relationship. --- .../Model/AddToCartPlugin.php | 3 --- sample-module-sample-message-queue/etc/communication.xml | 7 +------ sample-module-sample-message-queue/etc/queue.xml | 6 ++---- 3 files changed, 3 insertions(+), 13 deletions(-) diff --git a/sample-module-sample-message-queue/Model/AddToCartPlugin.php b/sample-module-sample-message-queue/Model/AddToCartPlugin.php index 675eb3c..3aad0cc 100644 --- a/sample-module-sample-message-queue/Model/AddToCartPlugin.php +++ b/sample-module-sample-message-queue/Model/AddToCartPlugin.php @@ -83,9 +83,6 @@ public function aroundSave( $this->publisherPool ->publish('add.to.cart.giftcard.added', json_encode($payload)); - $this->publisherPool - ->publish('add.to.cart.giftcard.added.success', json_encode($payload)); - } catch (\Exception $e) { $this->logger->debug('Plugin Error: ' . $e->getMessage()); } diff --git a/sample-module-sample-message-queue/etc/communication.xml b/sample-module-sample-message-queue/etc/communication.xml index f13f6e6..ebb1cf6 100644 --- a/sample-module-sample-message-queue/etc/communication.xml +++ b/sample-module-sample-message-queue/etc/communication.xml @@ -6,12 +6,7 @@ */ --> - - - - - - + diff --git a/sample-module-sample-message-queue/etc/queue.xml b/sample-module-sample-message-queue/etc/queue.xml index 9c49678..ddbe046 100644 --- a/sample-module-sample-message-queue/etc/queue.xml +++ b/sample-module-sample-message-queue/etc/queue.xml @@ -7,10 +7,8 @@ --> - - - - + + From a94342c31abb6eb340af36b703c7e7233cd4734e Mon Sep 17 00:00:00 2001 From: Arkadii Chyzhov Date: Wed, 10 Feb 2016 19:05:35 +0200 Subject: [PATCH 3/9] MAGETWO-48937: AMQP: After adding gift card to the cart, email sent to the customer is missing Gift Card code, and dollar amount. - fixed balance field - added giftcard_id field --- sample-module-sample-message-queue/Model/AddToCartPlugin.php | 3 ++- .../Model/Handler/Async/SendCustomerNotification.php | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/sample-module-sample-message-queue/Model/AddToCartPlugin.php b/sample-module-sample-message-queue/Model/AddToCartPlugin.php index 3aad0cc..4800133 100644 --- a/sample-module-sample-message-queue/Model/AddToCartPlugin.php +++ b/sample-module-sample-message-queue/Model/AddToCartPlugin.php @@ -74,10 +74,11 @@ public function aroundSave( throw new \Exception('Invalid gift card code'); } $payload = [ - 'amount' => $giftCard->getGiftCardsAmount(), + 'balance' => $giftCard->getBalance(), 'customer_email' => $customer->getEmail(), 'customer_name' => $customer->getFirstname() . ' ' . $customer->getLastname(), 'cart_id' => $subject->getQuote()->getId(), + 'giftcard_id' => $giftCard->getId() ]; $this->publisherPool diff --git a/sample-module-sample-message-queue/Model/Handler/Async/SendCustomerNotification.php b/sample-module-sample-message-queue/Model/Handler/Async/SendCustomerNotification.php index 7099094..3efb682 100644 --- a/sample-module-sample-message-queue/Model/Handler/Async/SendCustomerNotification.php +++ b/sample-module-sample-message-queue/Model/Handler/Async/SendCustomerNotification.php @@ -71,7 +71,8 @@ public function send($payload) ->setTemplateVars([ 'name' => $payload['customer_name'], 'sender_name' => 'Your Friends at ' . $storeName, - 'balance' => '$' . $payload['amount'] + 'balance' => '$' . $payload['balance'], + 'code' => $payload['giftcard_id'] ]) ->setFrom(['name' => 'Your Friends at ' . $storeName, 'email' => '']) ->addTo($payload['customer_email']) From 427eb472d7cae25a8e58ce522f85a3be0889de98 Mon Sep 17 00:00:00 2001 From: Arkadii Chyzhov Date: Wed, 10 Feb 2016 19:29:01 +0200 Subject: [PATCH 4/9] MAGETWO-48961: AMQP: Adding product to the cart, missing logging statements in var/log/debug.log --- sample-module-sample-message-queue/etc/di.xml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/sample-module-sample-message-queue/etc/di.xml b/sample-module-sample-message-queue/etc/di.xml index e91a333..7199dfe 100644 --- a/sample-module-sample-message-queue/etc/di.xml +++ b/sample-module-sample-message-queue/etc/di.xml @@ -9,4 +9,12 @@ + + + main + + Magento\Framework\Logger\Handler\Debug + + + From e0db00d4c0f4deaa8275b473060bf7d21b97d3be Mon Sep 17 00:00:00 2001 From: Arkadii Chyzhov Date: Thu, 11 Feb 2016 19:09:50 +0200 Subject: [PATCH 5/9] MAGETWO-48937: AMQP: After adding gift card to the cart, email sent to the customer is missing Gift Card code, and dollar amount. - fixed currency format - fixed giftcard code field --- .../Model/AddToCartPlugin.php | 3 +- .../Handler/Async/GitCardAddedSuccess.php | 2 +- .../Async/SendCustomerNotification.php | 84 ++++++++++++++++--- .../Model/Handler/Sync/AddGiftCardAccount.php | 2 +- 4 files changed, 77 insertions(+), 14 deletions(-) diff --git a/sample-module-sample-message-queue/Model/AddToCartPlugin.php b/sample-module-sample-message-queue/Model/AddToCartPlugin.php index 4800133..ced1832 100644 --- a/sample-module-sample-message-queue/Model/AddToCartPlugin.php +++ b/sample-module-sample-message-queue/Model/AddToCartPlugin.php @@ -78,7 +78,8 @@ public function aroundSave( 'customer_email' => $customer->getEmail(), 'customer_name' => $customer->getFirstname() . ' ' . $customer->getLastname(), 'cart_id' => $subject->getQuote()->getId(), - 'giftcard_id' => $giftCard->getId() + 'giftcard_code' => $giftCard->getCode(), + 'giftcard_is_redeemable' => $giftCard->getIsRedeemable() ]; $this->publisherPool diff --git a/sample-module-sample-message-queue/Model/Handler/Async/GitCardAddedSuccess.php b/sample-module-sample-message-queue/Model/Handler/Async/GitCardAddedSuccess.php index e7d3262..416daa0 100644 --- a/sample-module-sample-message-queue/Model/Handler/Async/GitCardAddedSuccess.php +++ b/sample-module-sample-message-queue/Model/Handler/Async/GitCardAddedSuccess.php @@ -6,7 +6,7 @@ namespace Magento\SampleMessageQueue\Model\Handler\Async; -use \Psr\Log\LoggerInterface; +use Psr\Log\LoggerInterface; class GitCardAddedSuccess { diff --git a/sample-module-sample-message-queue/Model/Handler/Async/SendCustomerNotification.php b/sample-module-sample-message-queue/Model/Handler/Async/SendCustomerNotification.php index 3efb682..8608362 100644 --- a/sample-module-sample-message-queue/Model/Handler/Async/SendCustomerNotification.php +++ b/sample-module-sample-message-queue/Model/Handler/Async/SendCustomerNotification.php @@ -3,13 +3,14 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ - namespace Magento\SampleMessageQueue\Model\Handler\Async; use Magento\Framework\Mail\Template\TransportBuilder; use Magento\Quote\Api\CartRepositoryInterface; use Magento\Store\Model\StoreManagerInterface; -use \Psr\Log\LoggerInterface; +use Psr\Log\LoggerInterface; +use Magento\GiftCard\Helper\Data as GiftCardData; +use Magento\Framework\Locale\CurrencyInterface as LocaleCurrency; class SendCustomerNotification { @@ -33,6 +34,16 @@ class SendCustomerNotification */ protected $storeManager; + /** + * @var GiftCardData + */ + protected $giftCardData; + + /** + * @var LocaleCurrency + */ + protected $localeCurrency; + /** * Initialize dependencies. * @@ -40,23 +51,29 @@ class SendCustomerNotification * @param TransportBuilder $transportBuilder * @param CartRepositoryInterface $cartRepository * @param StoreManagerInterface $storeManager + * @param GiftCardData $giftCardData + * @param LocaleCurrency $localeCurrency */ public function __construct( LoggerInterface $logger, TransportBuilder $transportBuilder, CartRepositoryInterface $cartRepository, - StoreManagerInterface $storeManager + StoreManagerInterface $storeManager, + GiftCardData $giftCardData, + LocaleCurrency $localeCurrency ) { $this->logger = $logger; $this->transportBuilder = $transportBuilder; $this->cartRepository = $cartRepository; $this->storeManager = $storeManager; + $this->giftCardData = $giftCardData; + $this->localeCurrency = $localeCurrency; } /** * Send customer notification * - * @param $payload + * @param string $payload */ public function send($payload) { @@ -67,17 +84,62 @@ public function send($payload) $storeName = $store->getName(); $transport = $this->transportBuilder->setTemplateIdentifier('giftcard_email_template') - ->setTemplateOptions(['area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => $quote->getStoreId()]) - ->setTemplateVars([ - 'name' => $payload['customer_name'], - 'sender_name' => 'Your Friends at ' . $storeName, - 'balance' => '$' . $payload['balance'], - 'code' => $payload['giftcard_id'] - ]) + ->setTemplateOptions( + ['area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => $quote->getStoreId()] + ) + ->setTemplateVars( + [ + 'name' => $payload['customer_name'], + 'sender_name' => 'Your Friends at ' . $storeName, + 'balance' => $this->getFormattedBalance($payload['balance'], $quote->getStoreId()), + 'giftcards' => $this->getCodeHtml($payload, $quote->getStoreId()), + 'is_redeemable' => $payload['giftcard_is_redeemable'], + 'store' => $store, + 'store_name' => $storeName, + 'is_multiple_codes' => 0 + ] + ) ->setFrom(['name' => 'Your Friends at ' . $storeName, 'email' => '']) ->addTo($payload['customer_email']) ->getTransport(); $transport->sendMessage(); $this->logger->debug('ASYNC Handler: Sent customer notification email to: ' . $payload['customer_email']); } + + /** + * Return gift card code html + * + * @param array $payload + * @param int $storeId + * @return string + */ + private function getCodeHtml(array $payload, $storeId) + { + return $this->giftCardData->getEmailGeneratedItemsBlock()->setCodes( + [$payload['giftcard_code']] + )->setArea( + \Magento\Framework\App\Area::AREA_FRONTEND + )->setIsRedeemable( + $payload['giftcard_is_redeemable'] + )->setStore( + $this->storeManager->getStore($storeId) + )->toHtml(); + } + + /** + * Return formatted Balance + * + * @param int|float $balance + * @param int $storeId + * @return string + * @throws \Zend_Currency_Exception + */ + private function getFormattedBalance($balance, $storeId) + { + return $this->localeCurrency->getCurrency( + $this->storeManager->getStore($storeId)->getBaseCurrencyCode() + )->toCurrency( + $balance + ); + } } diff --git a/sample-module-sample-message-queue/Model/Handler/Sync/AddGiftCardAccount.php b/sample-module-sample-message-queue/Model/Handler/Sync/AddGiftCardAccount.php index 243c9e5..8b05160 100644 --- a/sample-module-sample-message-queue/Model/Handler/Sync/AddGiftCardAccount.php +++ b/sample-module-sample-message-queue/Model/Handler/Sync/AddGiftCardAccount.php @@ -6,7 +6,7 @@ namespace Magento\SampleMessageQueue\Model\Handler\Sync; -use \Psr\Log\LoggerInterface; +use Psr\Log\LoggerInterface; use Magento\Store\Model\StoreManagerInterface; use Magento\GiftCardAccount\Model\Giftcardaccount; From 13d3502e07e67f35287643c2258e071584617e9b Mon Sep 17 00:00:00 2001 From: Oleksii Korshenko Date: Mon, 29 Feb 2016 14:39:42 -0600 Subject: [PATCH 6/9] MAGETWO-45161: API Out: RPC Integration - Part 1 --- sample-module-sample-message-queue/etc/communication.xml | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/sample-module-sample-message-queue/etc/communication.xml b/sample-module-sample-message-queue/etc/communication.xml index 3526da8..ebb1cf6 100644 --- a/sample-module-sample-message-queue/etc/communication.xml +++ b/sample-module-sample-message-queue/etc/communication.xml @@ -6,14 +6,7 @@ */ --> - - - - - - - - + From d6e35dca3a1ea94df80d6b80f94b1060427929e7 Mon Sep 17 00:00:00 2001 From: Hayder Sharhan Date: Mon, 29 Feb 2016 15:26:00 -0600 Subject: [PATCH 7/9] MAGETWO-43457: Queue tasks execution controller - small problem with name of class. --- sample-module-sample-message-queue/etc/queue.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sample-module-sample-message-queue/etc/queue.xml b/sample-module-sample-message-queue/etc/queue.xml index ddbe046..2ce34d0 100644 --- a/sample-module-sample-message-queue/etc/queue.xml +++ b/sample-module-sample-message-queue/etc/queue.xml @@ -8,7 +8,7 @@ - + From 05b68d575f0d19167a1d9bbd3d6e383f8453e9d6 Mon Sep 17 00:00:00 2001 From: Hayder Sharhan Date: Mon, 29 Feb 2016 15:33:48 -0600 Subject: [PATCH 8/9] MAGETWO-43457: Queue tasks execution controller - Corrected argument type. --- .../Model/Handler/Async/SendCustomerNotification.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sample-module-sample-message-queue/Model/Handler/Async/SendCustomerNotification.php b/sample-module-sample-message-queue/Model/Handler/Async/SendCustomerNotification.php index 1e0245a..8a1e7bf 100644 --- a/sample-module-sample-message-queue/Model/Handler/Async/SendCustomerNotification.php +++ b/sample-module-sample-message-queue/Model/Handler/Async/SendCustomerNotification.php @@ -77,7 +77,7 @@ public function __construct( * @throws \InvalidArgumentException * @return void */ - public function send(array $payload) + public function send($payload) { $payload = json_decode($payload, true); if (!isset($payload['cart_id'])) { From 3db27a40b1c7067fa773aa774211bb6c38457952 Mon Sep 17 00:00:00 2001 From: Hayder Sharhan Date: Mon, 28 Mar 2016 10:57:45 -0500 Subject: [PATCH 9/9] MAGETWO-43457: Queue tasks execution controller --- .../Model/Handler/Async/SendCustomerNotification.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/sample-module-sample-message-queue/Model/Handler/Async/SendCustomerNotification.php b/sample-module-sample-message-queue/Model/Handler/Async/SendCustomerNotification.php index 8a1e7bf..d398935 100644 --- a/sample-module-sample-message-queue/Model/Handler/Async/SendCustomerNotification.php +++ b/sample-module-sample-message-queue/Model/Handler/Async/SendCustomerNotification.php @@ -1,6 +1,6 @@ isset($payload['customer_name']) ? $payload['customer_name'] : '', 'sender_name' => 'Your Friends at ' . $storeName, - 'balance' => $this->getFormattedBalance(isset($payload['amount']) ? $payload['amount'] : 0, $quote->getStoreId()), + 'balance' => $this->getFormattedBalance( + isset($payload['amount']) ? $payload['amount'] : 0, + $quote->getStoreId() + ), 'giftcards' => $this->getCodeHtml($payload, $quote->getStoreId()), 'is_redeemable' => $payload['giftcard_is_redeemable'], 'store' => $store,