If the product images are missing after an upgrade for example, the following command (executed in the root of your Magento 2 shop) might help: php magento catalog:images:resize Note: Depending on the mumber of products, that might run some time.
Getting the type of a product (Magento 1)
Use the following code to get the type of a Magento product:
1 2 |
// configurable, simple, ... $type = $product->getTypeId(); |
Sort order items by SKU (Magento 1)
If you want to change the default sorting of the ordered items on the order detail page, go ahead and override app/design/adminhtml/default/default/template/sales/order/view/items.phtml in your theme and replace
1 2 3 4 5 6 7 8 |
<?php $_items = $this->getItemsCollection() ?> <?php $i=0;foreach ($_items as $_item):?> <?php if ($_item->getParentItem()) continue; else $i++;?> <tbody class="<?php echo $i%2?'even':'odd' ?>"> <?php echo $this->getItemHtml($_item) ?> <?php echo $this->getItemExtraInfoHtml($_item) ?> </tbody> <?php endforeach; ?> |
with
1 2 3 4 5 6 7 8 9 10 11 12 13 |
<?php $_items = $this->getItemsCollection() ?> <?php $_sortedItems = array(); ?> <?php foreach ($_items as $_item) : ?> <?php $_sortedItems[$_item->getSku()] = $_item;?> <?php endforeach;?> <?php ksort($_sortedItems); // This is where the sorting by SKU takes place ?> <?php $i=0;foreach ($_sortedItems as $_item):?> <?php if ($_item->getParentItem()) continue; else $i++;?> <tbody class="<?php echo $i%2?'even':'odd' ?>"> <?php echo $this->getItemHtml($_item) ?> <?php echo $this->getItemExtraInfoHtml($_item) ?> </tbody> <?php endforeach; ?> |
Done. If you open the detail page of an order…
Deleting all products using SQL (Magento 1)
To delete all product related data, use the following query:
1 |
DELETE FROM catalog_product_entity; |
Due to the constraints it will delete all related data from other tables as well.
Getting products with or without custom options using SQL (Magento 1)
To get all products that do not have custom options, simply run the following SQL query:
1 2 3 4 5 6 |
SELECT * FROM catalog_product_entity WHERE entity_id NOT IN (SELECT DISTINCT product_id FROM catalog_product_option); |
To get all products that do have custom options, remove the “NOT” from the above query.
Importing gallery images using MAGMI (Magento Mass Importer)
To import Magento gallery images using MAGMI (Magento Mass Importer) the following steps are required: Add a new column to your import file. It must be called media_gallery. Now add all your gallery images to that column. The format is:…
Adding a product image description programmatically (Magento 1)
There is no way to add a product image description using the addImageToMediaGallery function. The following code does the job though:
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')); } } |
Getting the attribute set name of a product (Magento 1)
Use the following code to get a products attribute set name.
1 2 3 |
$attributeSetModel = Mage::getModel("eav/entity_attribute_set"); $attributeSetModel->load($product->getAttributeSetId()); $attributeSetName = $attributeSetModel->getAttributeSetName(); |
Getting the product for cart item (Magento 1)
Use the following code to get the matching product of a Magento cart item:
1 |
$product = $item->getProduct(); |
Getting a products view count programmatically (Magento 1)
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/>'; } |