Magento convert quote item to order item
If you have custom product attribute(s), then you may need to convert them to quote item and then to order item in Magento when an order is placed. That helps the order get the product attributes details and saves it in order tables to reference in the backend Manage Orders screen. This allows you to know what values for the product is selected by the customer, so that you can consider it when dispatching the order items.
This is a two way process where first the product attribute converts to quote item, and then quote item (with your product attribute’s value) converts to order item.
To do this you will have to put the below code in your module’s config.xml file:
<global> | |
<!--convert your custom product attribute "myattribute" from quote item to order item--> | |
<fieldsets> | |
<sales_convert_quote_item> | |
<myattribute> | |
<to_order_item>*</to_order_item> | |
</myattribute> | |
</sales_convert_quote_item> | |
</fieldsets> | |
<!--add your custom product attribute "myattribute" to quote item--> | |
<sales> | |
<quote> | |
<item> | |
<product_attributes> | |
<myattribute></myattribute> | |
</product_attributes> | |
</item> | |
</quote> | |
</sales> | |
<!--convert product attribute to quote item through event observer--> | |
<events> | |
<sales_quote_item_set_product> | |
<observers> | |
<mymodule> | |
<class>mymodule/observer</class> | |
<method>convertAttribute</method> | |
</mymodule> | |
</observers> | |
</sales_quote_item_set_product> | |
</events> | |
</global> |
Magento get store information
Magento get store information from any page.
$store = Mage::app()->getStore(); //Mage_Core_Model_Store object |
Now to get store ID,
$storeID = $store->getStoreId(); |
To get store code,
$storeCode = $store->getCode(); |
To get store Website ID,
$websiteID = $store->getWebsiteId(); |
To get store name,
$storeName = $store->getName(); |
To get Default View store name,
$storeName = $store->getFrontendName(); |
To check if store is active or not,
$active = $store->getIsActive(); |
To get store’s Home URL,
$storeHomeURL = $store->getHomeUrl(); |
If you want to find store’s group name,
$storeGroupName = $store->getGroup()->getName(); |
If you want ADMIN Store information, admin store has ID 0. So, you can get the details of Admin Store like this:
$store = Mage::getModel('core/store')->load(0); |
and then getting all the information as shown above.
Magento filter products by status
Get all the products with status equal to enabled/disabled.
If you are using Flat Catalog in Magento, you will not get disabled products by this filter as in flat table all the products are only enabled one. You can check if your Magento website uses flat catalog or not by going here:
Admin > System > Configuration > Catalog section > Catalog > Frontend
Check Use Flat Catalog Category and Use Flat Catalog Product, if they are Yes it means you are using flat catalog, if they are No it means you are NOT using flat catalog.
So, if you don’t have flat catalog enabled and you want to filter all the products with status equal to disabled, you can use below code:
$products = Mage::getModel('catalog/category')->load($category_id) | |
->getProductCollection() | |
->addAttributeToSelect('*') //whatever attributes you want to get here | |
->addAttributeToFilter( | |
'status', | |
array('eq' => Mage_Catalog_Model_Product_Status::STATUS_DISABLED) | |
//replace DISABLED to ENABLED for products with status enabled | |
); |
Magento get subcategories of a category by category ID
Get all the subcategories of any category in Magento.
If you have a category ID (current category OR any category) then you can easily get all the subcategories of that particular category.
Below code will load all the subcategories of the current category. You can even get all the subcategories of any specific category by assigning category ID to $catID.
$catID = $current_category->getId(); //or any specific category id, e.g. 5 | |
$children = Mage::getModel('catalog/category')->getCategories($catID); | |
foreach ($children as $category) { | |
echo $category->getId(); | |
echo $category->getName(); | |
echo $category->getRequestPath(); | |
print_r($category->getData()); | |
} |
Magento remove index.php from URL
In Magento remove index.php from URL using below steps. It will convert your URL from
http://www.example.com/index.php/blah
to
http://www.example.com/blah
1.) In Magento Admin > System > Configuration > Web > Search Engine Optimization, change the value of Web Server Rewrites to Yes
Make sure your web server rewrite module is enabled. If you are using apache as your web server on Linux, you can check it by going to /etc/apache2/mods-enabled/rewrite.load, if rewrite.load is present there it means your rewrite module is enabled. If not, you will need to copy rewrite.load from /etc/apache2/mods-available/ and paste it at /etc/apache2/mods-enabled/ location. Then reload the apache by running service apache2 reload.
2.) Check the file permission of .htaccess, it should be present in Magento root directory and readable by server.
Welcome to my Blog
Certifications
Honor
Recognition
Contributions
Categories
- Apache (2)
- ChatGPT (1)
- Domain name (2)
- eCommerce (2)
- htaccess (1)
- Humor (3)
- Instagram API (1)
- jQuery (4)
- JSON (1)
- Linux (10)
- Magento (142)
- Magento admin (58)
- Magento Certification (5)
- Magento error (13)
- Magento frontend (68)
- Magento Imagine (2)
- Magento Interview (5)
- Magento Master (2)
- Magento2 (10)
- Mobile (1)
- MySQL (7)
- OpenAI (1)
- OroCRM (2)
- Performance (2)
- PHP (8)
- Prototype JS (3)
- Security (4)
- Wordpress (3)
- XML (2)