Get A Products Stock Quantity
$product->getStockItem()->getQty();
Yes, there is no method for it - it's set using setStockItem()
from Mage_CatalogInventory_Model_Stock_Item::assignProduct()
via the catalog_product_load_after
event.
Related cards:
Get Methods of Class
Yes, very dirty, but it works a treat! Save this file in your Magento root directory, then fire up a command line and run whatever.php Mage_Core_Model_App
(or some other class) and you should see the output.
Output looks like below:
$ ./cl...
Getting A Products URL
Potentially confusing due to the 3 methods you could use, all of which are in Mage_Catalog_Model_Product
:
public function getUrlPath($category=null)
public function getUrlInStore($params = array())
public function getProductUrl($use...
Stock Availability on Credit Note, Cancellation and Payment Deny
In summary - making a credit memo can increase the stock quantity but will never set the "Stock Availability" of the product to "In Stock", whereas a config option can control whether an order cancellation sets "In Stock" automatically. Denying a ...
Many to Many Resource Model Mapping
This is some boilerplate code to facilitate the use of many-to-many relationship tables in Magento. I found myself rewriting this code often, so this saves some time. This example links a sizeguide entity to attribute sets. Obviously you'll need t...
Fetching All Attributes For An Entity From The DB In One Query
Using the database to inspect EAV-based entity types can be a real pain in the ass, so here are a bunch of queries that let you inspect some popular EAV entity types easily. This practice can be applied to any EAV entity type, however as there are...
Product Attribute Addition
This code shows all possible configuration options for an attribute that I know of, you need not include all of these when adding an attribute (although it won't hurt)
$installer = Mage::getResourceModel('catalog/setup', 'catalog_setup');
...
Pretty Backtrace / Stack Trace
In app/code/core/Mage/Core/functions.php
Magento offers a function named mageDebugBacktrace()
which is nice, but I thought could be made nicer. This backtrace shows frame numbers, file names and line numbers, classes, methods and arguments whe...
Messages and Global Messages Blocks
Both use the same block, as we can see in page.xml
:
<block type="core/messages" name="global_messages" as="global_messages"/>
<block type="core/messages" name="messages" as="messages"/>
When you add a message, you add it to the session...
Product EAV Attribute Set, Group and Attribute List
To see a list of all attribute sets, groups, and associated attributes for products, use this SQL. BONUS! Also shows the sort ordering, useful for determining which sort_order
you need to place an attribute in a certain position:
SELECT...
Admin Grids - Filtering A Joined Column
Often, you'll want to add a column to a collection used in a grid, and to do so you'd use _prepareCollection()
:
protected function _prepareCollection()
{
$collection = Mage::getResourceModel($this->_getCollectionClass());
...