2

I have a multi store view with different languages ​​to describe the product. Each store has a different locale defined.

I have this code

    $shops = $this->_storeManager->getStores();

    $store_locales = array();
    foreach ($shops as $shop){

        $store_locales[$shop->getName()] = array();
        $store_locales[$shop->getName()][] = $shop->getId();
        $store_locales[$shop->getName()][] = $this->_scopeconfig->getValue('general/locale/code', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $shop->getId());

    }

and now i need to load a product desciption specifying a store id.

Any idea?

1 Answer 1

10

Complete untested (sorry!). But as long as you have the product ID you should be able to use the getAttributeRawValue function on the resource model.

class YourClass {
   protected $product;

   public function __construct(
       \Magento\Catalog\Model\Product $product
   ) {
       $this->product = $product;
   }

   public function getDescription($productId, $store)
   {
       return $this->product->getResource()->getAttributeRawValue($productId, 'description', $store);
   }
}

If you're happy to load the full product model then do the following instead.

class YourClass {
    protected $productRepository;

    public function __construct(
        \Magento\Catalog\Model\ProductRepository $productRepository
    ) {
        $this->productRepository = $productRepository;
    }

    public function getProduct($id, $storeId) {
        return $this->productRepository->getById($id, false, $storeId);
    }
}
6
  • it works but you know a way to load the entire object model? Thanks!! (depends store)
    – Miguel
    Jun 2, 2017 at 10:48
  • Do you defintiely need the whole model? If it's just to get more attribute values, you can pass an array of attributes into the second parameter.
    – Paul
    Jun 2, 2017 at 11:04
  • is there a list of attributes i can obtain?
    – Miguel
    Jun 2, 2017 at 11:49
  • I don't think you'll be restricted. Is there something you can't get?
    – Paul
    Jun 2, 2017 at 11:57
  • i need de price without taxes and with taxes
    – Miguel
    Jun 2, 2017 at 11:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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