0

I have used below code to get attribute value,

$category = $this->registry->registry('current_category');    
$external_url = $category->getData('attribute_code');

How to get it by store wise?

Any help would be appreciated.

  • how about using CollectionFactory of category? – fmsthird Apr 23 '19 at 9:43
  • 1
    I think using it you can filter by store – fmsthird Apr 23 '19 at 9:44
1

You can get value store vise from category collection :

protected $_storeManager;
protected $catCollectionFactory;

public function __construct(
    \Magento\Store\Model\StoreManagerInterface $storeManager,
    \Magento\Catalog\Model\ResourceModel\Category\CollectionFactory $catCollectionFactory,
    $data = []
) {
    $this->_storeManager = $storeManager;
    $this->catCollectionFactory = $catCollectionFactory;
    parent::__construct($data);
}

$categories = $this->catCollectionFactory->create()->addAttributeToSelect('*')->setStore($this->_storeManager->getStore());
foreach ($categories as $category){
    echo $category->getData('attribute_code');
}
| improve this answer | |
1

Please use below code it's helpfull for you.

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$objectManager->create('Magento\Catalog\Model\Category')->getCollection()->setStoreId('store_id')->addAttributeToSelect('attribute_code');
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.