Monday 18 July 2016

Get all parent category ids and self id in an array

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
   $category = $objectManager->get('Magento\Framework\Registry')->registry('current_category');//get current category
  $current_cat = $category->getId(); // current category id

  $parent_cat =  $category->getParentCategory()->getId(); // parent category id
  foreach ($category->getParentCategories() as $parent) {
    $catids[] = $parent->getId(); // show all parent cat ids and self id in an array
}
if($catids[0]==parent_cat_id){
echo "show parent cat custom code";

}

magento 2 how to get parent category id current category

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
   $category = $objectManager->get('Magento\Framework\Registry')->registry('current_category');//get current category
  $current_cat = $category->getId(); // current category id

  $parent_cat =  $category->getParentCategory()->getId(); // parent category id

magento 2 how to get current category id

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
   $category = $objectManager->get('Magento\Framework\Registry')->registry('current_category');//get current category
  $current_cat = $category->getId(); // current category id

How to remove Default Magento 2 footer links

Step 1: Contact us
Go to \app\code\Magento\catalog\view\frontend\Layout\default.xml

Step 2: Remove footer links
For Privacy and Cookie Policy

Go to \app\code\Magento\Cms\view\frontend\Layout\default.xml

Comment block Line no- 13

<referenceBlock name="footer_links">
<block class="Magento\Framework\View\Element\Html\Link\Current" name="privacy-policy-link">
<arguments>
<argument name="label" xsi:type="string">Privacy and Cookie Policy</argument>
<argument name="path" xsi:type="string">privacy-policy-cookie-restriction-mode</argument>
</arguments>
</block>
</referenceBlock>

For Search Terms

Go to app\code\Magento\Search\view\frontend\Layout\default.xml

Comment on block Line no- 13

<referenceBlock name="footer_links">
<block class="Magento\Framework\View\Element\Html\Link\Current" ifconfig="catalog/seo/search_terms" name="search-term-popular-link"><arguments>
<argument name="label" xsi:type="string" translate="true">Search Terms</argument>
<argument name="path" xsi:type="string">search/term/popular</argument></arguments>
</block>
</referenceBlock>

For Orders and Returns

Go to app\code\Magento\Sales\view\frontend\Layout\default.xml

Comment block Line no- 16

<referenceBlock name="footer_links">
<block class="Magento\Sales\Block\Guest\Link" name="sales-guest-form-link">
<arguments>
<argument name="label" xsi:type="string">Orders and Returns</argument>
<argument name="path" xsi:type="string">sales/guest/form</argument></arguments>
</block>
</referenceBlock>

For Advanced Search

Go to app\code\Magento\CatalogSearch\view\frontend\Layout\default.xml

Comment block Line no- 13

<referenceBlock name="footer_links">
<block class="Magento\Framework\View\Element\Html\Link\Current" name="catalog-search-advanced-link">
<arguments>
<argument name="label" xsi:type="string" translate="true">Advanced Search</argument>
<argument name="path" xsi:type="string">catalogsearch/advanced</argument><argument name="attributes" xsi:type="array">
<item name="data-action" xsi:type="string">advanced-search</item></argument>
</arguments>
</block>
</referenceBlock>

Magento 2 add custom footer

default.xml from module Magento\Theme add this code inside footer referenceContainer

<block class="Magento\Cms\Block\Block" name="block-footer" after="footer_links">
      <arguments>
            <argument name="block_id" xsi:type="string">block_footer_custom</argument>
      </arguments>

</block>


Goto backend Content > Blocks > Add new static block with identifier name block_footer_custom with any html code you need. It so easy to editable Clear cache and re-

deploy static. Now you will get your custom block

Custom jQuery use in magento 2

<script>
require(['jquery'],function($){ /*First call this function and after add your jQuery code*/

$( document ).ready(function() {
$(".navigation ul li").hover(function() {
    alert("hello");
});
});

});
</script>

magento call block in any where in page dynamically

Add xml in  Layout Update XML on Designs tab in cms page

<reference name="root">
<block type="bannerslider/default" name="bannerslider" template="bannerslider/bannerslider.phtml">
    <action method="setBannersliderId"><bannerslider_id>1</bannerslider_id></action>
</block>
</reference>

Add below code in any layout page (1column.phtml) where you want show

<?php echo $this->getChildHtml('bannerslider'); ?>

How to place top menu to left side bar in magento 2


Add below code in <body> tag in Magento_Theme/view/frontend/layout/default.xml

<referenceContainer name="sidebar.main">
<block class="Magento\Framework\View\Element\Template" name="store.menu" group="navigation-sections" template="Magento_Theme::html/container.phtml">
<arguments>
<argument name="title" translate="true" xsi:type="string">Menu</argument>
</arguments>
</block>
</referenceContainer>

magento 2 call newsletter in sidebar

add below code in <body> tag in module-newsletter/view/frontend/layout/default.xml

<referenceContainer name="sidebar.additional">
            <block class="Magento\Newsletter\Block\Subscribe" name="form.subscribe" as="subscribe" after="wishlist_sidebar" template="subscribe.phtml"/>

        </referenceContainer>

Note :- You can use sidebar.main instead of sidebar.additional  for show in top of sidebar.