0

Basically in my magento store (i am using magento 1.9.2.4) I have configurable product called "Design Dino Tee Shirt" with SKU of DESIGNDINO and the associated products are lets say "Blue Color - S" with SKU of DESIGNDINOBLUES and "Blue Color - M" and DESIGNDINOBLUEM..

Now when someone orders this product and chose Blue Color - S.. everything is fine.. But by default.. the PackingSlips pdf when I print it.. the SKU shown in that PDF is that of the child product ie: DESIGNDINOBLUES.. Now my question is, How can I change that SKU to show the parent product ie: DESIGNDINO?

I know I can edit the template at this location:

/app/code/core/Mage/Sales/Model/Order/Pdf/Items/Shipment/Default.php

And then.. under line 58:

        // draw SKU
        $lines[0][] = array(
            'text'  => Mage::helper('core/string')->str_split($this->getSku($item), 25),
            'feed'  => 565,
            'align' => 'right'
        );

I believe I need to change something along $this->getSku($item) but im not sure how and what is the correct way to do it..

Also my 2nd question is, I run multiple stores on this 1 single magento installation.. So the changes I make here I do not want it to affect other stores.. meaning the change to parent SKU for packingslips pdf should only be for this specific store and other stores should still use the default SKU of child products.. so How can I do this so that only this store is affected and not other stores in this Magento installation?

Thanks for the help! Appreciate any discussion/answers.. :)

0

You have to override Default.php file from app/code/core/Mage/Sales/Model/Order/Pdf/Items/Shipment/Default.php

app/code/local/Mage/Sales/Model/Order/Pdf/Items/Shipment/Default.php

Add below code at line no : 57 (replace $storeId == 1 with your store id in below code)

$order = $this->getOrder();
$storeId = $order->getStoreId();
if ($storeId == 1) {
    //$parentIds = Mage::getResourceSingleton('catalog/product_type_configurable')->getParentIdsByChild($item->getId());
 /* Using Item Sku */
$child_id = Mage::getModel('catalog/product')->getIdBySku($this->getSku($item));
$parentIds = Mage::getModel('catalog/product_type_configurable')->getParentIdsByChild($child_id);
    if ($parentIds) {
    foreach($parentIds as $configItem)
    {
            $_product = Mage::getModel('catalog/product')->load($configItem);
            if($_product->getName() == $item->getName()){ break; }
    }
        //$_product = Mage::getModel('catalog/product')->load($parentIds[0]);
        $itemSku = $_product->getSku();
    } else {
        $itemSku = $this->getSku($item);
    }
} else {
    $itemSku = $this->getSku($item);
}

Replace below code in line no : 60

'text'  => Mage::helper('core/string')->str_split($itemSku, 25),

Instead of

'text'  => Mage::helper('core/string')->str_split($this->getSku($item), 25),
  • Hi @Dhaval and sv3n.. thanks for the answers and edits.. I have tried this but it isnt working so I tried to troubleshoot and found out that this line: $parentIds = Mage::getResourceSingleton('catalog/product_type_configurable')->getParentIdsByChild($item->getId()); $parentIds is empty.. so since its empty.. it runs the default $itemSku = $this->getSku($item); and shows the child product sku.. I am not sure how to get this right.. would appreciate if you guys could help further.. Thanks!~ – krizalis Jun 10 '17 at 3:05
  • @sv3n when i checked the results of $item->getId() it gives the wrong ID value.. i believe that is causing it to be not working.. it isnt getting the right ID – krizalis Jun 10 '17 at 6:50
  • Would appreciate if you could try to help me solve this.. I've been cracking my head for the past 2 days and I still dont know how to get the right id out to get the parent sku :( – krizalis Jun 11 '17 at 7:23
  • @krizalis.. Use below two lines $child_id = Mage::getModel('catalog/product')->getIdBySku($this->getSku($item)); $parentIds = Mage::getModel('catalog/product_type_configurable')->getParentIdsByChild($child_id); instead of $parentIds = Mage::getResourceSingleton('catalog/product_type_configurable')->getParentIdsByChild($item->getId()); – Camit1dk Jun 11 '17 at 11:05
  • @krizalis.. I updated my answer . Follow that code – Camit1dk Jun 11 '17 at 11:08

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.