Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
2806d48
Add DB schema
Usik2203 Jul 8, 2020
da43047
add list_id during comparing products
Usik2203 Jul 8, 2020
2fe99e9
set customer for compare list during login
Usik2203 Jul 16, 2020
fb69971
Merge branch '2.4-develop' into compare-products
Usik2203 Aug 12, 2020
1fd3c5b
changes based on review
Usik2203 Aug 12, 2020
330c200
started working on compared list graphql modules
Usik2203 Aug 12, 2020
339a1a0
added resolver for getting compare list by id
Usik2203 Aug 17, 2020
d24e544
add remove and assign functionality
Usik2203 Aug 17, 2020
0abdc60
Merge branch '2.4-develop' into compare-products
Usik2203 Aug 17, 2020
a9ea92a
separated some logic
Usik2203 Aug 21, 2020
907877b
have decoupled some resolvers
Usik2203 Aug 21, 2020
e7e6f16
Merge branch '2.4-develop' into compare-products
Usik2203 Oct 3, 2020
3dceba9
Added changes to schema and add some class
Usik2203 Oct 3, 2020
571a73e
set type list_id as varchar in DB
Usik2203 Oct 3, 2020
a8fe53f
add changes to DB scheme
Usik2203 Oct 5, 2020
79eea2b
Extract list id to list_id_mask table
Usik2203 Oct 14, 2020
5f4fd9f
reverted changes
Usik2203 Oct 14, 2020
8be68b4
create compare list
Usik2203 Oct 14, 2020
c981564
added resolver
Usik2203 Oct 14, 2020
b03318a
rename classes
Usik2203 Oct 14, 2020
5e69a51
Refactoring resolvers
Usik2203 Oct 15, 2020
40d5bf6
removing product from compare list and compare list
Usik2203 Oct 16, 2020
eb4de34
fix static issues
Usik2203 Oct 16, 2020
94a9cdd
Merge branch '2.4-develop' into compare-products
Usik2203 Oct 16, 2020
261e00c
static issue fixes
Usik2203 Oct 17, 2020
89d77bb
changes in DB scheme
Usik2203 Oct 17, 2020
48197d4
Minor changes in schema
Usik2203 Oct 21, 2020
058e329
Merge branch '2.4-develop' into compare-products
Usik2203 Oct 21, 2020
455a28e
Add changes after schema updating
Usik2203 Oct 26, 2020
d436687
Add test coverage
Usik2203 Oct 26, 2020
b4a0ab6
Merge branch '2.4-develop' into compare-products
Usik2203 Oct 27, 2020
880e454
add new scenario to test coverage
Usik2203 Oct 28, 2020
bdbdddd
Merge branch '2.4-develop' into compare-products
Usik2203 Nov 2, 2020
0c34fd6
Merge branch '2.4-develop' into compare-products
Usik2203 Nov 3, 2020
193702b
Fixed failed test due to ProductInterface in schema
Usik2203 Nov 4, 2020
2857996
CR recommendations
Usik2203 Nov 4, 2020
1ec40b0
Removed list id mask table
Usik2203 Nov 6, 2020
8780f66
add additional check
Usik2203 Nov 6, 2020
dd5b443
luma compatibility add list id for customer compare list
Usik2203 Nov 6, 2020
2e48ca1
luma compatibility remove compare list
Usik2203 Nov 6, 2020
098a407
minor changes
Usik2203 Nov 7, 2020
32f251f
Merge remote-tracking branch 'mainline/2.4-develop' into compare-prod…
prabhuram93 Nov 10, 2020
b21be30
- Modified assigncomparelust output to match schema in architecture
prabhuram93 Nov 11, 2020
e4043da
Merge remote-tracking branch 'mainline/2.4-develop' into compare-prod…
prabhuram93 Nov 11, 2020
27a592c
- Updated assigncomparelist impl
prabhuram93 Nov 12, 2020
7124f66
Merge remote-tracking branch 'mainline/2.4-develop' into compare-prod…
prabhuram93 Nov 12, 2020
d7e1568
Merge commit 'b21be308c2a369bcbcde2db5921faaf8b2b237af' into compare-…
prabhuram93 Nov 12, 2020
5f7ad0e
Merge commit '27a592cf38b501bcf05d9ef2e5401a9cff7e986b' into compare-…
prabhuram93 Nov 12, 2020
923c723
Update schema description
Usik2203 Nov 13, 2020
34790b0
minor changes
Usik2203 Nov 13, 2020
6474eaa
Merge branch '2.4-develop' into compare-products
Usik2203 Nov 13, 2020
a9cffd6
changes in composer.json
Usik2203 Nov 13, 2020
93f7d44
Merge branch '2.4-develop' into compare-products
Usik2203 Nov 13, 2020
ce4fc73
Update app/code/Magento/CompareListGraphQl/etc/module.xml
Usik2203 Nov 16, 2020
a99515d
Merge branch '2.4-develop' into compare-products
Usik2203 Nov 16, 2020
e90810a
compare-products - Fixed errors on creating comparelist and adding pr…
prabhuram93 Nov 18, 2020
8aadac8
MC-37399: Product Compare :: Atwix PR review and delivery
dthampy Nov 19, 2020
058a0be
Update app/code/Magento/CompareListGraphQl/etc/schema.graphqls
Usik2203 Nov 23, 2020
9640f32
Update app/code/Magento/CompareListGraphQl/etc/schema.graphqls
Usik2203 Nov 23, 2020
270649c
Merge branch '2.4-develop' into compare-products
Usik2203 Nov 23, 2020
2b144f9
Merge remote-tracking branch 'mainline/2.4-develop' into compare-prod…
prabhuram93 Nov 23, 2020
28232a7
Merge remote-tracking branch 'usik/compare-products' into compare-pro…
prabhuram93 Nov 25, 2020
600bcac
Merge branch '2.4-develop' into compare-products
Usik2203 Nov 27, 2020
4d11de7
Merge remote-tracking branch 'mainline/2.4-develop' into compare-prod…
prabhuram93 Nov 30, 2020
c53a3cf
Merge remote-tracking branch 'usik/compare-products' into compare-pro…
prabhuram93 Nov 30, 2020
5cd7d07
Merge remote-tracking branch 'mainline/2.4-develop' into compare-prod…
prabhuram93 Dec 1, 2020
17ed57e
- Updated constraints on the catalog_compare_list table
prabhuram93 Dec 1, 2020
afb1581
Removing additional calls to the db.
prabhuram93 Dec 2, 2020
b2a1894
Merge branch '2.4-develop' into compare-products
Usik2203 Dec 3, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions app/code/Magento/Catalog/Model/CompareList.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

declare(strict_types=1);

namespace Magento\Catalog\Model;

use Magento\Framework\Model\AbstractModel;

class CompareList extends AbstractModel
{
/**
* Initialize resource
*
* @return void
*/
protected function _construct()
{
$this->_init(\Magento\Catalog\Model\ResourceModel\CompareList::class);
}
}
154 changes: 154 additions & 0 deletions app/code/Magento/Catalog/Model/Product/Compare/AddToList.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

declare(strict_types=1);

namespace Magento\Catalog\Model\Product\Compare;

use Magento\Catalog\Model\CompareList;
use Magento\Catalog\Model\CompareListFactory;
use Magento\Catalog\Model\ResourceModel\CompareList as CompareListResource;
use Magento\Customer\Model\Session;
use Magento\Customer\Model\Visitor;

class AddToList
{
/**
* @var CompareListFactory
*/
private $compareListFactory;

/**
* @var CompareList
*/
private $compareList;

/**
* @var CompareListResource
*/
private $compareListResource;

/**
* Customer session
*
* @var Session
*/
private $customerSession;

/**
* Customer visitor
*
* @var Visitor
*/
private $customerVisitor;

/**
* @param CompareListFactory $compareListFactory
* @param CompareList $compareList
* @param CompareListResource $compareListResource
* @param Session $customerSession
* @param Visitor $customerVisitor
*/
public function __construct(
CompareListFactory $compareListFactory,
CompareList $compareList,
CompareListResource $compareListResource,
Session $customerSession,
Visitor $customerVisitor
) {
$this->compareListFactory = $compareListFactory;
$this->compareList = $compareList;
$this->compareListResource = $compareListResource;
$this->customerSession = $customerSession;
$this->customerVisitor = $customerVisitor;
}

/**
* Get list_id
*
* @return int
*/
public function execute()
{
if ($this->customerSession->isLoggedIn()) {
return $this->getListIdByCustomerId();
}

return $this->getListIdByVisitorId();
}

/**
* Set customer from visitor
*/
public function setCustomerFromVisitor()
{
$customerId = $this->customerSession->getCustomerId();

if (!$customerId) {
return $this;
}

$visitorId = $this->customerVisitor->getId();
$compareListModel = $this->compareListFactory->create();
$this->compareListResource->load($compareListModel, $visitorId, 'visitor_id');
$compareListModel->setCustomerId($customerId);
$compareListModel->save();
}

/**
* Get list_id for visitor
*
* @return int
*/
private function getListIdByVisitorId()
{
$visitorId = $this->customerVisitor->getId();
$compareListModel = $this->compareListFactory->create();
$this->compareListResource->load($compareListModel, $visitorId, 'visitor_id');
if ($compareListId = $compareListModel->getId()) {
return (int)$compareListId;
}

return $this->createCompareList($visitorId, null);
}

/**
* Get list_id for logged customers
*
* @return int
*/
private function getListIdByCustomerId()
{
$customerId = $this->customerSession->getCustomerId();
$compareListModel = $this->compareListFactory->create();
$this->compareListResource->load($compareListModel, $customerId, 'customer_id');

if ($compareListId = $compareListModel->getId()) {
return (int)$compareListId;
}

return $this->createCompareList(0, $customerId);
}

/**
* Create new compare list
*
* @param $visitorId
* @param $customerId
*
* @return int
*/
private function createCompareList($visitorId, $customerId)
{
/* @var $compareList CompareList */
$compareList = $this->compareListFactory->create();
$compareList->setVisitorId($visitorId);
$compareList->setCustomerId($customerId);
$compareList->save();

return (int)$compareList->getId();
}
}
10 changes: 10 additions & 0 deletions app/code/Magento/Catalog/Model/Product/Compare/ListCompare.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ class ListCompare extends \Magento\Framework\DataObject
*/
private $productRepository;

/**
* @var AddToList
*/
private $addToCompareList;

/**
* Constructor
*
Expand All @@ -68,6 +73,7 @@ class ListCompare extends \Magento\Framework\DataObject
* @param \Magento\Catalog\Model\ResourceModel\Product\Compare\Item $catalogProductCompareItem
* @param \Magento\Customer\Model\Session $customerSession
* @param \Magento\Customer\Model\Visitor $customerVisitor
* @param \Magento\Catalog\Model\Product\Compare\AddToList
* @param array $data
* @param ProductRepository|null $productRepository
*/
Expand All @@ -77,6 +83,7 @@ public function __construct(
\Magento\Catalog\Model\ResourceModel\Product\Compare\Item $catalogProductCompareItem,
\Magento\Customer\Model\Session $customerSession,
\Magento\Customer\Model\Visitor $customerVisitor,
\Magento\Catalog\Model\Product\Compare\AddToList $addToList,
array $data = [],
ProductRepository $productRepository = null
) {
Expand All @@ -85,6 +92,7 @@ public function __construct(
$this->_catalogProductCompareItem = $catalogProductCompareItem;
$this->_customerSession = $customerSession;
$this->_customerVisitor = $customerVisitor;
$this->addToCompareList = $addToList;
$this->productRepository = $productRepository ?: ObjectManager::getInstance()->create(ProductRepository::class);
parent::__construct($data);
}
Expand All @@ -102,9 +110,11 @@ public function addProduct($product)
$item = $this->_compareItemFactory->create();
$this->_addVisitorToItem($item);
$item->loadByProduct($product);
$listId = $this->addToCompareList->execute();

if (!$item->getId() && $this->productExists($product)) {
$item->addProductData($product);
$item->setListId($listId);
$item->save();
}

Expand Down
23 changes: 23 additions & 0 deletions app/code/Magento/Catalog/Model/ResourceModel/CompareList.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

declare(strict_types=1);

namespace Magento\Catalog\Model\ResourceModel;

use Magento\Framework\Model\ResourceModel\Db\AbstractDb;


class CompareList extends AbstractDb
{
/**
* @inheritdoc
*/
protected function _construct()
{
$this->_init('catalog_compare_list', 'list_id');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,21 @@
*/
namespace Magento\Catalog\Model\ResourceModel\Product\Compare;

use Magento\Catalog\Model\Product\Compare\AddToList;
use Magento\Framework\Model\ResourceModel\Db\Context;

/**
* Catalog compare item resource model
*
* @author Magento Core Team <core@magentocommerce.com>
*/
class Item extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
{
/**
* @var AddToList
*/
private $compareList;

/**
* Initialize connection
*
Expand All @@ -22,6 +30,20 @@ protected function _construct()
$this->_init('catalog_compare_item', 'catalog_compare_item_id');
}

/**
* @param AddToList $addToList
* @param Context $context
* @param null $connectionName
*/
public function __construct(
AddToList $addToList,
Context $context,
$connectionName = null
) {
$this->compareList = $addToList;
parent::__construct($context, $connectionName);
}

/**
* Load object by product
*
Expand Down Expand Up @@ -213,6 +235,7 @@ public function updateCustomerFromVisitor($object)
$this->getConnection()->quoteInto($this->getIdFieldName() . '=?', $itemId)
);
}
$this->compareList->setCustomerFromVisitor();
}

return $this;
Expand Down
25 changes: 25 additions & 0 deletions app/code/Magento/Catalog/etc/db_schema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,8 @@
default="0" comment="Product ID"/>
<column xsi:type="smallint" name="store_id" unsigned="true" nullable="true" identity="false"
comment="Store ID"/>
<column xsi:type="int" name="list_id" padding="10" unsigned="true" nullable="false" identity="false"
comment="List ID"/>
<constraint xsi:type="primary" referenceId="PRIMARY">
<column name="catalog_compare_item_id"/>
</constraint>
Expand All @@ -558,6 +560,8 @@
referenceColumn="entity_id" onDelete="CASCADE"/>
<constraint xsi:type="foreign" referenceId="CATALOG_COMPARE_ITEM_STORE_ID_STORE_STORE_ID" table="catalog_compare_item"
column="store_id" referenceTable="store" referenceColumn="store_id" onDelete="SET NULL"/>
<constraint xsi:type="foreign" referenceId="CATALOG_COMPARE_ITEM_LIST_ID_CATALOG_COMPARE_LIST_LIST_ID" table="catalog_compare_item"
column="list_id" referenceTable="catalog_compare_list" referenceColumn="list_id" onDelete="CASCADE"/>
<index referenceId="CATALOG_COMPARE_ITEM_PRODUCT_ID" indexType="btree">
<column name="product_id"/>
</index>
Expand All @@ -573,6 +577,27 @@
<column name="store_id"/>
</index>
</table>
<table name="catalog_compare_list" resource="default" engine="innodb" comment="Catalog Compare List with hash Table">
<column xsi:type="int" name="list_id" padding="10" unsigned="true" nullable="false"
identity="true" comment="Compare List ID"/>
<column xsi:type="int" name="visitor_id" unsigned="true" nullable="false" identity="false"
default="0" comment="Visitor ID"/>
<column xsi:type="int" name="customer_id" padding="10" unsigned="true" nullable="true" identity="false"
comment="Customer ID"/>
<constraint xsi:type="primary" referenceId="PRIMARY">
<column name="list_id"/>
</constraint>
<constraint xsi:type="foreign" referenceId="CATALOG_COMPARE_LIST_CUSTOMER_ID_CUSTOMER_ENTITY_ENTITY_ID"
table="catalog_compare_list" column="customer_id" referenceTable="customer_entity"
referenceColumn="entity_id" onDelete="CASCADE"/>
<index referenceId="CATALOG_COMPARE_LIST_LIST_ID" indexType="btree">
<column name="list_id"/>
</index>
<index referenceId="CATALOG_COMPARE_LIST_VISITOR_ID_CUSTOMER_ID" indexType="btree">
<column name="visitor_id"/>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Usik2203 Why do we need the visitor_id? How is it being generated for a GraphQl client?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @prabhuram93
visitor_id it's value come from table customer_visitor field visitor_id
It need for detecting what compare list should remove or add to compare list for guest users

Scenario: https://drive.google.com/file/d/1jfEdoXa4tArU7z1rhSHgZX08Gxr4DzQL/view?usp=sharing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UPD
@prabhuram93
I have got rid from visitor_id field in DB as redundant after applying changes based on new schema
Thanks

<column name="customer_id"/>
</index>
</table>
<table name="catalog_product_website" resource="default" engine="innodb"
comment="Catalog Product To Website Linkage Table">
<column xsi:type="int" name="product_id" unsigned="true" nullable="false" identity="false"
Expand Down
23 changes: 20 additions & 3 deletions app/code/Magento/Catalog/etc/db_schema_whitelist.json
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,8 @@
"visitor_id": true,
"customer_id": true,
"product_id": true,
"store_id": true
"store_id": true,
"list_id": true
},
"index": {
"CATALOG_COMPARE_ITEM_PRODUCT_ID": true,
Expand All @@ -320,7 +321,8 @@
"PRIMARY": true,
"CATALOG_COMPARE_ITEM_CUSTOMER_ID_CUSTOMER_ENTITY_ENTITY_ID": true,
"CATALOG_COMPARE_ITEM_PRODUCT_ID_CATALOG_PRODUCT_ENTITY_ENTITY_ID": true,
"CATALOG_COMPARE_ITEM_STORE_ID_STORE_STORE_ID": true
"CATALOG_COMPARE_ITEM_STORE_ID_STORE_STORE_ID": true,
"CATALOG_COMPARE_ITEM_LIST_ID_CATALOG_COMPARE_LIST_LIST_ID": true
}
},
"catalog_product_website": {
Expand Down Expand Up @@ -1122,5 +1124,20 @@
"CATALOG_PRODUCT_FRONTEND_ACTION_VISITOR_ID_PRODUCT_ID_TYPE_ID": true,
"CATALOG_PRODUCT_FRONTEND_ACTION_CUSTOMER_ID_PRODUCT_ID_TYPE_ID": true
}
},
"catalog_compare_list": {
"column": {
"list_id": true,
"visitor_id": true,
"customer_id": true
},
"index": {
"CATALOG_COMPARE_LIST_LIST_ID": true,
"CATALOG_COMPARE_LIST_VISITOR_ID_CUSTOMER_ID": true
},
"constraint": {
"PRIMARY": true,
"CATALOG_COMPARE_LIST_CUSTOMER_ID_CUSTOMER_ENTITY_ENTITY_ID": true
}
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @Usik2203
Thank you for your contribution

Please don't forget to add a new line at end of file

Suggested change
}
}

Copy link
Contributor Author

@Usik2203 Usik2203 Nov 13, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file was generated by Magento .
It seems bad idea add empty line at end of the file.
Thanks