-
Notifications
You must be signed in to change notification settings - Fork 9.4k
[GraphQL] Compare products #29047
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[GraphQL] Compare products #29047
Changes from 3 commits
2806d48
da43047
2fe99e9
fb69971
1fd3c5b
330c200
339a1a0
d24e544
0abdc60
a9ea92a
907877b
e7e6f16
3dceba9
571a73e
a8fe53f
79eea2b
5f4fd9f
8be68b4
c981564
b03318a
5e69a51
40d5bf6
eb4de34
94a9cdd
261e00c
89d77bb
48197d4
058e329
455a28e
d436687
b4a0ab6
880e454
bdbdddd
0c34fd6
193702b
2857996
1ec40b0
8780f66
dd5b443
2e48ca1
098a407
32f251f
b21be30
e4043da
27a592c
7124f66
d7e1568
5f7ad0e
923c723
34790b0
6474eaa
a9cffd6
93f7d44
ce4fc73
a99515d
e90810a
8aadac8
058a0be
9640f32
270649c
2b144f9
28232a7
600bcac
4d11de7
c53a3cf
5cd7d07
17ed57e
afb1581
b2a1894
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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); | ||
| } | ||
| } |
| 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 | ||
Usik2203 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| /** | ||
| * @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() | ||
Usik2203 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| $customerId = $this->customerSession->getCustomerId(); | ||
Usik2203 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| 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(); | ||
| } | ||
| } | ||
| 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; | ||
|
|
||
|
|
||
Usik2203 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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 |
|---|---|---|
|
|
@@ -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> | ||
|
|
@@ -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> | ||
|
|
@@ -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"/> | ||
|
||
| <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" | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -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, | ||||||||
|
|
@@ -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": { | ||||||||
|
|
@@ -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 | ||||||||
| } | ||||||||
| } | ||||||||
| } | ||||||||
| } | ||||||||
|
||||||||
| } | |
| } | |
There was a problem hiding this comment.
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
Uh oh!
There was an error while loading. Please reload this page.