This repository has been archived by the owner on Apr 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from richdynamix/release/0.2.0rc
release/0.2.0
- Loading branch information
Showing
11 changed files
with
428 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
<?php | ||
|
||
namespace Richdynamix\PersonalisedProducts\Block\Checkout\Cart; | ||
|
||
use \Magento\Catalog\Block\Product\Context; | ||
use \Magento\TargetRule\Model\ResourceModel\Index; | ||
use \Magento\TargetRule\Helper\Data; | ||
use \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory; | ||
use \Magento\Catalog\Model\Product\Visibility; | ||
use \Magento\CatalogInventory\Helper\Stock; | ||
use \Magento\Checkout\Model\Session; | ||
use \Magento\Catalog\Model\Product\LinkFactory; | ||
use \Magento\TargetRule\Model\IndexFactory; | ||
use \Magento\Catalog\Model\ProductTypes\ConfigInterface; | ||
use \Magento\Catalog\Api\ProductRepositoryInterface; | ||
use \Richdynamix\PersonalisedProducts\Helper\Config; | ||
use \Magento\TargetRule\Block\Checkout\Cart\Crosssell; | ||
use \Richdynamix\PersonalisedProducts\Model\Frontend\Checkout\Cart\Crosssell as CrosssellModel; | ||
use \Magento\Catalog\Model\ProductFactory as ProductFactory; | ||
use \Magento\Framework\Module\Manager as Manager; | ||
|
||
/** | ||
* Class TargetCrosssell | ||
* | ||
* @category Richdynamix | ||
* @package PersonalisedProducts | ||
* @author Steven Richardson ([email protected]) @mage_gizmo | ||
*/ | ||
class TargetCrosssell extends Crosssell | ||
{ | ||
/** | ||
* @var Config | ||
*/ | ||
private $_config; | ||
/** | ||
* @var CrosssellModel | ||
*/ | ||
private $_crosssell; | ||
/** | ||
* @var ProductFactory | ||
*/ | ||
private $_productFactory; | ||
/** | ||
* @var Manager | ||
*/ | ||
private $_moduleManager; | ||
|
||
/** | ||
* TargetCrosssell constructor. | ||
* @param Context $context | ||
* @param Index $index | ||
* @param Data $targetRuleData | ||
* @param CollectionFactory $productCollectionFactory | ||
* @param Visibility $visibility | ||
* @param Stock $stockHelper | ||
* @param Session $session | ||
* @param LinkFactory $productLinkFactory | ||
* @param IndexFactory $indexFactory | ||
* @param ConfigInterface $productTypeConfig | ||
* @param ProductRepositoryInterface $productRepository | ||
* @param Config $config | ||
* @param CrosssellModel $crosssell | ||
* @param ProductFactory $productFactory | ||
* @param Manager $moduleManager | ||
* @param array $data | ||
*/ | ||
public function __construct( | ||
Context $context, | ||
Index $index, | ||
Data $targetRuleData, | ||
CollectionFactory $productCollectionFactory, | ||
Visibility $visibility, | ||
Stock $stockHelper, | ||
Session $session, | ||
LinkFactory $productLinkFactory, | ||
IndexFactory $indexFactory, | ||
ConfigInterface $productTypeConfig, | ||
ProductRepositoryInterface $productRepository, | ||
Config $config, | ||
CrosssellModel $crosssell, | ||
ProductFactory $productFactory, | ||
Manager $moduleManager, | ||
array $data = [] | ||
) { | ||
$this->_config = $config; | ||
$this->_crosssell = $crosssell; | ||
$this->_productFactory = $productFactory; | ||
$this->_moduleManager = $moduleManager; | ||
parent::__construct( | ||
$context, | ||
$index, | ||
$targetRuleData, | ||
$productCollectionFactory, | ||
$visibility, | ||
$stockHelper, | ||
$session, | ||
$productLinkFactory, | ||
$indexFactory, | ||
$productTypeConfig, | ||
$productRepository, | ||
$data | ||
); | ||
} | ||
|
||
/** | ||
* Get the crossell items for the basket page | ||
* Rewrites the target rules for Enterprise edition | ||
* | ||
* @return array | ||
*/ | ||
public function getItemCollection() | ||
{ | ||
if (!$this->_config->isEnabled() || !$this->_config->getItem(Config::COMPLEMENTARY_REPLACE_RULES)) { | ||
return parent::getItemCollection(); | ||
} | ||
|
||
$personalisedIds = $this->_crosssell->getProductCollection(); | ||
if (!$personalisedIds) { | ||
return parent::getItemCollection(); | ||
} | ||
|
||
$collection = $this->_crosssell->getPersonalisedProductCollection($personalisedIds); | ||
|
||
if ($this->_moduleManager->isEnabled('Magento_Checkout')) { | ||
$this->_addProductAttributesAndPrices($collection); | ||
} | ||
|
||
$this->_items = []; | ||
foreach ($collection as $item) { | ||
$this->_items[] = $item; | ||
} | ||
|
||
return $this->_items; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
<?php | ||
|
||
namespace Richdynamix\PersonalisedProducts\Block\Product\ProductList; | ||
|
||
use \Magento\TargetRule\Block\Catalog\Product\ProductList\Upsell; | ||
use \Magento\Catalog\Block\Product\Context; | ||
use \Magento\TargetRule\Model\ResourceModel\Index; | ||
use \Magento\TargetRule\Helper\Data; | ||
use \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory; | ||
use \Magento\Catalog\Model\Product\Visibility; | ||
use \Magento\TargetRule\Model\IndexFactory; | ||
use \Magento\Framework\Module\Manager as Manager; | ||
use \Magento\Checkout\Model\Cart; | ||
use \Richdynamix\PersonalisedProducts\Helper\Config; | ||
use \Richdynamix\PersonalisedProducts\Model\Frontend\Catalog\Product\ProductList\Upsell as UpsellModel; | ||
|
||
/** | ||
* Rewrite target rule product upsell block in enterprise edition | ||
* to switch out product collection for one returned from PredictionIO | ||
* | ||
* @category Richdynamix | ||
* @package PersonalisedProducts | ||
* @author Steven Richardson ([email protected]) @mage_gizmo | ||
*/ | ||
class TargetUpsell extends Upsell | ||
{ | ||
/** | ||
* @var Cart | ||
*/ | ||
protected $_cart; | ||
/** | ||
* @var Config | ||
*/ | ||
protected $_config; | ||
/** | ||
* @var UpsellModel | ||
*/ | ||
protected $_upsell; | ||
/** | ||
* @var Manager | ||
*/ | ||
protected $_moduleManager; | ||
|
||
/** | ||
* @param Context $context | ||
* @param Index $index | ||
* @param Data $targetRuleData | ||
* @param CollectionFactory $productCollectionFactory | ||
* @param Visibility $visibility | ||
* @param IndexFactory $indexFactory | ||
* @param Cart $cart | ||
* @param Config $config | ||
* @param UpsellModel $upsell | ||
* @param Manager $moduleManager | ||
*/ | ||
public function __construct( | ||
Context $context, | ||
Index $index, | ||
Data $targetRuleData, | ||
CollectionFactory $productCollectionFactory, | ||
Visibility $visibility, | ||
IndexFactory $indexFactory, | ||
Cart $cart, | ||
Config $config, | ||
UpsellModel $upsell, | ||
Manager $moduleManager | ||
) { | ||
$this->_cart = $cart; | ||
$this->_config = $config; | ||
$this->_upsell = $upsell; | ||
$this->_moduleManager = $moduleManager; | ||
parent::__construct( | ||
$context, | ||
$index, | ||
$targetRuleData, | ||
$productCollectionFactory, | ||
$visibility, | ||
$indexFactory, | ||
$cart | ||
); | ||
} | ||
|
||
/** | ||
* Rewrite parent getAllItems method to use PredictionIO results when available | ||
* Rewrites the target rules for Enterprise edition | ||
* | ||
* @return array | ||
*/ | ||
public function getAllItems() | ||
{ | ||
if (!$this->_config->isEnabled() || !$this->_config->getItem(Config::SIMILARITY_REPLACE_RULES)) { | ||
return parent::getAllItems(); | ||
} | ||
|
||
$product = $this->_coreRegistry->registry('product'); | ||
$categoryIds = $this->_upsell->getCategoryIds($product); | ||
$personalisedIds = $this->_upsell->getProductCollection([$product->getId()], $categoryIds); | ||
|
||
if (!$personalisedIds) { | ||
return parent::getAllItems(); | ||
} | ||
|
||
$collection = $this->_upsell->getPersonalisedProductCollection($personalisedIds); | ||
|
||
if ($this->_moduleManager->isEnabled('Magento_Checkout')) { | ||
$this->_addProductAttributesAndPrices($collection); | ||
} | ||
|
||
$items = []; | ||
foreach ($collection as $product) { | ||
$product->setDoNotUseCategoryId(true); | ||
$items[] = $product; | ||
} | ||
|
||
return $items; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.