Wednesday, 5 October 2016

Enable Admin Path Hint Without Database Access

Open any installed module in magento

Go to config.xml of module for example

app\code\local\Hiddenbrains\Strongpassword\etc\config.xml

Add this code in config.xml for enable path hint in backend.

<stores>
        <admin>
            <dev>
                <debug>
                    <template_hints>1</template_hints>
                    <template_hints_blocks>1</template_hints_blocks>
               </debug>
          </dev>
      </admin>
  </stores>


and after delete this code for remove path hint.

Monday, 4 July 2016

How To Get Sub Categories of Current Category In Magento 2

<?php 
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$category = $objectManager->get('Magento\Framework\Registry')->registry('current_category');
$subcats = $category->getChildrenCategories();
$_helper = $this->helper('Magento\Catalog\Helper\Output'); 
?>
<?php foreach ($subcats as $subcat): ?>
 <?php if($subcat->getChildrenCategories()->count() > 0): ?>
               <li class="item">
                    <a href="<?php echo $subcat->getUrl(); ?>">
                        <?php echo $subcat->getName(); ?>       
                        <?php echo $subcat->getChildrenCategories()->count(); ?>
                    </a>
                </li>
  <?php endif; ?>

<?php endforeach; ?>

How To Call Phtml File in Magento 2

 


Custom file path:
 
app/design/frontend/{Package}/{theme}/Magento_Theme/templates/html/test.phtml
 
Call In XML File:


<block class="Magento\Framework\View\Element\Template" name="test_file" 
 template="Magento_Theme::html/test.phtml"/>

Call In Block And CMS Pages:


{{block class="Magento\Framework\View\Element\Template" name="test_file" 
 template="Magento_Theme::html/test.phtml"}}

Call In PHTML File:
 
<?php include ($block->getTemplateFile('Magento_Theme::html/test.phtml')) ?>

OR, Like Magento
 
<?php echo $this->getLayout()->createBlock("Magento\Framework\View\Element\Template")
->setTemplate("Magento_Theme::html/test.phtml")->toHtml();?>

Thursday, 23 June 2016

How Remove Position and Other attributes from Sort-By

(1) BY ADMIN PANEL:

Go to catalog->category

Select Category which you want to remove sort-by attributes

Select Display Setting

uncheck use all Available Attributes option

select attribute which you want to show in sort-by


(2) VIA CODING:

Navigate to the /app/design/frontend/default/your_theme/template/catalog/product/list/toolbar.phtml. Look at the bottom of the file, there will be code lines looks like the below

<?php echo $this->__('Sort by') ?> <select onchange="setLocation(this.value)">
<?php foreach($this->getAvailableOrders() as $_key=>$_order): ?>
    <option value="<?php echo $this->getOrderUrl($_key, 'asc') ?>"<?php if($this->isOrderCurrent($_key)): ?> 
      selected="selected"<?php endif; ?>>
        <?php echo $_order ?>
    </option>
<?php endforeach; ?>
</select>
 
Just add an if statement like as the below code 
 
<?php echo $this->__('Sort by') ?> <select onchange="setLocation(this.value)">
<?php foreach($this->getAvailableOrders() as $_key=>$_order): ?>
    <?php if ($_order != 'Position') : // Start Removing Sort By "Position" option from the list ?>
        <option value="<?php echo $this->getOrderUrl($_key, 'asc') ?>"<?php if($this->isOrderCurrent($_key)): ?> 
             selected="selected"<?php endif; ?>>
            <?php echo $_order ?>
        </option>
    <?php endif; // End Removing Sort By "Position" option from the list ?>
<?php endforeach; ?>
</select> 


Thursday, 12 May 2016

Problem in uploading catalog images after upgrade to Magento 1.9.2.3

Here's a problem I've found when patching Magento CE with SUPEE-7405. It replaces the line:

chmod($destinationFile, 0777);

with:

chmod($destinationFile, 0640);

in the file lib/Varien/File/Uploader.php

This stopped my images displaying in the back end, 
since this file permission should actually be 644. Is there any reason this has been set to 640?

Sunday, 6 March 2016

Get Last Added Product In cart

$productID=Mage::getSingleton('checkout/session')->getLastAddedProductId(true);
echo $productID."<br>";
$_product=Mage::getModel('catalog/product')->load($productID);
echo $_product->getName()."<br>";
 
$session= Mage::getSingleton('checkout/session');
foreach($session->getQuote()->getAllItems() as $item)
{
    $productID = $item->getProductId();
    $productSku = $item->getSku();
    $productName = $item->getName();
    $productQty = $item->getQty();
    echo $productID."|".$productSku."|".$productName."|".$productQty."<br>";
}

Saturday, 20 February 2016

Get Multiple Select Attribute Value

<?php 
echo $_product->getResource()
->getAttribute('attribute_code')
->getFrontend()
->getValue($_product); 
?>