3

I want to get attributeText of product depending on what storeId is passed.

  • $attribute->getStoreLabel() for current store attribute label – Ketan Borada Dec 9 '19 at 5:33
3

You can get AttributeText by passing storeId from product collection:

$stores = $this->_storeManager->getStores();
foreach ($stores as $key => $store) {
    $store_id          = $store->getId();
    $productCollection = $this->getProductCollection($store_id);
    foreach ($productCollection as $_product) {
        $productdetails    = $_product->getData();
        $_conditionDefault = $_product->getResource()
                                      ->getAttribute('condition')
                                      ->setStoreId($store_id)
                                      ->getFrontend()
                                      ->getValue($_product);
        echo $_conditionDefault;
    }
}

protected function getProductCollection($store_id)
{
    $collection = $this->_productCollectionFactory
        ->create()
        ->addAttributeToSelect('*')->addStoreFilter($store_id)
        ->setVisibility($this->_productVisibility->getVisibleInSiteIds())
        ->addAttributeToFilter(
            'status',
            array('eq' => \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
        );

    return $collection;
}
| improve this answer | |
2
+50

You can try this..

<?php
    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $productId = 2; //Product ID
    $storeId = 1 //Store ID
    $product = $objectManager->get('Magento\Catalog\Model\Product')->load($productId);
    $attributeValue = $product->getResource()->getAttributeRawValue($product->getId(),'attribute_code',$storeId); //change attribute_code
    var_dump($attributeValue);
?>

Hope this will work for you!

| improve this answer | |
  • won't this return the id of an option instead of the label? – Marius Dec 6 '19 at 12:52
  • No @Marius, It will return value of attribute not ID. :) – Kishan Savaliya Dec 6 '19 at 13:09
  • How to get item attribute values based on store-level on order summary section at checkout Magento 2 – Yo Yo Roshan Mar 31 at 10:20
0

Haven't tested, but this might work:

Let's say $product is the product instance.
and $code is the attribute code for which you need the label. and $storeId the id of the store you need.

$attribute = $product->getResource()->getAttribute($code);
$attribute->setStoreId($storeId);
$text = $attribute->getSource()->getOptionText($product->getData($code));
| improve this answer | |
  • How to get item attribute values based on store-level on order summary section at checkout Magento 2 – Yo Yo Roshan Mar 31 at 10:21

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.