To import gallery images into Magento using MAGMI (Magento Mass Importer), follow these steps: Add a media_gallery column to your import file Then put the gallery images into that column using this format: image1.jpg::label1;/image2.jpg::label2…
Adding a product image label programmatically (Magento 1)
If you want to add a label to a product image programmatically, you cannot do this with the addImageToMediaGallery method. The following code, however, does the job:
|
1 2 3 4 5 6 |
foreach($product->getData('media_gallery') as $each){ foreach($each as $image){ $attributes = $product->getTypeInstance(true)->getSetAttributes($product); $attributes['media_gallery']->getBackend()->updateImage($product, $image['file'], array('label' => 'whatever')); } } |
Improving page load speed with Gzip compression (Magento 1)
Want to speed up your Magento store? One option is to enable gzip compression. This can be activated relatively easily in your server’s .htaccess file. Add the following lines:
|
1 2 3 4 5 |
<IfModule mod_deflate.c> <FilesMatch ".(js|css|html|htm|php)$"> SetOutputFilter DEFLATE </FilesMatch> </IfModule> |
You can then check whether the changes work by running…
Users cannot log in after a version update (Magento 1)
If a customer cannot log in after a Magento version update, you may have overridden login.phtml in your theme. Open \customer\form\login.phtml in your theme and insert the following code immediately after the form tags.
|
1 |
<?php echo $this->getBlockHtml('formkey'); ?> |
Setting configuration values programmatically (Magento 1)
You can set Magento store configuration values in code using the following snippet. The first parameter specifies the path in the core_config_data table.
|
1 |
Mage::getModel('core/config')->saveConfig('my/path/whatever', $value); |
Fixing Invalid backend model specified: catalog/attribute_backend_customlayoutupdate (Magento 1)
First, run this query:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
SELECT * FROM eav_attribute WHERE ( `attribute_id` LIKE '%stomlayoutupdate%' OR `entity_type_id` LIKE '%stomlayoutupdate%' OR `attribute_code` LIKE '%stomlayoutupdate%' OR `attribute_model` LIKE '%stomlayoutupdate%' OR `backend_model` LIKE '%stomlayoutupdate%' OR `backend_type` LIKE '%stomlayoutupdate%' OR `backend_table` LIKE '%stomlayoutupdate%' OR `frontend_model` LIKE '%stomlayoutupdate%' OR `frontend_input` LIKE '%stomlayoutupdate%' OR `frontend_label` LIKE '%stomlayoutupdate%' OR `frontend_class` LIKE '%stomlayoutupdate%' OR `source_model` LIKE '%stomlayoutupdate%' OR `is_required` LIKE '%stomlayoutupdate%' OR `is_user_defined` LIKE '%stomlayoutupdate%' OR `default_value` LIKE '%stomlayoutupdate%' OR `is_unique` LIKE '%stomlayoutupdate%' OR `note` LIKE '%stomlayoutupdate%' ); |
Write down the attribute_ids returned by the query, then run the following query:
|
1 2 3 |
DELETE FROM eav_attribute WHERE attribute_id IN (attribute_ids aus erster Abfrage); |
Fertig!
Cart items disappear from the shopping cart (Magento 1)
Sometimes products disappear from the shopping cart, for example after refreshing the cart page. One possible reason is a missing image on the Magento cart page. Check that all images are available and upload any missing files to the server.
Creating a credit memo programmatically (Magento 1)
The following code can create a credit memo for an order. $invoices = array(); foreach ($this->getInvoiceCollection() as $invoice) { $invoices[] = $invoice; } $service = Mage::getModel(‘sales/service_order’, $this); foreach ($invoices as $invoice) { $creditmemo = $service->prepareInvoiceCreditmemo($invoice); $creditmemo->register(); $creditmemo->save(); }
Getting the current date and time (Magento 1)
The following snippet returns the current date and time.
|
1 |
$dateAndTime = date("Y-m-d H:i:s", Mage::getModel('core/date')->timestamp(time())); |
Solving syntax error, unexpected ‘endif’ (T_ENDIF) problem (Magento 1)
Sometimes, when opening a Magento product page, the following error is shown: Parse error: syntax error, unexpected ‘endif’ (T_ENDIF) in … The problem here is not with the Magento code itself. Its a problem with the Apache server configuration. To…