0

I'm trying to fetch the order and/or the product data, but translated to a specific language/store view from an observer. This will send out an internal email so the order will be handled. Im calling the order data like this:

public function execute(\Magento\Framework\Event\Observer $observer) {
    $order = $observer->getEvent()->getOrder();
    // Stuff
}

And product Data

foreach ($order->getAllItems() as $item) {
        $product = $item->getProduct();
        $itemData = $item->getData();
        // Stuff
}

I've tried adding ->setStoreId(X) to the above but that didn't help.

Can it be done on the complete order object? Can it be done on the product level, including attributes? Or is this a case of fetching it one by one?

1 Answer 1

0

Use the object managers with product id for the product data.

$product_id      = 1; // for example

$objectManager   = \Magento\Framework\App\ObjectManager::getInstance();

$productData     = $objectManager->get('Magento\Catalog\Model\Product')->load($product_id);

$productStockObj = $objectManager->get('Magento\CatalogInventory\Api\StockRegistryInterface')->getStockItem($product_id);

Show all product data as well as arrays, variables and values:

foreach($productData->getProductOptionsCollection() as $o){
    foreach($o->getValues() as $ov){
            echo "<pre>"; print_r($ov->getData()); echo "</pre>";
    }
}

Show Stock Data:

$productStockObj->getData());

Get Current Store Id:

$storeManager  = $objectManager->get('\Magento\Store\Model\StoreManagerInterface');

echo $storeManager->getStore()->getStoreId();
3
  • Sorry I wasn't able to dive into your answer sooner. While I appreciate your effort, please tell me where do you actually change the storeview/language? Let's say my main view is DE, the order is coming in FR and I want to get all the information in EN Commented Feb 16, 2022 at 13:17
  • Do you also want to retrieve the product data or do you only mean order data per Store Id.
    – Booba
    Commented Feb 16, 2022 at 21:17
  • I want to retrieve all the data of the order passed by the observer, but translated to a different language/storeview. So product(name), its custom options (labels) but preferably also things like shipping/payment options Commented Feb 23, 2022 at 10:05

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.