0
  1. I'm trying to add a link to an order confirmation email.
  2. The link should only display if SKU 2133 exists.
  3. The problem when SKU 2133 exists it displays SKU 2133 does not exist.

Before adding the link, I'm testing with the code below. In default.phtml, I added the code below -

           <?php
            $sku = '2133';
            $id = Mage::getModel('catalog/product')->getIdBySku($sku);
            if ($id){
                echo "SKU {$sku} exists";
            }
            else{
                echo "SKU {$sku} does not exist";
            }
            ?>
  • What is $_item ? – Keyur Shah Jan 8 '18 at 19:20
  • Sorry should be - getIdBySku($sku); – Jad Jan 8 '18 at 20:39
  • <?php $sku = '2133'; $id = Mage::getModel('catalog/product')->getIdBySku($sku); if ($id){ echo "SKU {$sku} exists"; } else{ echo "SKU {$sku} does not exist"; } ?> – Jad Jan 8 '18 at 20:40
0

Your test:

$sku       = '2133';
$catalog   = Mage::getModel('catalog/product');
$productId = $catalog->getIdBySku($sku);
$product   = Mage::getModel('catalog/product')->load($productId);

if ($product->getId()) {
    echo "Yes";
} else {
    echo "No";
}

Your file:

You have to get your current product Id then check if the SKU is aqual to 2133

$productId = "10";
$product   = Mage::getModel('catalog/product')->load($productId);
if ($product->getSku() == "2133") {
    echo "Yes";
} else {
    echo "No";
}
  • I added the productID for SKU 2133 and it prints "Yes" no matter if the SKU is 2133 or not. – Jad Jan 8 '18 at 22:46
  • Try the exemple 2 'your file' and put var_dump($product); and look if your sku is 2133 – PЯINCƏ Jan 9 '18 at 4:54
  • Attention: you have written the sku manually $sku = '2133'; so if you white this test its logical To get yes in all times ! You have to get the sku dynamically according to your current product. – PЯINCƏ Jan 9 '18 at 5:00

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.