From 9df8dc7e6ea17b7bae94019fa1e3e085db21c607 Mon Sep 17 00:00:00 2001 From: bst2002git Date: Thu, 30 Jul 2020 16:45:23 +0200 Subject: [PATCH 1/9] Add Product Display Select Options: Up-Sell Products, Related Products, Cross-Sell Products --- composer.json | 4 +- popup-admin/Model/Config/Source/Carousel.php | 10 ++- popup-display/CustomerData/PopupCartData.php | 73 +++++++++++++++++++- 3 files changed, 82 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index c465ed0..9b9792a 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ ] }, "type": "magento2-metapackage", - "version": "1.0.0", + "version": "1.0.0.1", "authors": [ { "name": "Andresa Martins", @@ -48,4 +48,4 @@ "url": "https://repo.magento.com/" } ] -} \ No newline at end of file +} diff --git a/popup-admin/Model/Config/Source/Carousel.php b/popup-admin/Model/Config/Source/Carousel.php index f8e050f..1b6823b 100644 --- a/popup-admin/Model/Config/Source/Carousel.php +++ b/popup-admin/Model/Config/Source/Carousel.php @@ -23,7 +23,10 @@ public function toOptionArray() return [ ['value' => '_bestSellerProducts', 'label' => __('Best Sellers')], ['value' => '_latestProducts', 'label' => __('Latest Products')], - ['value' => '_randomProducts', 'label' => __('Random Products')] + ['value' => '_randomProducts', 'label' => __('Random Products')], + ['value' => '_upSellingProducts', 'label' => __('Up-Sell Products')], + ['value' => '_relatedProducts', 'label' => __('Related Products')], + ['value' => '_crossSellProducts', 'label' => __('Cross-Sell Products')] ]; } @@ -37,7 +40,10 @@ public function toArray() return [ '_bestSellerProducts' => __('Best Sellers'), '_latestProducts' => __('Latest Products'), - '_randomProducts' => __('Random Products') + '_randomProducts' => __('Random Products'), + '_upSellingProducts' => __('Up-Sell Products'), + '_relatedProducts' => __('Related Products'), + '_crossSellProducts' => __('Cross-Sell Products') ]; } } diff --git a/popup-display/CustomerData/PopupCartData.php b/popup-display/CustomerData/PopupCartData.php index 13ab714..2d065e6 100644 --- a/popup-display/CustomerData/PopupCartData.php +++ b/popup-display/CustomerData/PopupCartData.php @@ -21,6 +21,8 @@ use Magento\Framework\Pricing\Helper\Data as PricingHelper; use Magento\Sales\Model\ResourceModel\Report\Bestsellers\CollectionFactory as BestSellersCollectionFactory; use Prestafy\PopupDisplay\Helper\Data as Helper; +use Magento\Checkout\Model\Session as CheckoutSession; +use Magento\Catalog\Api\ProductRepositoryInterface as ProductRepositoryInterface; /** * PopupCart source @@ -73,6 +75,13 @@ class PopupCartData implements SectionSourceInterface */ protected $bestSellersCollectionFactory; + /** + * @var \Magento\Checkout\Model\Session + */ + protected $checkoutSession; + + protected $productRepository; + /** * @param CollectionFactory $collectionFactory * @param Image $catalogImage @@ -81,6 +90,9 @@ class PopupCartData implements SectionSourceInterface * @param Visibility $productVisibility * @param CartHelper $cartHelper * @param Helper $helper + * @param BestSellersCollectionFactory $bestSellersCollectionFactory + * @param CheckoutSession $checkoutSession + * @param ProductRepositoryInterface $productRepository * @codeCoverageIgnore */ public function __construct( @@ -91,7 +103,9 @@ public function __construct( Visibility $productVisibility, CartHelper $cartHelper, Helper $helper, - BestSellersCollectionFactory $bestSellersCollectionFactory + BestSellersCollectionFactory $bestSellersCollectionFactory, + CheckoutSession $checkoutSession, + ProductRepositoryInterface $productRepository ) { $this->collectionFactory = $collectionFactory; @@ -102,6 +116,8 @@ public function __construct( $this->cartHelper = $cartHelper; $this->helper = $helper; $this->bestSellersCollectionFactory = $bestSellersCollectionFactory; + $this->checkoutSession = $checkoutSession; + $this->productRepository = $productRepository; $this->_initCollection(); } @@ -221,4 +237,59 @@ private function _bestSellerProducts() $this->collection->addIdFilter($productIds); } } + + /** + * Create collection with UpSelling products + */ + private function _upSellingProducts() + { + $productIds = []; + $product = $this->productRepository->getById($this->checkoutSession->getLastAddedProductId()); + $upSellProducts = $product->getUpSellProducts(); + + foreach ($upSellProducts as $upSellProduct) { + $productIds[] = $upSellProduct->getId(); + } + + if (empty($productIds)) { + $this->_randomProducts(); + } else { + $this->collection->addIdFilter($productIds); + } + } + + private function _relatedProducts() + { + $productIds = []; + $product = $this->productRepository->getById($this->checkoutSession->getLastAddedProductId()); + $relatedProducts = $product->getRelatedProducts(); + + foreach ($relatedProducts as $relatedProduct) { + $productIds[] = $relatedProduct->getId(); + } + + if (empty($productIds)) { + $this->_randomProducts(); + } else { + $this->collection->addIdFilter($productIds); + } + } + + private function _crossSellProducts() + { + $productIds = []; + $product = $this->productRepository->getById($this->checkoutSession->getLastAddedProductId()); + $crossSellProducts = $product->getCrossSellProducts(); + + foreach ($crossSellProducts as $crossSellProduct) { + $productIds[] = $crossSellProduct->getId(); + } + + if (empty($productIds)) { + $this->_randomProducts(); + } else { + $this->collection->addIdFilter($productIds); + } + } + } From 06863747d319fd9717069417899bac37f1f9347d Mon Sep 17 00:00:00 2001 From: bst2002git Date: Tue, 4 Aug 2020 16:27:05 +0200 Subject: [PATCH 2/9] add i18n Translation change popup content template --- composer.json | 2 +- popup-admin/Model/Config/Source/Carousel.php | 2 +- popup-display/CustomerData/PopupCartData.php | 52 +++++++++---------- popup-display/i18n/de_DE.csv | 7 +++ .../view/frontend/web/template/popup.html | 36 +++++++++---- 5 files changed, 61 insertions(+), 38 deletions(-) create mode 100644 popup-display/i18n/de_DE.csv diff --git a/composer.json b/composer.json index 9b9792a..a0c8878 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ ] }, "type": "magento2-metapackage", - "version": "1.0.0.1", + "version": "1.0.0.2", "authors": [ { "name": "Andresa Martins", diff --git a/popup-admin/Model/Config/Source/Carousel.php b/popup-admin/Model/Config/Source/Carousel.php index 1b6823b..e448c1d 100644 --- a/popup-admin/Model/Config/Source/Carousel.php +++ b/popup-admin/Model/Config/Source/Carousel.php @@ -24,7 +24,7 @@ public function toOptionArray() ['value' => '_bestSellerProducts', 'label' => __('Best Sellers')], ['value' => '_latestProducts', 'label' => __('Latest Products')], ['value' => '_randomProducts', 'label' => __('Random Products')], - ['value' => '_upSellingProducts', 'label' => __('Up-Sell Products')], + ['value' => '_upSellingProducts', 'label' => __('Up-Sell Products')], ['value' => '_relatedProducts', 'label' => __('Related Products')], ['value' => '_crossSellProducts', 'label' => __('Cross-Sell Products')] ]; diff --git a/popup-display/CustomerData/PopupCartData.php b/popup-display/CustomerData/PopupCartData.php index 2d065e6..d2219b3 100644 --- a/popup-display/CustomerData/PopupCartData.php +++ b/popup-display/CustomerData/PopupCartData.php @@ -29,7 +29,8 @@ */ class PopupCartData implements SectionSourceInterface { - const CONFIG_PRODUCT_LIMIT = 4; + //const CONFIG_PRODUCT_LIMIT = 4; + const CONFIG_PRODUCT_LIMIT = 2; const CONFIG_COLLECTION_TYPE = 'cartpopup/settings/product_carousel'; /** @@ -75,12 +76,12 @@ class PopupCartData implements SectionSourceInterface */ protected $bestSellersCollectionFactory; - /** + /** * @var \Magento\Checkout\Model\Session */ - protected $checkoutSession; + protected $checkoutSession; - protected $productRepository; + protected $productRepository; /** * @param CollectionFactory $collectionFactory @@ -90,9 +91,9 @@ class PopupCartData implements SectionSourceInterface * @param Visibility $productVisibility * @param CartHelper $cartHelper * @param Helper $helper - * @param BestSellersCollectionFactory $bestSellersCollectionFactory - * @param CheckoutSession $checkoutSession - * @param ProductRepositoryInterface $productRepository + * @param BestSellersCollectionFactory $bestSellersCollectionFactory + * @param CheckoutSession $checkoutSession + * @param ProductRepositoryInterface $productRepository * @codeCoverageIgnore */ public function __construct( @@ -104,8 +105,8 @@ public function __construct( CartHelper $cartHelper, Helper $helper, BestSellersCollectionFactory $bestSellersCollectionFactory, - CheckoutSession $checkoutSession, - ProductRepositoryInterface $productRepository + CheckoutSession $checkoutSession, + ProductRepositoryInterface $productRepository ) { $this->collectionFactory = $collectionFactory; @@ -116,8 +117,8 @@ public function __construct( $this->cartHelper = $cartHelper; $this->helper = $helper; $this->bestSellersCollectionFactory = $bestSellersCollectionFactory; - $this->checkoutSession = $checkoutSession; - $this->productRepository = $productRepository; + $this->checkoutSession = $checkoutSession; + $this->productRepository = $productRepository; $this->_initCollection(); } @@ -136,7 +137,6 @@ public function getSectionData() 'cartTotalCount' => $this->cartHelper->getSummaryCount(), 'products' => $this->_getCollection() ]; - return $output; } @@ -238,14 +238,14 @@ private function _bestSellerProducts() } } - /** + /** * Create collection with UpSelling products */ private function _upSellingProducts() { $productIds = []; - $product = $this->productRepository->getById($this->checkoutSession->getLastAddedProductId()); - $upSellProducts = $product->getUpSellProducts(); + $product = $this->productRepository->getById($this->checkoutSession->getLastAddedProductId()); + $upSellProducts = $product->getUpSellProducts(); foreach ($upSellProducts as $upSellProduct) { $productIds[] = $upSellProduct->getId(); @@ -258,11 +258,11 @@ private function _upSellingProducts() } } - private function _relatedProducts() - { - $productIds = []; - $product = $this->productRepository->getById($this->checkoutSession->getLastAddedProductId()); - $relatedProducts = $product->getRelatedProducts(); + private function _relatedProducts() + { + $productIds = []; + $product = $this->productRepository->getById($this->checkoutSession->getLastAddedProductId()); + $relatedProducts = $product->getRelatedProducts(); foreach ($relatedProducts as $relatedProduct) { $productIds[] = $relatedProduct->getId(); @@ -273,13 +273,13 @@ private function _relatedProducts() } else { $this->collection->addIdFilter($productIds); } - } + } - private function _crossSellProducts() - { + private function _crossSellProducts() + { $productIds = []; - $product = $this->productRepository->getById($this->checkoutSession->getLastAddedProductId()); - $crossSellProducts = $product->getCrossSellProducts(); + $product = $this->productRepository->getById($this->checkoutSession->getLastAddedProductId()); + $crossSellProducts = $product->getCrossSellProducts(); foreach ($crossSellProducts as $crossSellProduct) { $productIds[] = $crossSellProduct->getId(); @@ -290,6 +290,6 @@ private function _crossSellProducts() } else { $this->collection->addIdFilter($productIds); } - } + } } diff --git a/popup-display/i18n/de_DE.csv b/popup-display/i18n/de_DE.csv new file mode 100644 index 0000000..b2482a8 --- /dev/null +++ b/popup-display/i18n/de_DE.csv @@ -0,0 +1,7 @@ +"A new item has been added to your Shopping Cart. ","Der Artikel wurde Ihrem Warenkorb hinzugefügt. " +"You now have %s items in your Shopping Cart.","Sie haben %s Artikel in Ihrem Warenkorb." +"View Shopping Cart","Warenkorb ansehen" +"Continue Shopping","Mit dem Einkaufen fortfahren" +"Other Items You Might Be Interested In:","Das könnte Sie auch interessieren:" +Close,Schließen +"Incl. Tax, plus shipping","Inkl. MwSt., zzgl. Versand" diff --git a/popup-display/view/frontend/web/template/popup.html b/popup-display/view/frontend/web/template/popup.html index 66bcd11..e01eec8 100644 --- a/popup-display/view/frontend/web/template/popup.html +++ b/popup-display/view/frontend/web/template/popup.html @@ -19,21 +19,37 @@ +

-