search
top

Get payment method of quote in Magento

Hello All, Please check the below script that will help you find the payment method information set in Magento quote $quote = Mage::getModel("sales/quote")->loadByIdWithoutStore($quoteId); //$quoteId to be replaced with your required id if ($quote) { $_qid = $quote->getId(); if (!empty($_qid)) { $_paymentObj = $quote->getPayment(); if(!empty($_paymentObj)) { $_paymentMethod...
read more

Coupon code generation using Magento

Hello All, I am writing here a script that will help you generate random coupon codes using Magento’s existing modules $format = Mage_SalesRule_Helper_Coupon::COUPON_FORMAT_ALPHANUMERIC; $charset = Mage::helper('salesrule/coupon')->getCharset($format); $del = Mage::helper('salesrule/coupon')->getCodeSeparator(); $l = 6; //length of the coupon code $d = 0; $pre = 'TT'; //prefix...
read more

Get child product in Magento

Hello All, I am writing here a script for getting all the child products of the required parent product id <?php $productId = '123'; $product = Mage::getModel('catalog/product')->load($productId); //$productId for which the child products to be found $childids = $product->getTypeInstance(true)->getChildrenIds($productId, false); echo '<pre>'; print_r($childids); if(!empty($childids)) { $allProds...
read more

First and Last collection item in Magento

We the Magento developers work mostly with data collections. For accessing the data we use ‘foreach’ to iterate over collection. $product_collection = Mage::getModel('catalog/product') ->getCollection() ->addAttributeToSelect('*'); foreach ($product_collection as $k => $v) { echo $v->getName(); echo '<br/>'; } What if we need only...
read more

Limit results collection in Magento

Many times need arises to limit collection for say pagination or for any customization. I am listing here an example which shows how to limit the collection. I have used the Product Model below. <?php $limit = 5; $starting_from = 2; $product_collection = Mage::getModel('catalog/product')->getCollection()->setOrder('name', 'asc'); //getting the product collection, results are ordered by...
read more

Optgroup in Magento

For a module I was working on in one of my project, I needed to display a select box, with optgroup, Magento has inbuilt function for this. Kindly go through this post Select Box in Magento of mine for understanding how to generate select box before reading forward. For option group you need to pass the ‘value’ also as an array. Suppose your Category name is ‘Furniture’ and...
read more

Event and Observer in Magento

There is an Event-Observer methodology used in Magento, Magento has been programmed to raise events in crucial areas of the flow. We can use these events for our requirement. I am describing here a way to use it. An example would be the event ‘checkout_onepage_controller_success_action’ (this has been use by me at many instances) which will be raised by Magento immediately after an order...
read more

Adminhtml Frontname in Magento

I am writing here a code snipet for fetching the name (alias) used to access admin end, which is set to ‘admin’ by default <?php echo Mage::getConfig()->getNode('admin/routers/adminhtml/args/frontName'); ?> Below code for creating an admin URL <?php $hlpr = Mage::helper("adminhtml"); $params = array('v'=>1,'pv'=>2); echo $url = $hlpr->getUrl('*/sales_order/',$params); ?>
read more

Category and Product SOAP API in Magento

In one of my post I explained the basics of SOAP API, please refer Magento SOAP API before proceeding further I am listing here the methods to create Categories and Products using SOAP API 1) Category a) Category Creation <?php $category_name = 'Test Category'; //create new category //start $category = array( 2, array('name'=>$category_name, 'display_mode' => PRODUCTS_AND_PAGE, 'is_anchor'...
read more

Payment Methods in Magento

These days I am working on Payment Module. I am writing here the code which is useful and related to Payment module 1) To fetch the existing Payment Methods There is a payment module helper file existing in default Magento, which is really very helpful. Path – app/code/core/Mage/Payment/Helper/Data.php <?php $payment_helper = Mage::helper('payment'); $method_list = $payment_helper->getPaymentMethodList(); echo...
read more

« Previous Entries

top