Wednesday, 10 January 2018

How to get current category in magento2 ?

<?php
    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $category = $objectManager->get('Magento\Framework\Registry')->registry('current_category');//get current category
    echo $category->getId();
    echo $category->getName();
?>

Remove Wishlist and compare products from sidebar in magento2

Here you need to do some coding level changes. follow me:
 Go to app/design/frontend/webguru/mifitness/Magento_Catalog/layout/default.xml
 <body>
........

 <referenceBlock name="catalog.compare.sidebar" remove="true" />
 <referenceBlock name="wishlist_sidebar" remove="true" />
 </body>

Tuesday, 26 September 2017

Add Custom Field to Customer Address

$installer = Mage::getSingleton('eav/entity_setup', 'eav_setup');

$installer->startSetup();

$installer->addAttribute('customer_address', 'addresstyped', array(
    'type' => 'varchar',
    'input' => 'text',
    'label' => 'Address Type',
    'global' => 1,
    'visible' => 1,
    'required' => 0,
    'user_defined' => 1,
    'visible_on_front' => 1
));
Mage::getSingleton('eav/config')
    ->getAttribute('customer_address', 'addresstyped')
    ->setData('used_in_forms', array('customer_register_address','customer_address_edit','adminhtml_customer_address'))
    ->save();
$installer->endSetup();


Module created :-
1. Path :- /app/etc/modules/Dapl_Excellenceaddress.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Dapl_Excellenceaddress>
            <active>true</active>
            <codePool>local</codePool>
        </Dapl_Excellenceaddress>
    </modules>
</config>

2. Path:- /app/code/local/Dapl/Excellenceaddress/etc/config.xml

 <global>
                <fieldsets>
            <sales_convert_quote_address>
                <addresstyped>
                    <to_order_address>*</to_order_address>
                    <to_customer_address>*</to_customer_address>
                </addresstyped>
            </sales_convert_quote_address>
            <customer_address>
                <addresstyped>
                    <to_quote_address>*</to_quote_address>
                </addresstyped>
            </customer_address>
        </fieldsets>
 </global>

Next step:-
ALTER TABLE  `sales_flat_quote_address` ADD  `addresstyped` VARCHAR( 255 ) NOT NULL AFTER  `fax` ;

Text
Add {{depend addresstyped}}ID# {{var addresstyped}}{{/depend}} where ever you want it. {{depend}} basically checks, if govt_id is not empty.
Text One line
Add {{depend addresstyped}}ID# {{var addresstyped}}{{/depend}} where ever you want it. This format shows up in the checkout page shipping,billing address dropdowns.
HTML
Add {{depend addresstyped}}<br/>ID# {{var addresstyped}}{{/depend}}. This format is used in many places like Order View, Address Display etc.
PDF
Add {{depend addresstyped}}<br/>ID# {{var addresstyped}}{{/depend}}|. This format is used in PDF invoices, shipments etc.
Javascript Template
Add <br/>ID#{addresstyped}. This is used in admin add/edit address area.
After saving these in the configuration, the new address format should be visible. 

Wednesday, 13 September 2017

Magento Custom Category Attribute File

1.Your category attribute installer:
$installer = $this;
$installer->startSetup();
$installer->addAttribute('catalog_category', 'custom_flv', array(
    'group'                    => 'General',
    'label'                    => 'Some File',
    'input'                    => 'image',
    'type'                     => 'varchar',
    'backend'                  => 'some_module/category_attribute_backend_file',
    'global'                   => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
    'visible'                  => true,
    'required'                 => false,
    'user_defined'             => true,
    'order'                    => 20
));
$installer->endSetup();


2.\app\code\local\Some\Module\Model\Category\Attribute\Backend\File.php

class Some_Module_Model_Category_Attribute_Backend_File extends Mage_Eav_Model_Entity_Attribute_Backend_Abstract
{
    public function afterSave($object)
    {
        $value = $object->getData($this->getAttribute()->getName());

        if (is_array($value) && !empty($value['delete'])) {
            $object->setData($this->getAttribute()->getName(), '');
            $this->getAttribute()->getEntity()
                ->saveAttribute($object, $this->getAttribute()->getName());
            return;
        }

        $path = Mage::getBaseDir('media') . DS . 'catalog' . DS . 'category' . DS;
        try {
            $uploader = new Mage_Core_Model_File_Uploader($this->getAttribute()->getName());

            $uploader->setAllowedExtensions(array('flv','pdf','doc','txt','sql'));
            $uploader->setAllowRenameFiles(true);
            $result = $uploader->save($path);
            //allowed extensions here
            $object->setData($this->getAttribute()->getName(), $result['file']);
            $this->getAttribute()->getEntity()->saveAttribute($object, $this->getAttribute()->getName());
        } catch (Exception $e) {
            if ($e->getCode() != Mage_Core_Model_File_Uploader::TMP_NAME_EMPTY) {
                Mage::logException($e);
            }
            return;
        }
    }
}

3./app/code/local/Some/Module/etc/config.xml
<global>
    <resources>
        <some_module_setup>
            <setup>
                <module>Some_Module</module>
                <class>Mage_Catalog_Model_Resource_Eav_Mysql4_Setup</class>
            </setup>
        </some_module_setup>
    </resources>
    <!--another nodes -->
 </global>

Wednesday, 23 August 2017

How to use WYSIWYG editor (TinyMCE) in custom Admin Magento Module

1> Including TincyMCE in Head
Add the following function in your Adminhtml Edit Class
(MagePsycho_Demomodule_Block_Adminhtml_Demomodule_Edit):

protected function _prepareLayout() {
    parent::_prepareLayout();
    if (Mage::getSingleton('cms/wysiwyg_config')->isEnabled()) {
        $this->getLayout()->getBlock('head')->setCanLoadTinyMce(true);
    }
}


2> Enabling in Form Field
Add the following content field in your Adminhtml Form class
(MagePsycho_Demomodule_Block_Adminhtml_Demomodule_Edit_Tab_Form):

$fieldset->addField('content', 'editor', array(
    'name'      => 'content',
    'label'     => Mage::helper('demomodule')->__('Content'),
    'title'     => Mage::helper('demomodule')->__('Content'),
    'style'     => 'height:15em',
    'config'    => Mage::getSingleton('cms/wysiwyg_config')->getConfig(),
    'wysiwyg'   => true,
    'required'  => false,
));

Thursday, 8 June 2017

blur jQuery

jQuery(".qty").blur(function(){
  var currency_sy= jQuery('#currency_syamble').val();
  var qty_val = jQuery(this).val();
  var item_price = parseFloat(jQuery(this).attr('data-price'));
  var currency_sy = jQuery(this).attr('data-currency');
  var totalItemPrice = qty_val*item_price;
  var total_item = parseFloat(totalItemPrice).toFixed(2);
  jQuery(this).parent().find('.item_total_price').html(currency_sy+total_item);
  var Totalprice=0;
  jQuery(".qty-wrapper").each(function(index) {
      var eachQty = jQuery(this).find('.qty').val();
      var eachprice = jQuery(this).find('.qty').attr('data-price');
      Totalprice = Totalprice + (eachQty*eachprice);
     
  });
  var total = parseFloat(Totalprice).toFixed(2);

 
  jQuery("#total_price").html(currency_sy+total);
});

Removing an item from a select box JQuery

$("#selectBox option[value='option1']").remove();


<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select name="selectBox" id="selectBox">
  <option value="option1">option1</option>
  <option value="option2">option2</option>
  <option value="option3">option3</option>
  <option value="option4">option4</option>
</select>