0

I want to edit the template /app/design/adminhtml/default/default/template/sales/items/column/name.phtml

This so that I can add my own custom attribute to the sales order. Therefore I created a line, that does work perfect for orders with products that still exists.

But when the order contains products that has been removed, the sales order does not load and the page breaks.

How can I change my line, so that it checks if the attribute value exists (or if the product still exists)?

CODE;

<?php $product_dpn = Mage::getModel('catalog/product')->loadByAttribute('sku', $_item->getSku(), array('dpn'));
$product_mpn = Mage::getModel('catalog/product')->loadByAttribute('sku', $_item->getSku(), array('mpn')); ?>

<div><?php if ($product_dpn->getDpn()): echo $product_dpn->getDpn(); endif; ?></div>
<div><?php if ($product_mpn->getMpn()): echo $product_mpn->getMpn(); endif; ?></div>
2
  • products that has been removed means ? from order or store ?
    – Keyur Shah
    Commented Jan 27, 2017 at 9:36
  • @KeyurShah Sorry, products that has been removed from store. So it can not find that product attribute and it breaks the page. So I need a if rule, that checks if the product exists or the value exists.
    – JGeer
    Commented Jan 27, 2017 at 9:40

1 Answer 1

1

You can put some condition like check product is exist or not in store

 <?php
       if(Mage::getModel('catalog/product')->getIdBySku($_item->getSku())) {
 ?>
    <?php $product_dpn = Mage::getModel('catalog/product')->loadByAttribute('sku', $_item->getSku(), array('dpn'));
    $product_mpn = Mage::getModel('catalog/product')->loadByAttribute('sku', $_item->getSku(), array('mpn')); ?>

    <div><?php if ($product_dpn->getDpn()): echo $product_dpn->getDpn(); endif; ?></div>
    <div><?php if ($product_mpn->getMpn()): echo $product_mpn->getMpn(); endif; ?></div>
     <?php
 }    
     ?>
2
  • Thanks! I tried that, but that does also remove the code for products that do exists. So it remove the code in all orders.
    – JGeer
    Commented Jan 27, 2017 at 10:09
  • just updated the answer please check @HenkZ
    – Keyur Shah
    Commented Jan 27, 2017 at 10:13

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.