0

I am trying to retrieve the Child Item of a Configurable Details in the Shipment email.

I have overwritten the default template file in my theme at: app/code/design/MyTheme/theme/Magento_Sales/templates/email/items/order/default.phtml

I did this in the Order Confirmation email using $product = $_item->getProduct(). I'm unable to use this in the shipment email.

This snippet is how I retrieve Child Product Details in my Order Confirmation Template:

$_item = $block->getItem();
$_order = $_item->getOrder();
$product = $_item->getProduct();

// Normal Products
$productId = $product->getId();
$productName = $product->getName();
$productUrl = $product->getProductUrl();
$productSku = $product->getSku();

// Configurable Child Item Details
  foreach($_item->getChildrenItems() as $item){
    $product = $item->getProduct();
    $productId = $product->getId();
    $productName = $product->getName();
    $productUrl = $product->getProductUrl();
    $productSku = $product->getSku();
  }

This does not work in the Shipment email.

I see the table sales_shipment_item includes the Child Item in the name column. Can I retrieve this from there?

Thank you

1 Answer 1

0

The solution for me was to get the product using getOrderItem(); I then retrieve the Child Items from that using getChildrenItems();

$_item = $block->getItem();

// Normal Products
$productId = $_item->getId();
$productName = $_item->getName();
$productUrl = $_item->getProductUrl();
$productSku = $_item->getSku();

// Configurable Child Items
// Get Order Item
  foreach($_item->getOrderItem()->getChildrenItems() as $orderItem){
    $productId = $orderItem->getId();
    $productName = $orderItem->getName();
    $productUrl = $orderItem->getProductUrl();
    $productSku = $orderItem->getSku();
  }

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.