Experimenting with Magento EE 2.1.7 and creating modules. I've created an attribute by the name of "brand" and have assigned a few products with brand data so that I can filter them by brand name/value.
I've created the boilerplate M2 module code and can confirm it's registered and loading. I'm attempting to extend \Magento\Catalog\Model\Layer so here is the code and file I'm modifying:
File: app/code/MyCompany/MyModule/Model/Magento/Catalog/Layer.php
Code:
<?php
namespace MyCompany\MyModule\Model\Magento\Catalog;
class Layer extends \Magento\Catalog\Model\Layer {
public function afterGetProductCollection($subject, $collection)
{
$collection->addAttributeToFilter('brand', array('eq' => 'Ryobi'));
return $collection;
}
}
With the above code I'm attempting to filter my custom product attribute "brand" with the value "Ryobi". Is this the correct approach for customer product attributes?