Wednesday 21 February 2018

How can I add a custom block to the products page in Magento 2?

In app/code/Namespace/Modulename/Magento_Catalog/layout/catalog_product_view.xml add like below code.
 You can use your required referenceContainer

 <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceContainer name="alert.urls">
            <block class="Magento\Catalog\Block\Product\View" name="textblock" as="textblock" before="-" template="product/view/stockavilable.phtml" />
        </referenceContainer>
    </body>
</page>

Tuesday 20 February 2018

How to assign products in category by programmability in magento

How to assign products in category by programmability in magento

To Add Product to Category:
Mage::getSingleton('catalog/category_api')->assignProduct($category->getId(),$p‌​roduct->getId());

To Remove product from category:
Mage::getSingleton('catalog/category_api')->removeProduct($category->getId(),$p‌​roduct->getId());

Saturday 10 February 2018

How to list products in descending order in magento 1.x?

How to list products in descending order?

 <reference name="product_list">
            <action method="setDefaultDirection"><dir>desc</dir></action>
  </reference>