If you want to filter a product collection by categories as well, the following code may help. Once the category filter is applied, the collection contains only products from the specified categories, in this example category IDs 123 and 456.…
Save Product button not working? (Magento 2)
You click “Save Product” in your Magento 2 admin area, but nothing happens? No error message or log entry appears? Then a required field may be empty. Expand all sections and check whether a mandatory field has been left blank.…
Product images missing on category page (Magento 2)
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.
Product images missing on category pages (Magento 2)
If product images are missing on your category pages after an upgrade, for example, the following shell command may help (run it from your Magento 2 root directory): php magento catalog:images:resize Note: Depending on the number of products, this process…
Loading all cross-sell products of a product (Magento 1)
Use this code to load all cross-sell products associated with a product:
|
1 2 3 4 |
$crossSellProducts = $product->getCrossSellProductCollection() ->addAttributeToSelect(Mage::getSingleton('catalog/config') ->getProductAttributes()) ->setPositionOrder()->addStoreFilter(); |
Getting a product’s manufacturer (Magento 1)
The following code retrieves the name of a product’s manufacturer. $manufacturer = $product->getAttributeText(‘manufacturer’);
Getting the type of a product (Magento 1)
Use the following code to get the type of a Magento product: // configurable, simple, … $type = $product->getTypeId();
Getting a product’s type (Magento 1)
Use this code to determine a product’s type (such as simple or configurable):
|
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
Sorting order items by SKU (Magento 1)
To display ordered products sorted by SKU in the order view, override the 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); // Sort by array keys ?> <?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; ?> |
That’s it. When you open an order containing two or more products, they will now be displayed in…