Wednesday 25 November 2015

Get base product image path in Magento

echo Mage::getModel('catalog/product_media_config')
        ->getMediaUrl( $product->getImage() ); //getSmallImage(), getThumbnail()

Monday 16 November 2015

Magento programmatically add comment to order

// get the last order
$lastOrderId = $this->_getOnepage()->getCheckout()->getLastOrderId();
$order = Mage::getModel('sales/order')->load($lastOrderId);

// Add the comment and save the order (last parameter will determine if comment will be sent to customer)
$order->addStatusHistoryComment('This comment is programatically added to last order in this Magento setup');
$order->save();

Monday 2 November 2015

unique array in php

array_unique
<?php
$input = array("a" => "green", "red", "b" => "green", "blue", "red");
$result = array_unique($input);
print_r($result);
?>



Array
(
    [a] => green
    [0] => red
    [1] => blue
)

Getting Configurable Product from Simple Product ID in Magento

$simpleProductId = 465;
$parentIds = Mage::getResourceSingleton('catalog/product_type_configurable')
                  ->getParentIdsByChild($simpleProductId);

$product = Mage::getModel('catalog/product')->load($parentIds[0]);
echo $product->getId();