I want to filter the products, listed on a particular category page by an attribute valueProduct Image on category view not updated with new imageMagento 2 : Static blocks with products on category landing pageFilter product search by categoryIs it possible to filter products in the admin catalog by Category in Magento 2?Filter by attribute doesn't bring any productsMagento 2: How to show New Products in a particular Category?Resolved: How to exclude specific attributes's values products in category product listing page?Magento 2: Filter by custom product/category attribute returns 0 resultsMagento 2.2.5 get the product collection without Stock dataHow can I remove the category filter from category page that do not have further any categories?How to filter products by discount percentage on category page?
How important are the Author's mood and feelings for writing a story?
"This used to be my phone number"
Why should fork() have been designed to return a file descriptor?
Why are flying carpets banned while flying brooms are not?
Why teach C using scanf without talking about command line arguments?
Do higher dimensions have axes?
Counting multiples of 3 up to a given number
Locked-up DOS computer beeped on keypress. What mechanism caused that?
How should I interpret a promising preprint that was never published in a peer-reviewed journal?
Why would word of Princess Leia's capture generate sympathy for the Rebellion in the Senate?
How to get a type of "screech" on guitar
When a ball on a rope swings in a circle, is there both centripetal force and tension force?
What makes MOVEQ quicker than a normal MOVE in 68000 assembly?
Authorship dispute on a paper that came out of a final report of a course?
Could a US citizen born through "birth tourism" become President?
Get Chord Name From a Given Set of Notes
Inside Out and Back to Front
Are there any satellites in geosynchronous but not geostationary orbits?
Why don't humans perceive sound waves as twice the frequency they are?
You have no, but can try for yes
Is encryption still applied if you ignore the SSL certificate warning for self-signed certs?
Applying for jobs with an obvious scar
Simplest instruction set that has an c++/C compiler to write an emulator for?
Why is carrying a heavy object more taxing on the body than pushing the same object on wheels?
I want to filter the products, listed on a particular category page by an attribute value
Product Image on category view not updated with new imageMagento 2 : Static blocks with products on category landing pageFilter product search by categoryIs it possible to filter products in the admin catalog by Category in Magento 2?Filter by attribute doesn't bring any productsMagento 2: How to show New Products in a particular Category?Resolved: How to exclude specific attributes's values products in category product listing page?Magento 2: Filter by custom product/category attribute returns 0 resultsMagento 2.2.5 get the product collection without Stock dataHow can I remove the category filter from category page that do not have further any categories?How to filter products by discount percentage on category page?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I want to filter the product collection on a category page by the user_id of the current user. I have created an attribute 'user_id' which is linked to the product when it is created with the current id of the user(here products are created by the user). I have created a category 'User Products' also when directed to userproducts.html all the products are shown, I want to filter it by user_id of the current user.
Edit 1.
I tried overriding catalog_category_view in my module as suggested by @MohitRane but it is not loading from my module. This is the screenshot
magento2
add a comment |
I want to filter the product collection on a category page by the user_id of the current user. I have created an attribute 'user_id' which is linked to the product when it is created with the current id of the user(here products are created by the user). I have created a category 'User Products' also when directed to userproducts.html all the products are shown, I want to filter it by user_id of the current user.
Edit 1.
I tried overriding catalog_category_view in my module as suggested by @MohitRane but it is not loading from my module. This is the screenshot
magento2
Update your code such that it will be easy to debug..
– aravind
Jul 11 at 14:01
add a comment |
I want to filter the product collection on a category page by the user_id of the current user. I have created an attribute 'user_id' which is linked to the product when it is created with the current id of the user(here products are created by the user). I have created a category 'User Products' also when directed to userproducts.html all the products are shown, I want to filter it by user_id of the current user.
Edit 1.
I tried overriding catalog_category_view in my module as suggested by @MohitRane but it is not loading from my module. This is the screenshot
magento2
I want to filter the product collection on a category page by the user_id of the current user. I have created an attribute 'user_id' which is linked to the product when it is created with the current id of the user(here products are created by the user). I have created a category 'User Products' also when directed to userproducts.html all the products are shown, I want to filter it by user_id of the current user.
Edit 1.
I tried overriding catalog_category_view in my module as suggested by @MohitRane but it is not loading from my module. This is the screenshot
magento2
magento2
edited Jul 11 at 14:34
Sidharth Satheesh
asked Jul 11 at 10:28
Sidharth SatheeshSidharth Satheesh
164 bronze badges
164 bronze badges
Update your code such that it will be easy to debug..
– aravind
Jul 11 at 14:01
add a comment |
Update your code such that it will be easy to debug..
– aravind
Jul 11 at 14:01
Update your code such that it will be easy to debug..
– aravind
Jul 11 at 14:01
Update your code such that it will be easy to debug..
– aravind
Jul 11 at 14:01
add a comment |
1 Answer
1
active
oldest
votes
You can do this by following code,
<?php
namespace VendorModuleBlock;
class Test extends MagentoFrameworkViewElementTemplate
protected $_productCollectionFactory;
protected $_session;
protected $_customerFactory;
public function __construct(
MagentoBackendBlockTemplateContext $context,
MagentoCatalogModelResourceModelProductCollectionFactory $productCollectionFactory,
MagentoCustomerModelCustomerFactory $customerFactory,
MagentoCustomerModelSession $session,
array $data = []
)
$this->_productCollectionFactory = $productCollectionFactory;
$this->_customerFactory = $customerFactory;
$this->_session = $session;
parent::__construct($context, $data);
public function getCustomerId()
if ($this->_session->isLoggedIn())
return $this->_session->getCustomer()->getId();
public function getProductCollection()
$userId = $this->getCustomerId();
if (!empty($userId))
/*$customerCollection = $this->_customerFactory->create()
->getCollection()
->addAttributeToSelect("*")
->load(); */
$productCollection = $this->_productCollectionFactory->create();
$productCollection->addAttributeToSelect('*')
->addAttributeToFilter(
'user_id',
array('eq' => $userId)
); // user_id is your attribute name
return $productCollection;
Add
view/frontend/layout/catalog_category_view.xml
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="category.products.list">
<block class="NamespaceModulenameBlockTest" name="my.block.name" template="Namespace_Modulename::product/list.phtml" />
</referenceContainer>
</body>
</page>
copy this
list.phtml
file from
vendor/magento/module-catalog/view/frontend/templates/product/list.phtml
to
view/frontend/templates/product/list.phtml
Where should I be calling getProductCollection(); ? I need to list these products in a page Being new to Magento, excuse my level of knowledge
– Sidharth Satheesh
Jul 11 at 12:47
I did the above things in my module, but the list is not loading from my module. My module name is Faes_CCEngine.
– Sidharth Satheesh
Jul 11 at 13:53
Please check screenshots
– Sidharth Satheesh
Jul 11 at 14:00
okay i will look into it
– Mohit Rane
Jul 11 at 14:01
Hi, any updates? @MohitRane
– Sidharth Satheesh
Jul 12 at 3:14
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "479"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f281712%2fi-want-to-filter-the-products-listed-on-a-particular-category-page-by-an-attrib%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can do this by following code,
<?php
namespace VendorModuleBlock;
class Test extends MagentoFrameworkViewElementTemplate
protected $_productCollectionFactory;
protected $_session;
protected $_customerFactory;
public function __construct(
MagentoBackendBlockTemplateContext $context,
MagentoCatalogModelResourceModelProductCollectionFactory $productCollectionFactory,
MagentoCustomerModelCustomerFactory $customerFactory,
MagentoCustomerModelSession $session,
array $data = []
)
$this->_productCollectionFactory = $productCollectionFactory;
$this->_customerFactory = $customerFactory;
$this->_session = $session;
parent::__construct($context, $data);
public function getCustomerId()
if ($this->_session->isLoggedIn())
return $this->_session->getCustomer()->getId();
public function getProductCollection()
$userId = $this->getCustomerId();
if (!empty($userId))
/*$customerCollection = $this->_customerFactory->create()
->getCollection()
->addAttributeToSelect("*")
->load(); */
$productCollection = $this->_productCollectionFactory->create();
$productCollection->addAttributeToSelect('*')
->addAttributeToFilter(
'user_id',
array('eq' => $userId)
); // user_id is your attribute name
return $productCollection;
Add
view/frontend/layout/catalog_category_view.xml
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="category.products.list">
<block class="NamespaceModulenameBlockTest" name="my.block.name" template="Namespace_Modulename::product/list.phtml" />
</referenceContainer>
</body>
</page>
copy this
list.phtml
file from
vendor/magento/module-catalog/view/frontend/templates/product/list.phtml
to
view/frontend/templates/product/list.phtml
Where should I be calling getProductCollection(); ? I need to list these products in a page Being new to Magento, excuse my level of knowledge
– Sidharth Satheesh
Jul 11 at 12:47
I did the above things in my module, but the list is not loading from my module. My module name is Faes_CCEngine.
– Sidharth Satheesh
Jul 11 at 13:53
Please check screenshots
– Sidharth Satheesh
Jul 11 at 14:00
okay i will look into it
– Mohit Rane
Jul 11 at 14:01
Hi, any updates? @MohitRane
– Sidharth Satheesh
Jul 12 at 3:14
add a comment |
You can do this by following code,
<?php
namespace VendorModuleBlock;
class Test extends MagentoFrameworkViewElementTemplate
protected $_productCollectionFactory;
protected $_session;
protected $_customerFactory;
public function __construct(
MagentoBackendBlockTemplateContext $context,
MagentoCatalogModelResourceModelProductCollectionFactory $productCollectionFactory,
MagentoCustomerModelCustomerFactory $customerFactory,
MagentoCustomerModelSession $session,
array $data = []
)
$this->_productCollectionFactory = $productCollectionFactory;
$this->_customerFactory = $customerFactory;
$this->_session = $session;
parent::__construct($context, $data);
public function getCustomerId()
if ($this->_session->isLoggedIn())
return $this->_session->getCustomer()->getId();
public function getProductCollection()
$userId = $this->getCustomerId();
if (!empty($userId))
/*$customerCollection = $this->_customerFactory->create()
->getCollection()
->addAttributeToSelect("*")
->load(); */
$productCollection = $this->_productCollectionFactory->create();
$productCollection->addAttributeToSelect('*')
->addAttributeToFilter(
'user_id',
array('eq' => $userId)
); // user_id is your attribute name
return $productCollection;
Add
view/frontend/layout/catalog_category_view.xml
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="category.products.list">
<block class="NamespaceModulenameBlockTest" name="my.block.name" template="Namespace_Modulename::product/list.phtml" />
</referenceContainer>
</body>
</page>
copy this
list.phtml
file from
vendor/magento/module-catalog/view/frontend/templates/product/list.phtml
to
view/frontend/templates/product/list.phtml
Where should I be calling getProductCollection(); ? I need to list these products in a page Being new to Magento, excuse my level of knowledge
– Sidharth Satheesh
Jul 11 at 12:47
I did the above things in my module, but the list is not loading from my module. My module name is Faes_CCEngine.
– Sidharth Satheesh
Jul 11 at 13:53
Please check screenshots
– Sidharth Satheesh
Jul 11 at 14:00
okay i will look into it
– Mohit Rane
Jul 11 at 14:01
Hi, any updates? @MohitRane
– Sidharth Satheesh
Jul 12 at 3:14
add a comment |
You can do this by following code,
<?php
namespace VendorModuleBlock;
class Test extends MagentoFrameworkViewElementTemplate
protected $_productCollectionFactory;
protected $_session;
protected $_customerFactory;
public function __construct(
MagentoBackendBlockTemplateContext $context,
MagentoCatalogModelResourceModelProductCollectionFactory $productCollectionFactory,
MagentoCustomerModelCustomerFactory $customerFactory,
MagentoCustomerModelSession $session,
array $data = []
)
$this->_productCollectionFactory = $productCollectionFactory;
$this->_customerFactory = $customerFactory;
$this->_session = $session;
parent::__construct($context, $data);
public function getCustomerId()
if ($this->_session->isLoggedIn())
return $this->_session->getCustomer()->getId();
public function getProductCollection()
$userId = $this->getCustomerId();
if (!empty($userId))
/*$customerCollection = $this->_customerFactory->create()
->getCollection()
->addAttributeToSelect("*")
->load(); */
$productCollection = $this->_productCollectionFactory->create();
$productCollection->addAttributeToSelect('*')
->addAttributeToFilter(
'user_id',
array('eq' => $userId)
); // user_id is your attribute name
return $productCollection;
Add
view/frontend/layout/catalog_category_view.xml
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="category.products.list">
<block class="NamespaceModulenameBlockTest" name="my.block.name" template="Namespace_Modulename::product/list.phtml" />
</referenceContainer>
</body>
</page>
copy this
list.phtml
file from
vendor/magento/module-catalog/view/frontend/templates/product/list.phtml
to
view/frontend/templates/product/list.phtml
You can do this by following code,
<?php
namespace VendorModuleBlock;
class Test extends MagentoFrameworkViewElementTemplate
protected $_productCollectionFactory;
protected $_session;
protected $_customerFactory;
public function __construct(
MagentoBackendBlockTemplateContext $context,
MagentoCatalogModelResourceModelProductCollectionFactory $productCollectionFactory,
MagentoCustomerModelCustomerFactory $customerFactory,
MagentoCustomerModelSession $session,
array $data = []
)
$this->_productCollectionFactory = $productCollectionFactory;
$this->_customerFactory = $customerFactory;
$this->_session = $session;
parent::__construct($context, $data);
public function getCustomerId()
if ($this->_session->isLoggedIn())
return $this->_session->getCustomer()->getId();
public function getProductCollection()
$userId = $this->getCustomerId();
if (!empty($userId))
/*$customerCollection = $this->_customerFactory->create()
->getCollection()
->addAttributeToSelect("*")
->load(); */
$productCollection = $this->_productCollectionFactory->create();
$productCollection->addAttributeToSelect('*')
->addAttributeToFilter(
'user_id',
array('eq' => $userId)
); // user_id is your attribute name
return $productCollection;
Add
view/frontend/layout/catalog_category_view.xml
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="category.products.list">
<block class="NamespaceModulenameBlockTest" name="my.block.name" template="Namespace_Modulename::product/list.phtml" />
</referenceContainer>
</body>
</page>
copy this
list.phtml
file from
vendor/magento/module-catalog/view/frontend/templates/product/list.phtml
to
view/frontend/templates/product/list.phtml
edited Jul 11 at 13:12
answered Jul 11 at 12:22
Mohit RaneMohit Rane
76816 bronze badges
76816 bronze badges
Where should I be calling getProductCollection(); ? I need to list these products in a page Being new to Magento, excuse my level of knowledge
– Sidharth Satheesh
Jul 11 at 12:47
I did the above things in my module, but the list is not loading from my module. My module name is Faes_CCEngine.
– Sidharth Satheesh
Jul 11 at 13:53
Please check screenshots
– Sidharth Satheesh
Jul 11 at 14:00
okay i will look into it
– Mohit Rane
Jul 11 at 14:01
Hi, any updates? @MohitRane
– Sidharth Satheesh
Jul 12 at 3:14
add a comment |
Where should I be calling getProductCollection(); ? I need to list these products in a page Being new to Magento, excuse my level of knowledge
– Sidharth Satheesh
Jul 11 at 12:47
I did the above things in my module, but the list is not loading from my module. My module name is Faes_CCEngine.
– Sidharth Satheesh
Jul 11 at 13:53
Please check screenshots
– Sidharth Satheesh
Jul 11 at 14:00
okay i will look into it
– Mohit Rane
Jul 11 at 14:01
Hi, any updates? @MohitRane
– Sidharth Satheesh
Jul 12 at 3:14
Where should I be calling getProductCollection(); ? I need to list these products in a page Being new to Magento, excuse my level of knowledge
– Sidharth Satheesh
Jul 11 at 12:47
Where should I be calling getProductCollection(); ? I need to list these products in a page Being new to Magento, excuse my level of knowledge
– Sidharth Satheesh
Jul 11 at 12:47
I did the above things in my module, but the list is not loading from my module. My module name is Faes_CCEngine.
– Sidharth Satheesh
Jul 11 at 13:53
I did the above things in my module, but the list is not loading from my module. My module name is Faes_CCEngine.
– Sidharth Satheesh
Jul 11 at 13:53
Please check screenshots
– Sidharth Satheesh
Jul 11 at 14:00
Please check screenshots
– Sidharth Satheesh
Jul 11 at 14:00
okay i will look into it
– Mohit Rane
Jul 11 at 14:01
okay i will look into it
– Mohit Rane
Jul 11 at 14:01
Hi, any updates? @MohitRane
– Sidharth Satheesh
Jul 12 at 3:14
Hi, any updates? @MohitRane
– Sidharth Satheesh
Jul 12 at 3:14
add a comment |
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f281712%2fi-want-to-filter-the-products-listed-on-a-particular-category-page-by-an-attrib%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Update your code such that it will be easy to debug..
– aravind
Jul 11 at 14:01