Monday, 2 December 2019

Magento 2 Add Attribute Name To Configurable Select Option 'Choose a option..'

Configurable products display 'Choose an option...'. with Attribute option label like 'Color Choose an option...'


You also need to change that text in below file,

vendor/magento/module-configurable-product/view/frontend/web/js/configurable.js
In this file, you need to find _fillSelect method and see "chooseText" value.

element.options[0].innerHTML = this.options.spConfig.chooseText

Replace with below code


var attribute_lable = this.options.spConfig.attributes[element.id.replace(/[a-z]*/, '')]['label']; element.options[0].innerHTML = attribute_lable +' ' + this.options.spConfig.chooseText; 

Thanks,

Wednesday, 16 October 2019

Magento 2: Pub Static CSS files are present but show 404

Resolved after placing the missing .htaccess file in the static folder.

Magento 2 Error error too many redirects in admin login screen

This web page has a redirect loop.

Go to PHP Myadmin

In the "core_config_data" table remove the value of "web/cookie/cookie_domain" and set "web/cookie/cookie_httponly" to "0". 

Clear the cache by 'php -d error_log= -d memory_limit=-1 bin/magento cache:flush'

Thursday, 1 August 2019

Magento 2.3.1 Notice: Undefined index: color_bucket / gift_dropdown_bucket / gift_price_bucket

This is not to be a problem in Magento, but in problem with Elastic-Search.

Magento 2.3.1 Notice: Undefined index: color_bucket / gift_dropdown_bucket / gift_price_bucket \/app\/vendor\/magento\/module-elasticsearch\/SearchAdapter\/Aggregation\/Builder\/Term.php$

Solved :

 Find the attribute gift_dropdown remove _bucket

Go To admin and Store >> Product then search attribute with code.

Use in Search: No

Use In Search Results Layered Navigation No 

Then run the following two commands:

php bin/magento cache:clean

php bin/magento indexer:reindex catalogsearch_fulltext 

if get this warning for another attribute after doing this change. repeat the same process with another attribute.


Thursday, 18 July 2019

Magento 2 : Adding additional store email addresses in the store admin

Magento 2 allows you to set five email addresses in the store admin:

  1. 1.General Contact
  2. Sales Representative
  3. Customer Support
  4. Custom Email 1
  5. Custom Email 2


add more
  • Custom Email 3
  • Custom Email 4
  • Custom Email 5
  • .
  • .
  • .
  • .
  • more.........


Need to create a new module using the below steps
Mycompany/Additionalstoreemail/

registration.php
composer.json
etc/module.xml
etc/adminhtml/system.xml

registration.php
<?php
/**
 * Copyright © 2015 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */

\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'Mycompany_Additionalstoreemail',
    __DIR__
);
------------------------------------------------------
composer.json

{
    "name": "mycompany\/additionalstoreemail",
    "description": "Magento 2 Additional Store Email Address",
     "require": {
        "php": "~5.5.22|~5.6.0|7.0.2|7.0.4|~7.0.6|~7.1.0",
        "magento/framework": "100.0.*|100.1.*|101.0.*"
    },
    "type": "magento2-module",
    "version": "1.0.1",
    "license": [
        "OSL-3.0",
        "AFL-3.0"
    ],
    "autoload": {
        "files": [
            "registration.php"
        ],
        "psr-4": {
            "Mycompany\\Additionalstoreemail\\": ""
        }
    }
}

------------------------------------------------------
etc/module.xml

<?xml version="1.0"?>
<!--
/**
 * Copyright © 2015 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Mycompany_Additionalstoreemail" setup_version="1.0.1" />
</config>

------------------------------------------------------
etc/adminhtml/system.xml

<?xml version="1.0"?>
<!--
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
    <system>
        <tab id="general" translate="label" sortOrder="100">
            <label>General</label>
        </tab>             
        <section id="trans_email" translate="label" type="text" sortOrder="100" showInDefault="1" showInWebsite="1" showInStore="1">
                   
            <group id="ident_custom3" translate="label" type="text" sortOrder="6" showInDefault="1" showInWebsite="1" showInStore="1">
                <label>Custom Email 3</label>
                <field id="email" translate="label" type="text" sortOrder="2" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
                    <label>Sender Email</label>
                    <validate>validate-email</validate>
                    <backend_model>Magento\Config\Model\Config\Backend\Email\Address</backend_model>
                </field>
                <field id="name" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
                    <label>Sender Name</label>
                    <backend_model>Magento\Config\Model\Config\Backend\Email\Sender</backend_model>
                    <validate>validate-emailSender</validate>
                </field>
            </group>
           
            <group id="ident_custom4" translate="label" type="text" sortOrder="7" showInDefault="1" showInWebsite="1" showInStore="1">
                <label>Custom Email 4</label>
                <field id="email" translate="label" type="text" sortOrder="2" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
                    <label>Sender Email</label>
                    <validate>validate-email</validate>
                    <backend_model>Magento\Config\Model\Config\Backend\Email\Address</backend_model>
                </field>
                <field id="name" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
                    <label>Sender Name</label>
                    <backend_model>Magento\Config\Model\Config\Backend\Email\Sender</backend_model>
                    <validate>validate-emailSender</validate>
                </field>
            </group>
           
            <group id="ident_custom5" translate="label" type="text" sortOrder="8" showInDefault="1" showInWebsite="1" showInStore="1">
                <label>Custom Email 5</label>
                <field id="email" translate="label" type="text" sortOrder="2" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
                    <label>Sender Email</label>
                    <validate>validate-email</validate>
                    <backend_model>Magento\Config\Model\Config\Backend\Email\Address</backend_model>
                </field>
                <field id="name" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
                    <label>Sender Name</label>
                    <backend_model>Magento\Config\Model\Config\Backend\Email\Sender</backend_model>
                    <validate>validate-emailSender</validate>
                </field>
            </group>           
           
        </section>       
    </system>
</config>

Wednesday, 3 July 2019

Magento 2 : Add WYSISYG Editor Admin Form In Custom Module

<?php
namespace [VENDOR]\[EXTENSION]\Block\Adminhtml\[CUSTOM]\Edit\Tab;

class Form extends \Magento\Backend\Block\Widget\Form\Generic implements \Magento\Backend\Block\Widget\Tab\TabInterface
{
protected $_wysiwygConfig;

public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Framework\Registry $registry,
\Magento\Framework\Data\FormFactory $formFactory, 
\Magento\Cms\Model\Wysiwyg\Config $wysiwygConfig,
array $data = []
)
{
$this->_wysiwygConfig = $wysiwygConfig;
parent::__construct($context, $registry, $formFactory, $data);
}

protected function _prepareForm()
{
$model = $this->_coreRegistry->registry('EXTENSIONKEY');

/** @var \Magento\Framework\Data\Form $form */
$form = $this->_formFactory->create();

$fieldset = $form->addFieldset('base_fieldset', ['legend' => __('YOUR FORM TITLE')]);

$fieldset->addField('storycontent', 'editor', [
  'name'      => 'storycontent',
  'label'   => 'Story Content',
  'config'    => $this->_wysiwygConfig->getConfig(),
  'wysiwyg'   => true,
  'required'  => false,
  'after_element_html' => '<small>YOURCOMMENT.</small>',
  'value' => $model->getStorycontent()
]);

$this->setForm($form);
return parent::_prepareForm();
}
}
?>

Monday, 1 July 2019

Magento 2 : Modal Popup Window Call Anywhere

Modal Popup Window Call Anywhere

<a href="#" id="click-header">View Video</a></div>

<div id="header-mpdal" style="display:none;">
<div class="videoWrapper">
    <iframe width="560" height="315" src="https://www.youtube.com/embed/code_hear" frameborder="0" gesture="media" allow="encrypted-media" allowfullscreen></iframe>
</div>
</div>

<script>
    require(
        [
            'jquery',
            'Magento_Ui/js/modal/modal'
        ],
        function(
            $,
            modal
        ) {
            var options = {
                type: 'popup',
                responsive: true,
                innerScroll: true,
                title: '',
                buttons: [{
                    text: $.mage.__('Close'),
                    class: '',
                    click: function () {
                        this.closeModal();
                    }
                }]
            };

            var popup = modal(options, $('#header-mpdal'));
            $("#click-header").on('click',function(){
                $("#header-mpdal").modal("openModal");
            });

        }
    );
</script>

Magento 2: How to Call a CMS Static Block in Phtml File

Display CMS Static Block In Phtml File:

Here the code to show CMS Static Block in any template (phtml) file in Magento 2,
Display CMS Static Block In Phtml File:

Here the code to show CMS Static Block in any template (phtml) file in Magento 2,

<?php
    echo $block->getLayout()
               ->createBlock('Magento\Cms\Block\Block')
               ->setBlockId('block_identifier')
               ->toHtml();
?>
Display CMS Static Block In CMS Content:

Here the code to show CMS Static Block in any other CMS static block/page in Magento 2,
1

{{block class="Magento\\Cms\\Block\\Block" block_id="block_identifier"}}
Display CMS Static Block In XML:

Here the code to show CMS Static Block in any layout (XML) file in Magento 2,

<referenceContainer name="content">
    <block class="Magento\Cms\Block\Block" name="block_identifier">
        <arguments>
            <argument name="block_id" xsi:type="string">block_identifier</argument>
        </arguments>
    </block>
</referenceContainer>

Wednesday, 8 May 2019

Magento 2 full page cache invalidates every time

We have found a quick fix without any issues. Go To this file and update below changes.

/vendor/magento/module-page-cache/Observer/FlushCacheByTags.php

Line no 57
Replace this function
public function execute(\Magento\Framework\Event\Observer $observer)
    {
        if ($this->_config->getType() == \Magento\PageCache\Model\Config::BUILT_IN && $this->_config->isEnabled()) {
            $object = $observer->getEvent()->getObject();
            if (!is_object($object)) {
                return;
            }
            $tags = $this->getTagResolver()->getTags($object);

            if (!empty($tags)) {
                $this->getCache()->clean(\Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG, array_unique($tags));
            }
        }
    }
 
 
To

 
public function execute(\Magento\Framework\Event\Observer $observer)
    {
        if ($this->_config->getType() == \Magento\PageCache\Model\Config::BUILT_IN && $this->_config->isEnabled()) {
            $object = $observer->getEvent()->getObject();
            if (!is_object($object)) {
                return;
            }
            $tags = $this->getTagResolver()->getTags($object);

            if (!empty($tags)) {
                $this->getCache()->clean(\Zend_Cache::CLEANING_MODE_MATCHING_TAG, array_unique($tags));
            }
        }
    }
   

 In both function change only  CLEANING_MODE_MATCHING_ANY_TAG from CLEANING_MODE_MATCHING_TAG   
   
After the update a code it's working in my case.

Magento2 : Reset/Change Magento2 admin password

Solution 1.
Go to phpMyAdmin, select the corresponding database and find admin_user table run the foloing query

UPDATE admin_user SET password = CONCAT(SHA2('xxxxxxxxNewpassword', 256), ':xxxxxxxx:1') WHERE username = ‘adminusername';

Note that each xxxxxxxx sequence should be replaced with any random characters.

Solution 2.
Forgot your password? You can change your forgotten or lost password for the admin account. 

Monday, 1 April 2019

Magento 2 : [SOLUTION] Add Bundle product into Cart Programmatically

We have created a script to add bundle product to the cart, programmatically adding all options to the bundle.

It's a simple code and its work perfectly.

create a text file in root directory and past the code then save and run in a browser. Then check the quote table.

test.php
<?php
ini_set('memory_limit','2048M');
use Magento\Framework\App\Bootstrap;
require __DIR__ . '/app/bootstrap.php';
$params = $_SERVER;
$params[Bootstrap::PARAM_REQUIRE_MAINTENANCE] = true; // default false
$params[Bootstrap::PARAM_REQUIRE_IS_INSTALLED] = false; // default true

$bootstrap = Bootstrap::create(BP, $params);

$obj = $bootstrap->getObjectManager();
$state = $obj->get('Magento\Framework\App\State');
$state->setAreaCode('global');

$quote = $obj->get('\Magento\Checkout\Model\Cart');

$product_id=66;
$_product = $obj->create('Magento\Catalog\Model\Product')->load($product_id);
 $selectionCollection = $_product->getTypeInstance(true)
                           ->getSelectionsCollection(
    $_product->getTypeInstance(true)->getOptionsIds($_product),$_product);
    // create bundle option
    $cont = 0;
    $selectionArray = [];
    $selectionqtyArray = [];
    $selectionpriceArray = [];
    foreach ($selectionCollection as $proselection){ 
       
                $selectionArray[$cont] = $proselection->getSelectionId();
                $selectionqtyArray[$cont] = $proselection->getSelectionQty();
                $selectionpriceArray[$cont] = $proselection->getPrice();
                $cont++;
            }
    // get options ids
    $optionsCollection = $_product->getTypeInstance(true)
                ->getOptionsCollection($_product);
   
    foreach ($optionsCollection as $options) {
           $id_option = $options->getId();
                }           
    // generate bundle_option array
    $bundle_option = [$id_option => $selectionArray];
    $bundle_qty = [$id_option => $selectionqtyArray];
    $bundle_price = [$id_option => $selectionpriceArray];
   
   
    $params = [
                'product' => $_product->getId(),
                'bundle_option' => $bundle_option,
                'bundle_option_qty' => $bundle_qty,
                'bundle_option_price' => $bundle_price,                           
                'qty' => 1,
                'original_qty' => 1
              ]; 
             
 $quote->addProduct($_product, $params);
 $quote->save();
//echo "<pre>";
//print_r($params);

?>

Please feel free to contact me any M1 & M2 issue at any time.


Regards
Kuldeep Singh
kuldeep4110@gmail.com