Use the following code to get the matching product of a Magento cart item:
|
1 |
$product = $item->getProduct(); |
Use the following code to get the matching product of a Magento cart item:
|
1 |
$product = $item->getProduct(); |
When testing new features locally on your development machine, it is advisable to change the customers’ email addresses. You can use the following script for this purpose: Warning: Never execute these statements on a production system!
|
1 2 3 4 |
update sales_flat_quote set customer_email = (concat(substring(md5(rand()) from 1 for 20), '@example.com')); update sales_flat_order set customer_email = (concat(substring(md5(rand()) from 1 for 20), '@example.com')); update sales_flat_quote_address set email = (concat(substring(md5(rand()) from 1 for 20), '@example.com')); update customer_entity set email = (concat(substring(md5(rand()) from 1 for 20), '@example.com')); |
Now open an…
Warning: Never execute these statements on a production system! The following query generates an update script according to a pattern you define. In this example the pattern is “your-domain.com”. Replace it with your own domain.
|
1 2 |
select concat('update core_config_data set value = \'test@example.com\' where path = \'', path, '\';') from core_config_data where value like '%@ihre-domain.de%' |
The resulting script might…
Normally Magento does not permit changing an order state to COMPLETE or CLOSED directly. Instead, you receive an error message (The Order State “complete” must not be set manually). You can work around this by overriding Order.php and View.php. 1.…
Sometimes values stored in the session cannot be read again in Internet Explorer or Chrome.
|
1 2 3 4 5 |
// Set session value Mage::getSingleton('core/session')->setImageData($imgData); // Reading the session value returns null $imgData = Mage::getSingleton('core/session')->getImageData(); |
Try the following workaround. Open System > Configuration > Web > Session Cookie Management > Use HTTP Only, then select Yes. Reading and writing…
This is the standard code for resizing images:
|
1 |
<?php echo $this->helper('catalog/image')->init($_product, 'image')->resize(100) ?> |
If an image is rectangular, a white border appears around it. Sometimes that is undesirable. To change this behavior, use the following methods: constrainOnly(true) (prevents resizing images that are smaller than…
You have to use so called filters to send parameters to a static block from a template for example. Lets take a look at the following code: Thats the static Magento block:
|
1 2 3 |
<a href="{{store url=''}}{{var attribute_set_name}}/configuration/test/product_id/{{var product_id}}"> Configure </a> |
We want to send attribute_set_name and product_id…
Sometimes, when adding custom options to a quote in ther admin area, the custom options are not available. To avoid that problem, simply add the custom options to your modules config.xml, like this:
|
1 2 3 4 5 6 7 8 9 10 11 12 |
<global> <sales> <quote> <item> <product_attributes> <custom_product_attribute1/> <custom_product_attribute2/> </product_attributes> </item> </quote> </sales> </global> |
Use the below code to figure out, how often a product was called in between 2 dates:
|
1 2 3 4 5 6 7 8 |
$fromDate = '2012-01-01'; $toDate = now(); $viewedProducts = Mage::getResourceModel('reports/product_collection')->addViewsCount($fromDate, $toDate); foreach($viewedProducts as $product) { echo 'sku ' . $product->getData('sku') . ' was viewed ' . $product->getData('views') . ' times.<br/>'; } |
Use the below code to figure out what custom option was selected by the customer for a cart item:
|
1 2 3 4 5 |
$productOptions = $item->getProduct()->getTypeInstance(true)->getOrderOptions($item->getProduct()); foreach($productOptions as $option) { .... } |