Thursday 29 November 2018

How do Delete wishlist item in magento 1.9 by programatically?

  $wishList = Mage::getSingleton('wishlist/wishlist')->loadByCustomer($userId);
            $wishListItemCollection = $wishList->getItemCollection();
            foreach ($wishListItemCollection as $item) {
               $w_product_id = $item->getProductId();
                if ($w_product_id==$product_id) {
                    $item->delete();
                   
                    echo 'Deleted successfully';
                }else{
                    echo 'Not Deleted';

                }

How do List to wishlist item in magento 1.9 by programatically?

$itemCollection = Mage::getModel('wishlist/item')->getCollection()->addCustomerIdFilter($customarId);
 foreach($itemCollection as $product) {
                   
                    $product_id = $product->getId(),
                   
                 
                
            }

Wednesday 28 November 2018

How do I add to wishlist in magento 1.9 by programatically?

$wishlist = Mage::getModel('wishlist/wishlist')->loadByCustomer($customerId, true);
$product = Mage::getModel('catalog/product')->load($productId);

$buyRequest = new Varien_Object(array()); // any possible options that are configurable and you want to save with the product

$result = $wishlist->addNewItem($product, $buyRequest);
$wishlist->save();

Friday 23 November 2018

How to get list billing address and list shipping address by customer id in magento 1.9

$customerId = 2;
$customer = Mage::getModel('customer/customer')->load($customerId);
$defaultBilling  = $customer->getDefaultBilling();
$defaultShipping = $customer->getDefaultShipping();

$allAddress = Mage::getModel('customer/address')->getCollection()->setCustomerFilter($customer);

foreach ($allAddress as $address) {
    if($defaultBilling == $address->getId()) {
        // its customer default billing address
    } else if($defaultShipping == $address->getId()) {
        // its customer default shipping address
    } else {
        // its customer other address that saved
    }
}

Saturday 27 October 2018

How to remove +/- symbol off the price in Magento 1.9 product custom option


 app/code/core/Mage/Catalog/Block/Product/View/Options/Abstract.php and edited the line number 127

$priceStr = $sign;

to look like this:

$priceStr = '';

Magento 1.9 product Custom Options - make every first radio button checked

<script type="text/javascript">
var $j = jQuery.noConflict();
$j(document).ready(function(){

    $j('.options-list input.radio:first').attr('checked','checked');
    opConfig.reloadPrice();
});
</script>

Thursday 13 September 2018

How to Login with phone number without extension? [duplicate] in magento 1

Override Mage_Customer_AccountController to your local module and update loginPostAction function with below code.


    ......
    if ($this->getRequest()->isPost()) {
        $login = $this->getRequest()->getPost('login');
        // NEW CODE ADDED
        $phoneNumber = $login['username'];
        $customer = Mage::getResourceModel('customer/address_collection')
            ->addAttributeToSelect('telephone')
            ->addAttributeToFilter('telephone', $phoneNumber)
            ->getFirstItem()->getCustomer();
        if ($customer !== false) {
            $login['username'] = $customer->getEmail();
        }else{
            $login['username'] = $phoneNumber;
        }
        // NEW CODE COMPLETED
    .......

Tuesday 11 September 2018

How to display star rating summary in custom phtml page in magento 1

<?php if ($_rating['rating_summary']) {?>
  <div class="ratings">
      <div class="rating-box">
         <div class="rating" style="width:<?php echo $_rating['rating_summary']; ?>%"></div>
      </div>
  </div>
<?php } ?>

Tuesday 4 September 2018

Magento 2: Get product attribute’s select option id,label for configurable product




<?php
    $_helper = $this->helper('Magento\Catalog\Helper\Output');
    $_product = $block->getProduct();
    $optionId = $_product->getColor()
?>


$attr = $_product->getResource()->getAttribute('color');
 if ($attr->usesSource()) {
       $optionText = $attr->getSource()->getOptionText($optionId);
 }

Monday 27 August 2018

Add the order number to the subject in order email template in magento 2

Re: Add the order number to the subject in order email template


{{trans "Your %store_name order confirmation" store_name=$store.getFrontendName()}} #{{var order.increment_id}}

Thursday 23 August 2018

Customer Account Navigation links how to remove in magento 2

Customer Account Navigation links how to remove in magento 2

I created a file , inserted below, in app/design/frontend/Custom_VENDOR_Theme/My_Custom_THEME/Magento_Customer/layout/customer_account.xml

<?xml version="1.0"?>
<!--
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="2columns-left" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd" label="Customer My Account (All Pages)" design_abstraction="custom">
    <body>
        <!-- To Remove My Downloadable Products-->
        <referenceBlock name="customer-account-navigation-downloadable-products-link" remove="true"/>
        <!-- To Remove Billing Agreements-->
        <referenceBlock name="customer-account-navigation-billing-agreements-link" remove="true"/>
        <!-- To Remove My Credit Cards-->
        <referenceBlock name="customer-account-navigation-my-credit-cards-link" remove="true"/>
 
<move element="customer-account-navigation-quotes-link" destination="customer_account_navigation" after="customer-account-navigation-orders-link"/>

    </body>
</page>

Wednesday 11 July 2018

Thursday 21 June 2018

Friday 15 June 2018

How to implemented Magento 2 Sort By Price: Low to High and High to Low.


How to implemented Magento 2 Sort By Price: Low to High and High to Low.

Step 1: Create plugins
    app/code/Vendor/Module/etc/di.xml

    <?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">

    <type name="Magento\Catalog\Block\Product\ProductList\Toolbar">
        <plugin name="custom_custom_block_toolbar" type="Vendor\Module\Plugin\Catalog\Block\Toolbar" />
    </type>

    <type name="Magento\Catalog\Model\Config">
        <plugin name="custom_catalog_model_config" type="Vendor\Module\Plugin\Catalog\Model\Config" />
    </type>

</config>


Step 2: Create Config.php
app/code/Vendor/Module/Plugin/Catalog/Model/Config.php

<?php

namespace Vendor\Module\Plugin\Catalog\Model;

class Config
{
    public function afterGetAttributeUsedForSortByArray(
    \Magento\Catalog\Model\Config $catalogConfig,
    $options
    ) {

        $options['low_to_high'] = __('Price - Low To High');
        $options['high_to_low'] = __('Price - High To Low');
        return $options;

    }

}

Step 3: Create Toolbar.php
app/code/Vendor/Module/Plugin/Catalog/Block/Toolbar.php

<?php
namespace Vendor\Module\Plugin\Catalog\Block;

class Toolbar
{

    /**
    * Plugin
    *
    * @param \Magento\Catalog\Block\Product\ProductList\Toolbar $subject
    * @param \Closure $proceed
    * @param \Magento\Framework\Data\Collection $collection
    * @return \Magento\Catalog\Block\Product\ProductList\Toolbar
    */
    public function aroundSetCollection(
    \Magento\Catalog\Block\Product\ProductList\Toolbar $subject,
    \Closure $proceed,
    $collection
    ) {
    $currentOrder = $subject->getCurrentOrder();
    $result = $proceed($collection);

    if ($currentOrder) {
        if ($currentOrder == 'high_to_low') {
            $subject->getCollection()->setOrder('price', 'desc');
        } elseif ($currentOrder == 'low_to_high') {
            $subject->getCollection()->setOrder('price', 'asc');
        }
    }

    return $result;
    }

}

Saturday 2 June 2018

How can I display indian price symble properly in invoice pdf in magento 1.9

1.Download the font that support Indian Rupee symbol. recommended dejavu-sans font.

2.place the font in lib directory.
3.open app/code/core/Mage/Sales/Model/Order/Pdf/Abstract.php and app/code/core/Mage/Sales/Model/Order/Pdf/Items/Abstract.php

and replace
$font = Zend_Pdf_Font::fontWithPath(Mage::getBaseDir() . '/lib/LinLibertineFont/LinLibertine_Re-4.4.1.ttf');

With
$font = Zend_Pdf_Font::fontWithPath(Mage::getBaseDir() . '/lib/dejavu-sans/DejaVuSans.ttf');

(in _setFontRegular(), _setFontBold(), _setFontItalic() functions in both files.)
 

Friday 1 June 2018

How to get data from Magento 1.9 System Configuration

<?php
$store = Mage::app()->getStore(); // store info
$configValue = Mage::getStoreConfig('sectionName/groupName/fieldName', $store);
?>
example
<?php
$store = Mage::app()->getStore(); // store info
$configValue = Mage::getStoreConfig('rene_banner_settings/rene_banner_rule/igstnumber', $store);
?>

Admin config with extendable amount of fields system.xml in magento 1.9

app/code/local/Abhi/Banner/etc/system.xml

<config>
    <sections>
        <abhi_banner_settings translate="label" module="banner">
             <label>HSN Number Settings</label>
            <tab>general</tab>
            <frontend_type>text</frontend_type>
            <sort_order>304</sort_order>
            <show_in_default>1</show_in_default>
            <show_in_website>1</show_in_website>
            <show_in_store>1</show_in_store>
            <groups>
                <abhi_banner_rule translate="label">
                    <label>HSN </label>
                    <frontend_type>text</frontend_type>
                    <sort_order>10</sort_order>
                    <show_in_default>1</show_in_default>
                    <show_in_website>1</show_in_website>
                    <show_in_store>1</show_in_store>
                    <fields>

                        <hsnnumber translate="label">
                            <label>HSN Number</label>
                            <frontend_type>text</frontend_type>
                            <sort_order>10</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>1</show_in_store>
                        </hsnnumber>
                    </fields>
                </abhi_banner_rule>
            </groups>
        </abhi_banner_settings>
    </sections>
</config>

===============================
app/code/local/Abhi/Banner/etc/adminhtml.xml

<config>
    <acl>
        <resources>
            <admin>
                <children>
                    <system>
                        <children>
                            <config>
                                <children>
                                    <abhi_banner_settings translate="title">
                                        <title>HSN Number Settings</title>
                                        <sort_order>55</sort_order>
                                    </abhi_banner_settings>
                                </children>
                            </config>
                        </children>
                    </system>
                </children>
            </admin>
        </resources>
    </acl>
</config>

get value:-
<?php
$store = Mage::app()->getStore(); // store info
echo $configValue = Mage::getStoreConfig('abhi_banner_settings/abhi_banner_rule/hsnnumber', $store);
?>

Tuesday 17 April 2018

How to get current Currency and symbol in PHTML File in magento 2 ?


    <?php
        $_objectManager = \Magento\Framework\App\ObjectManager::getInstance();
        $currencysymbol = $_objectManager->get('Magento\Store\Model\StoreManagerInterface');
        $currencyCode = $currencysymbol->getStore()->getCurrentCurrencyCode();
        $currency = $_objectManager->create('Magento\Directory\Model\CurrencyFactory')->create()->load($currencyCode);
        $currencySymbol = $currency->getCurrencySymbol();
    ?>

Magento 2 How can I show custom options on product list page?



<?php
     $_objectManager = \Magento\Framework\App\ObjectManager::getInstance();

    $customOptions = $_objectManager->get('Magento\Catalog\Model\Product\Option')->getProductOptionCollection($_product);
    $optStr = "";
    foreach($customOptions as $optionKey => $optionVal):
        $optStr .= "<div class='custom-options'><label>".$optionVal->getTitle()." </label>";
            $optStr .= "<select name='options[".$optionVal->getId()."]'>";
            foreach($optionVal->getValues() as $valuesKey => $valuesVal) {
            $optStr .= "<option value='".$valuesVal->getId()."'>".$valuesVal->getTitle()."</option>";
                }

        $optStr .= "</select></div>";
    endforeach;
       echo($optStr );

?>

How to select option onchange url redirection

How to select option onchange url redirection:

<select onchange="this.options[this.selectedIndex].value && (window.location = this.options[this.selectedIndex].value);">
<option value="" selected>---Select---</option>
<option value="https://www.google.com">Google</option>
<option value="https://www.google.com">Google</option>
<option value="https://www.google.com">Google</option>
<option value="https://www.google.com">Google</option>
</select>

Monday 9 April 2018

How to display percentage of discount on product list and product view page in magento1.9?

How to display percentage of discount on product list and product view page in magento1.9?

app/design/frontend/yourpackage/yourtheme/template/catalog/product/price.phtml

Find: (line 397)

<?php endif; /* if ($_finalPrice == $_price): */ ?>

Past above it:

<?php // Discount percents output start ?>
    <?php if($_finalPrice < $_price): ?>
    <?php $_savePercent = 100 - round(($_finalPrice / $_price)*100); ?>
        <p class="special-price yousave">
            <span class="label"><?php echo $this->__('You Save:') ?></span>
            <span class="price">
                <?php echo $_savePercent; ?>%
            </span>
        </p>
    <?php endif; ?>
<?php // Discount percent output end ?>

How to set min height by Jquery

$j(document).ready(function(){
$j('.progrdCol').each(function() {
        startListHeight($j('.progrdCol > .productRap'));
    });
});

function startListHeight($tag) {
 
    function setHeight(s) {
        var max = 0;
        s.each(function() {
            var h = $j(this).height();           
            max = Math.max(max, h);
        }).height('').height(max);
    }
 
    $j(window).on('ready load resize', setHeight($tag));
}

Friday 6 April 2018

How to Add Social Sharing Links for a Product in Magento 2

How to Add Social Sharing Links for a Product in Magento 2


<div class="wdm-social-icons" data-role="wdm-social-icons">

<!-- FACEBOOK -->
<a href="https://www.facebook.com/sharer/sharer.php?u=<?php echo urlencode($_product->getProductUrl());?>&t=<?php echo urlencode($_product->getName())?>" onclick='javascript:window.open(this.href,"","width=640,height=480,left=0,top=0,location=no,status=yes,scrollbars=yes,resizable=yes");return false' title="Share on FaceBook">
<img src="<?php echo $this->getViewFileUrl('images/fb-med.png'); ?>" alt="FaceBook" width="5%">
</a>

<!-- TWITTER -->
<a href="http://twitter.com/home/?status=<?php echo urlencode($_product->getProductUrl());?>(<?php echo urlencode($_product->getName())?>)" onclick='javascript:window.open(this.href,"","width=640,height=480,left=0,top=0,location=no,status=yes,scrollbars=yes,resizable=yes");return false' title="Share on Twitter">
<img src="<?php echo $this->getViewFileUrl('images/tw.png'); ?>" alt="Twitter" width="5%">
</a>

</div>

Tuesday 3 April 2018

How to Increase / decrease qty directly on cart page in magento 1.9

How to Increase / decrease qty directly on cart page in magento 1.9

First, I give an id (form-update-post) to the form of the cart page : (app/design/frontend/rwd/default/template/checkout/cart.phtml)

<form action="<?php echo $this->getFormActionUrl() ?>" method="post" id="form-update-post">

    Then, I add two buttons, and I add an id to the qty field of the items : (checkout/cart/item/default.phtml)

<a href="javascript:decreaseQty(<?php echo $_item->getId() ?>)" class="decrement_qty"><span class="fa fa-minus">-</span></a>
<input id="quantity-item-<?php echo $_item->getId() ?>" name="cart[<?php echo $_item->getId() ?>][qty]"
   data-cart-item-id="<?php echo $this->jsQuoteEscape($_item->getSku()) ?>"
   value="<?php echo $this->getQty() ?>" size="4" title="<?php echo $this->__('Qty') ?>" class="input-text qty" maxlength="12" />
<a href="javascript:increaseQty(<?php echo $_item->getId() ?>)" class="increment_qty"><span class="fa fa-plus">+</span></a>

The last step is to add those Javascript functions in the cart page : (checkout/cart.phtml)

<script type="text/javascript">
    function increaseQty(id){
        var input = jQuery("#quantity-item-"+id);
        input.val(parseInt(input.val())+1);
        var form = jQuery("#form-update-post");
        if(form !== undefined){
            form.submit();
        }
    }

    function decreaseQty(id){
        var input = jQuery("#quantity-item-"+id);
        if(input.val() > 1){
            input.val(input.val()-1);
        }
        var form = jQuery("#form-update-post");
        if(form !== undefined){
            form.submit();
        }
    }
</script>

Increment and decrement qty button on shopping cart page in magento 1.9

Increment and decrement qty button on shopping cart page in magento 1.9

        <div class="qty-wrapper">
            <label for="qty"><?php echo $this->__('Quantity:') ?></label>
            <div class="qty-box">
                 <?php if(!$_product->isGrouped()): ?>
                    <a class="minus" id="<?php echo $_product->getId() . "minus" ?>" href="javascript:void(0);">-</a>
                    <input type="text" readonly="true" name="qty" id="qty<?php echo $_product->getId() ?>" maxlength="12" value="<?php echo ($_product->getStockItem()->getMinSaleQty() ? $_product->getStockItem()->getMinSaleQty() : 1) ?>" />
                    <a class="plus" id="<?php echo $_product->getId() . "plus" ?>"  href="javascript:void(0);">+</a>
                <?php endif; ?>
            </div>
        </div>


----------------------------------------------------
<script type="text/javascript">
$j(document).ready(function() {
    $j(".minus").click(function() {
        var id = this.id;
        var value = $j('#' + id).next('input').val();
        var fieldID = $j(this).next('input').attr("id");
        if (value > 1) {
            value = value - 1;
            $j('#' + fieldID).val(value);
        }
    });
    $j(".plus").click(function() {
        var id = this.id;
        var value = $j('#' + id).prev('input').val();
        var fieldID = $j(this).prev('input').attr("id");
        ++value;
        $j('#' + fieldID).val(value);
    });
});
</script>



Thursday 29 March 2018

How to remove compare, adto wishlist, sku in magento 2

<referenceBlock name="catalog.compare.sidebar" remove="true"/>
    <referenceBlock name="view.addto.compare" remove="true" />
    <referenceBlock name="view.addto.wishlist" remove="true" />

    <referenceBlock name="product.info.sku" remove="true"/>


================= All remove sidebar =============
<referenceContainer name="sidebar.additional" remove="true" />

================== wishlist remove sidebar============
<referenceBlock name="wishlist_sidebar" remove="true" />


Move short description below page product detail title via XML magento 2


app/design/frontend/webguru/mifitness/Magento_Catalog/layout/catalog_product_view.xml

Move short description below page product detail title via XML magento 2
<move element="product.info.overview" destination="product.info.main" before="product.info"/>

Magento 2: Safe and easiest way to disable Compare products & Wishlist Module

Magento 2: Safe and easiest way to disable Compare products & Wishlist Module
<referenceBlock name="view.addto.compare" remove="true" />

How to Remove product details apge Email to

How to Remove product details apge Email to

app/design/frontend/webguru/mifitness/Magento_Catalog/layout/catalog_product_view.xml

<referenceBlock name="product.info.mailto" remove="true" />

How to move product description after product options in Magento2

How to move product description after product options in Magento2

<move element="product.info.description" destination="product.info.main" before="product.info"/>

Tuesday 6 March 2018

How to remove breadcrumbs from category page in Magento 2

How to remove breadcrumbs from category page in Magento 2

app/design/frontend/Vendor/Theme/Magento_Catalog/layout/default.xml

---------------------------------------------------
<?xml version="1.0"?>
<!--
/**
 * Copyright © 2013-2017 Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="breadcrumbs" remove="true" />
   </body>
</page>
----------------------------------------------
For remove toolbar
<referenceBlock name="product_list_toolbar" display="false" />

Sunday 4 March 2018

How To add JS file in frontend for all pages in magento 2

How To add JS file in frontend for all pages in magento 2
requirejs-config.js under :- /app/design/frontend/your_vendor/your_theme/

To load a custom main.js file on all pages (in the RequireJS-way) this is a good way:
1) Create main.js
Create main.js within the theme folder
<theme_dir>/web/js/main.js
with this content:-------------

define([
  "jquery"
],
function($) {
  "use strict";

  // Here your custom code...
  console.log('Hola');

});

2) Declare main.js with a requirejs-config.js file
Create a requirejs-config.js file within the theme folder:

<theme_dir>/requirejs-config.js

with this content:

var config = {

  // When load 'requirejs' always load the following files also
  deps: [
    "js/main"
  ]

};


--------------------------------------------
app/code/your_vendor/your_theme/Magento_Theme/layout/default_head_blocks.xml

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <head>
        <!-- Add local resources -->
        <css src="css/my-styles.css"/>

        <!-- The following two ways to add local JavaScript files are equal -->
        <script src="Magento_Catalog::js/sample1.js"/>
        <link src="js/sample.js"/>

        <!-- Add external resources -->
        <css src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap-theme.min.css" src_type="url" />
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js" src_type="url" />
        <link src="http://fonts.googleapis.com/css?family=Montserrat" src_type="url" />
    </head>
</page>

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>

Tuesday 30 January 2018

Get config value for specific store from admin area in Magento 1.9

Get config value for specific store from admin area in Magento 1.9

<?xml version="1.0"?>
<!--
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magento.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magento.com for more information.
 *
 * @category    Mage
 * @package     Mage_Newsletter
 * @copyright   Copyright (c) 2006-2017 X.commerce, Inc. and affiliates (http://www.magento.com)
 * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
-->
<config>
    <sections>
        <newsletter translate="label" module="newsletter">
            <label>Newsletter</label>
            <tab>customer</tab>
            <frontend_type>text</frontend_type>
            <sort_order>110</sort_order>
            <show_in_default>1</show_in_default>
            <show_in_website>1</show_in_website>
            <show_in_store>1</show_in_store>
            <groups>
                 <subscription translate="label">
                    <label>Subscription Options</label>
                    <frontend_type>text</frontend_type>
                    <sort_order>1</sort_order>
                    <show_in_default>1</show_in_default>
                    <show_in_website>1</show_in_website>
                    <show_in_store>1</show_in_store>
                    <fields>
                        <cc_email translate="label">
                            <label>CC Email</label>
                            <frontend_type>text</frontend_type>                   
                            <sort_order>2</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>1</show_in_store>
                        </cc_email>
                     </fields>
                </subscription>
            </groups>
        </newsletter>
    </sections>
</config>

 $recipient=Mage::getStoreConfig('newsletter/subscription/cc_email');

Friday 26 January 2018

How to add first/last name in newsletter subscriber module in Magento1.9

How to  add first/last name in newsletter subscriber module in Magento1.9

 >> First add two fields ( subscriber_firstname, subscriber_lastname) in newsletter_subscriber table and
 app\design\frontend\THEME\default\template\newsletter\subscribe.phtml.

    >> Now edit this page : app\code\core\Mage\Newsletter\controllers\SubscriberController.php

        Here you'll find "public function newAction()"
            Paste the below code after this following code:
            $status = Mage::getModel('newsletter/subscriber')->subscribe($email);    //line (63)

     ///////////////////////// First Name //////////////////////////////

            if ($this->getRequest()->getPost('subscriber_firstname'))
                {
                     $subscriber = Mage::getModel('newsletter/subscriber')->loadByEmail($email);
                     $name     = (string) $this->getRequest()->getPost('subscriber_firstname');
                     $subscriber->setSubscriberFirstname($name);
                     $subscriber->save();
                }

     //////////////////////  END  ///////////////////////////////////////

            Do same for field Last Name....

    >> The above code will effect your frontend. If you want to see the information from Admin too, you have to implement a little bit.

    Go to this link : app\code\core\Mage\Adminhtml\Block\Newsletter\Subscriber\grid.php
    Add this code :

    //It will show the information to the admin on News Letter Subscriber Section.
    $this->addColumn('subscriber_firstname', array(
            'header'    => Mage::helper('newsletter')->__('Subscriber First Name'),
            'index'     => 'subscriber_firstname',
            'default'   =>    '----'
        ));

Tuesday 23 January 2018

How to add Custom Options - Drop Down add field in magento 1.9


How to add Custom Options - Drop Down add field in magento 1.9
Step1:
app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Options/Option.php

you have to modify the code in the line numbers 263 and 287 (or)
search sku as keyword, based on that just keep below code.

line number 263
'stockcount' => $_value->getStockcount(),

and in the line number 287
$value['stockcount'] = $option->getStockcount();

Step 2:
/app/design/adminhtml/default/default/template/catalog/product/edit/options/type/select.phtml
line number 42 add below code
'<th class="type-stockcount"><?php echo Mage::helper('core')->jsQuoteEscape(Mage::helper('catalog')->__('Stock Count')) ?></th>'+

line number 67
+'<td><input type="text" class="validate-zero-or-greater input-text" name="product[options][{{id}}][values][{{select_id}}][stockcount]" value="{{stockcount}}"></td>'+

Step 3:
finally you should add create a column 'stockcount' in the database table called catalog_product_option_type_value as shown in the below screenshot

Friday 19 January 2018

How to add custom dropdown attribute for category in Magento 2

How to add custom dropdown attribute for category in Magento 2

============================================================

/app/code/Wa/Categoryattrhome/registration.php

<?php 
\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'Wa_Categoryattrhome',
    __DIR__
);

===========================================================

/app/code/Wa/Categoryattrhome/composer.json


{
  "name": "wa/categoryattrhome",
  "description": "Create Custom Category Attribute",
  "require": {
    "php": "~5.5.0|~5.6.0",
    "magento/magento-composer-installer": "*"
  },
  "type": "magento2-module",
  "version": "1.0.0",
  "license": [
    "OSL-3.0",
    "AFL-3.0"
  ],
  "extra": {
    "map": [
      [
        "*",
        "Wa/categoryattrhome"
      ]
    ]
  }

}


==============================================

/app/code/Wa/Categoryattrhome/view/adminhtml/ui_component/category_form.xml


<?xml version="1.0" encoding="UTF-8"?>
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
    <fieldset name="category_fields">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="label" xsi:type="string" translate="true">Additional Settings</item>
                <item name="collapsible" xsi:type="boolean">true</item>
                <item name="sortOrder" xsi:type="number">100</item>
            </item>
        </argument>
        <field name="ishome_featured">
            <argument name="data" xsi:type="array">
            <item name="options" xsi:type="object">Magento\Eav\Model\Entity\Attribute\Source\Boolean</item>
                <item name="config" xsi:type="array">
                    <item name="sortOrder" xsi:type="number">60</item>
                    <item name="dataType" xsi:type="string">string</item>
                    <item name="formElement" xsi:type="string">select</item>
                    <item name="label" xsi:type="string" translate="true">Featured Category for home</item>
                </item>
            </argument>
        </field>
    </fieldset>
</form>

==================================================
/app/code/Wa/Categoryattrhome/Setup/UpgradeData.php

<?php
namespace Wa\Categoryattrhome\Setup;

use Magento\Eav\Setup\EavSetup;
use Magento\Eav\Setup\EavSetupFactory;
use Magento\Framework\Setup\UpgradeDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;

class UpgradeData implements UpgradeDataInterface
{
    private $eavSetupFactory;

    public function __construct(\Magento\Eav\Setup\EavSetupFactory $eavSetupFactory)
    {
            $this->eavSetupFactory = $eavSetupFactory;
    }

    public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
    {
            $setup->startSetup();

            if (version_compare($context->getVersion(), '9.0.1', '<')) {
                $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);

                $eavSetup->addAttribute(
                \Magento\Catalog\Model\Category::ENTITY,
                'ishome_featured',
                [
                    'group' => 'General',
                    'type' => 'varchar',
                    'backend' => '',
                    'frontend' => '',
                    'label' => 'Featured Category for home',
                    'input' => 'select',
                    'class' => '',
                    'source' => 'Magento\Eav\Model\Entity\Attribute\Source\Boolean',
                    'global' => \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_GLOBAL,
                    'visible' => true,
                    'required' => true,
                    'user_defined' => false,
                    'default' => '',
                    'searchable' => false,
                    'filterable' => false,
                    'comparable' => false,
                    'visible_on_front' => false,
                    'used_in_product_listing' => true,
                    'unique' => false
                ]);
            }

            $setup->endSetup();
    }

}

==========================================================

/app/code/Wa/Categoryattrhome/etc/module.xml

<?xml version="1.0"?> 
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd"> 
    <module name="Wa_Categoryattrhome" setup_version="1.0.0">
        <sequence>
            <module name="Magento_Catalog"/>
        </sequence>
    </module>
</config>


=====================================
* Copy the content of the repo to the Magento 2 root folder
* Run command: php bin/magento setup:upgrade
* Run Command: php bin/magento setup:static-content:deploy
* Now Flush Cache: php bin/magento cache:flush
 

Monday 15 January 2018

How to change the default product images sizes on Magento 2?

How to change the default product images sizes on Magento 2?

/app/design/frontend/vendor_name/theme_name/etc/view.xml

<view xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Config/etc/view.xsd">
    <media>
        <images module="Magento_Catalog">
            <image id="bundled_product_customization_page" type="thumbnail">
                <width>140</width>
                <height>140</height>
            </image>
            <image id="cart_cross_sell_products" type="thumbnail">
                <width>200</width>
                <height>248</height>
            </image>
          <image id="category_page_grid" type="small_image">
             <width>334</width>
             <height>284</height>
         </image>
            <image id="cart_page_product_thumbnail" type="small_image">
                <width>165</width>
                <height>165</height>
            </image>
            ........
        </images>
    </media>
    ......
</view>

Thursday 11 January 2018

How to added add-to-compare links on custom pages in magento2

 How to added add-to-compare links on custom pages in magento2
<?php
$compareHelper = $this->helper('Magento\Catalog\Helper\Product\Compare');
?>
<a href="#"
class="action tocompare"
title="<?php echo $block->escapeHtml(__('Add to Compare')); ?>"
aria-label="<?php echo $block->escapeHtml(__('Add to Compare')); ?>"
data-post='<?php /* @escapeNotVerified */ echo $compareHelper->getPostDataParams($product); ?>'
role="button">
<i class="fa fa-compress" aria-hidden="true"></i>
</a>

How to added wishlist link in custom product listing page in magento2

<a href="#" data-post='<?php echo $this->helper('Magento\Wishlist\Helper\Data')->getAddParams($product) ?>'
 data-action="add-to-wishlist">
  <?php /* @escapeNotVerified */ echo __('Wishlist'); ?>

</a>

How to expand layered navigation magento 2

Then, copy the file located at "vendor\magento\theme-frontend-luma\Magento_LayeredNavigation\templates\layer\view.phtml" into the appropriate area in your child theme.

You need to change the data-mage-init attribute and the "active" property to be in a format that specifies which filters to open by their index. I have 6 filters, so I want that property to read "0 1 2 3 4 5".

I made a couple of changes between lines 30-45 and it looks like this

<?php $wrapOptions = false; ?>
<?php
$filters = $block->getFilters();
$active_filters_str = implode(' ', range(0, count($filters)-1));
?>
<?php foreach ($filters as $filter): ?>
    <?php if ($filter->getItemsCount()): ?>
        <?php if (!$wrapOptions): ?>
            <div class="filter-options" id="narrow-by-list" data-role="content" data-mage-init='{"accordion":{"openedState": "active", "collapsible": true, "active": "<?php echo $active_filters_str ?>", "multipleCollapsible": true}}'>
        <?php  $wrapOptions = true; endif; ?>
        <div data-role="collapsible" class="filter-options-item">
            <div data-role="title" class="filter-options-title"><?php /* @escapeNotVerified */ echo __($filter->getName()) ?></div>
            <div data-role="content" class="filter-options-content"><?php /* @escapeNotVerified */ echo $block->getChildBlock('renderer')->render($filter); ?></div>
        </div>
    <?php endif; ?>
<?php endforeach; ?>

Add new tab on product detail page Magento 2

Add new tab on product detail page Magento 2

Create file catalog_product_view.xml in the app/design/frontend/{vender name}/{theme name}/Magento_Catalog/layout/catalog_product_view.xml


        <referenceBlock name="product.info.details">
          <block class="Magento\Catalog\Block\Product\View" name="deliveryinfo.tab" as="deliveryinfo" template="product/view/delivery_info.phtml" group="detailed_info" >
             <arguments>
                <argument translate="true" name="title" xsi:type="string">Product Question</argument>
             </arguments>
          </block>
        </referenceBlock>


app/design/frontend/{vender name}/{theme name}/Magento_Catalog/templates/product/view/delivery_info.phtml

Wednesday 10 January 2018

How to load product by id Magento2

How to load product by id Magento2

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$product = $objectManager->create('Magento\Catalog\Model\Product')->load($product_id);

How to get dropdown product attribute value in Magento 2

Get Dropdown Product Attribute Value in Magento 2
<?php
$attribute_code = 'availability';
echo $_product->getResource()->getAttribute($attribute_code)->getFrontend()->getValue($_product);
?>

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>