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>