Magento Themes and Magento Extensions

Programmatically Add Attribute to an Attribute Set in Magento

Share
Posted on February 9th, 2015 | Posted by admin

Sometimes we need to create attribute and add it to an attribute set or to all attribute sets.In this article, we look how to add an attribute to ‘catalog_product’ entity for both these cases.

$model=Mage::getModel('eav/entity_setup','core_setup');

Here we instantiate Mage_Eav_Entity_Setup model

$data=array(
'type'=>'dropdown',
'input'=>'text',
'label'=>'Test Attribute',
'global'=>Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
'is_required'=>'0',
'is_comparable'=>'0',
'is_searchable'=>'0',
'is_unique'=>'1',
'is_configurable'=>'1',
'use_defined'=>'1'
);

$model->addAttribute('catalog_product','test_attribute',$data);

We just created a new attribute called ‘test_attribute’.

Refresh Magento Cache Programmatically

Share
Posted on April 23rd, 2013 | Posted by admin

When writing processes to automate some of Magento’s normally laborious tasks, perhaps for a product-import script, a mass attribute update script, category import, or inventory adjustment, keep in mind that you may have to refresh some kind of cache — especially when working with attributes. If you are encountering quirks or inconsistencies with your data, try these:

  • Rebuild Catalog Index
    Mage::getSingleton('catalog/index')->rebuild();
  • Rebuild Flat Catalog Product
    Mage::getResourceModel('catalog/product_flat_indexer')->rebuild();
  • Inventory Stock
    Mage::getSingleton('cataloginventory/stock_status')->rebuild();

Magento: Change order status programmatically

Share
Posted on April 7th, 2013 | Posted by admin

Change order status programmatically in Magento

Load an order using the following code

$order = Mage::getModel('sales/order')->load($orderId);

OR
$incrementId = 1000002;
$order = Mage::getModel('sales/order')->loadByIncrementId($incrementId);

magento set order status programmatically

Share
Posted on March 9th, 2013 | Posted by admin

magento set order status programmatically

While working on a project this evening, I was tasked with setting the order status of all orders within September to Complete automatically, no notifications to the customer, and a comment was needed for exporting later.

Below is how it was accomplished. This was done on Magento Enterprise 1.12

File: /root/orderUpdates.php

Programmatically Setting a Magento Item’s Price When Adding It to Cart

Share
Posted on February 3rd, 2013 | Posted by admin

Using code, how would we give a Magento item a one-time special price then add that item to the shopping cart?

The process is simple:

  • Create an instance of the Magento product,
    • give it a custom price by calling setSpecialPrice,
    • then save the product instance (store must be running as the admin store).
  • Next, grab the Magento cart object (a singleton),
    • add the product instance to the cart,
    • then save the cart.
Page 1 of 212»