Magento2 Custom Admin Extension

Magento2 Custom Admin Extension is one of the simple and useful extension as it removes the footer of the ‘magento’ copyright with custom logo and admin navigation colors.

Features:

  • Magento2 Custom Admin extension will allows to upload custom admin logo for the admin panel.
  • Magento2 Custom Admin extension will allows to upload custom logo for the admin login screen.
  • Magento2 Custom Admin extension will allows to apply the custom navigation background and text color for the admin panel.
  • Magento2 Custom Admin extension will remove footer copyright from the login screen.
  • Magento2 Custom Admin extension will remove footer from the admin panel.

 

Magento2 Custom Navigation Menu Color

Magento2 Custom Admin Menu Navigation Color by color picker
Magento2 Remove footer from admin panel

Get an array of all products attributes in magento2

[php]Sample model file : Dys\Ajaxsearch\Model\Searchtype.php code as below

namespace Dys\Ajaxsearch\Model;
use Magento\Catalog\Model;

class Searchtype implements \Magento\Framework\Option\ArrayInterface
{

protected $objectManager;

public function __construct( \Magento\Framework\ObjectManagerInterface $interface ) {
$this->objectManager = $interface;
}

/**
* Options getter
*
* @return array
*/
public function toOptionArray( $isMultiselect = false)
{
$customer_attributes = $this->objectManager->get('Magento\Catalog\Model\Product')->getAttributes();

$attributesArrays = array();

foreach($customer_attributes as $cal=>$val){
$attributesArrays[] = array(
'label' => $cal,
'value' => $val
);
}

return $attributesArrays;
}
}
?>

How to use :
use Dys\Ajaxsearch\Model\Attributes
[/php]

Add js css in module .xml in Magento2

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
<head>
 <!-- for css file -->
 <css src="Dys_Ajaxsearch::css/ajaxsearch.css"/> 
 <!-- for js file -->
 <script src="Dys_Ajaxsearch::js/ajaxsearch.js"/>
</head>
</page>

Remove .std div (wrapper) from Magento CMS Pages through xml

Add below xml code to local.xml of your current theme or cms.xml file.

1. Remove from all cms pages.

<cms_page>
    <reference name="content">
        <remove name="cms.wrapper"/>
    </reference>
</cms_page>

2. Remove from CMS Home page only

<cms_index_index>
    <reference name="content">
        <remove name="cms.wrapper"/>
    </reference>
</cms_index_index>

Display Magento cart total Block in custom pages or XML

There is a two way to display checkout cart total block to any page.

1. Through .phtml

<?php
    // Method 1: 
              echo $this->getLayout()->createBlock('checkout/cart_totals')
                                     ->setTemplate('checkout/cart/totals.phtml')->toHtml();

    // Method 2: 
               $layout = $this->getLayout();
               $layout->getUpdate()
                      ->addHandle('default')
                      ->addHandle('checkout_cart_index')
                      ->load();
               $layout->generateXml()->generateBlocks();
               $total_html = $layout->getBlock('checkout.cart.totals')->toHtml();
               echo $total_html;
?>

2. Through xml

<reference name="content">
    <block type="checkout/cart_totals" name="custom.cart.total" template="checkout/cart/totals.phtml" />
</reference>

Split single table field to two separate fields in Magento collection

Here is the example of split order street address in to 2 separate fields separated by ‘n’ newline.

<?php
$collection = Mage::getModel('sales/order_address')->getCollection()
            ->addExpressionFieldToSelect('street_line1',
                    'IF(LOCATE("n", {{full_street}}) > 0,
                        SUBSTRING({{full_street}}, 1, LOCATE("n", {{full_street}}) - 1),
                        {{full_street}} )',
                array('full_street' => 'street'))

            ->addExpressionFieldToSelect('street_line2',
                    'IF(LOCATE("n", {{full_street}}) > 0,
                        SUBSTRING({{full_street}}, LOCATE("n", {{full_street}}) + 1),
                        NULL )',
                array('full_street' => 'street'));            
print_r($collection->getData());        
?>

On print_r($collection->getData()); you can see the 2 new field added to result ‘street_line1′ and ‘street_line2′.

Note : Use ‘addExpressionAttributeToSelect’ if not works ‘addExpressionFieldToSelect’.