Thursday 4 June 2020

Magento 2 all essential command line

To enable the cache:
php bin/magento cache:enable

To disable the cache:
php bin/magento cache:disable

To flush the cache:
php bin/magento cache:flush

A short command line:
php bin/magento c:f

To clean the cache in the website:
php bin/magento cache:clean

A short command line:
php bin/magento c:c


To view a list of all indexers:
php bin/magento indexer:info

View indexer status:
php bin/magento indexer:status

Reindex Command options:
php bin/magento indexer:reindex

If you want to reindex only one indexer then write following command:
php bin/magento indexer:reindex indexer_name
ex: php bin/magento indexer:status catalog_category_product

In case you fill memory limit, try this command
php -d memory_limit=10G bin/magento indexer:reindex

If any index is looping You can reset all index by using
php bin/magento indexer:reset

Current application mode:
php bin/magento deploy:mode:show

Set to production mode:
php bin/magento deploy:mode:set production

Set to developer mode:
php bin/magento deploy:mode:set developer

Set to default mode:
php bin/magento deploy:mode:set default


To install a non-optional CRON job:
php bin/magento cron:install

To remove the Magento crontab:
php bin/magento cron:remove

Run cron from the command line:
php bin/magento cron:run

To run the indexing cron job, enter:
php bin/magento cron:run --group index

To run the default cron job, enter:
php bin/magento cron:run --group default

If you enabled one or more modules, then you will need to run magento
setup:upgrade to update the database schema:
php bin/magento module:enable Nwdthemes_Module
php bin/magento setup:upgrade

1.Reach out to Smartwave extension's support team to
get the idea if they have any fix or suggestion.

2.If you do not need Smartwave_Dailydeals extension than
disable that extension / module and compile again.
3. on Magento Stack exchange a similar bug is reported
and is fixed as well, please try if that helps to fix your issue
:-
php bin/magento setup:di:compile

Simple run the following command line to deploy static content
your store when install / update an extension:
php bin/magento setup:static-content:deploy

Magento admin user created by command line:
php bin/magento admin:user:create --admin-user='adminuser' --admin-password='admin#123' --admin-email='test@test.com' --admin-firstname='Test' --admin-lastname='Tester'

How to Unlock Admin User via Command Line:
php bin/magento admin:user:unlock username
ex php bin/magento admin:user:unlock admin


Thursday 30 April 2020

How To Validate Custom Form in Magento 2

<form class="form" id="custom-form" method="post" autocomplete="off" data-mage-init='{"validation": {}}'>

   <fieldset class="fieldset">

       <legend class="legend"><span><?php echo __('Personal Information') ?></span></legend><br>
     
       <div class="field name required">
          <label class="label"><?php echo __('Name') ?>:</label>
          <div class="control">
            <input type="text"  name="name" id="name" class="input-text"  data-validate="{required:true, }" />
          </div>
      </div>

        <div class="field email required">

            <label for="email_address" class="label"><span><?php echo __('Email') ?></span></label>

            <div class="control">

                <input type="email" name="email" id="email" value="" title="<?php echo __('Email') ?>" class="input-text" data-validate="{required:true, 'validate-email':true}">

            </div>

        </div>

   </fieldset>

   <div class="actions-toolbar">

        <div class="primary">

            <button type="submit" class="action submit primary" title="<?php  echo __('Submit') ?>"><span><?php echo __('Submit') ?></span></button>

        </div>

    </div>

</form>



<script type="text/javascript">

require([

    'jquery',

    'mage/mage'

], function($){



   var dataForm = $('#custom-form');

   dataForm.mage('validation', {});



});

</script>

Wednesday 8 April 2020

Magento 2.x | Can't Access Web Setup Wizard | Welcome to Magento Admin, your online store headquarters. To use the Magento setup wizard sign into your Admin account and navigate to System => Tools => Web Setup Wizard


Solution for me was:
Base URLs (Secure)
-> Use Secure URLs on Storefront -> Yes
-> Use Secure URLs in Admin -> Yes
-> Enable HTTP Strict Transport Security (HSTS) -> Yes
-> Upgrade Insecure Requests -> Yes
php bin/magento cache:clean

I SOLVE THIS.

Friday 3 April 2020

Magento 2 how to move category title to above description

catalog_category_view.xml at below location

app/design/frontend/Package/theme/Magento_Catalog/view/frontend/layout

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="2columns-left" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
    <move element="columns.top" destination="content" before="-"/>
    </body>
</page>

Thursday 2 April 2020

How to Expand default Layered Navigation Category Filters in Magento 2

app\design\frontend\Themes\Yourtheme\Magento_LayeredNavigation\templates\layer\view.phtml
Now, Search for the below code, you will find that code around line no-32.


<?php foreach ($block->getFilters() as $filter): ?>
                <?php if ($filter->getItemsCount()): ?>
                    <?php if (!$wrapOptions): ?>
                        <strong role="heading" aria-level="2" class="block-subtitle filter-subtitle"><?= / @escapeNotVerified / __('Shopping Options') ?></strong>
                        <div class="filter-options" id="narrow-by-list" data-role="content" data-mage-init='{"accordion":{"openedState": "active", "collapsible": true, "active": false, "multipleCollapsible": false}}'>
                    <?php  $wrapOptions = true; endif; ?>
                    <div data-role="collapsible" class="filter-options-item">
                        <div data-role="title" class="filter-options-title"><?= / @escapeNotVerified / __($filter->getName()) ?></div>
                        <div data-role="content" class="filter-options-content"><?= / @escapeNotVerified / $block->getChildBlock('renderer')->render($filter) ?></div>
                    </div>
                <?php endif; ?>
            <?php endforeach; ?>


 And replace that piece code with below-given code.

 <?php foreach ($block->getFilters() as $filter): ?>
<?php if ($filter->getItemsCount()): ?>
    <?php if (!$wrapOptions): ?>
        <?php $collapsibleRange = implode(' ', range(0, $filter->getItemsCount())); ?>
        <strong role="heading" aria-level="2" class="block-subtitle filter-subtitle"><?php /* @escapeNotVerified */ echo __('Shopping Options') ?></strong>
        <div class="filter-options" id="narrow-by-list" data-role="content" data-mage-init='{"accordion":{"openedState": "active", "collapsible": true, "active": "<?php echo $collapsibleRange ?>", "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; ?>

How to move “Add to Wishlist” Button after “Add to Cart” in Product View page in magento 2

Just add below code to catalog_product_view.xml file for the simple and configurable product:


For Simple Product
<referenceBlock name="product.info.addtocart">
     <block class="Magento\Wishlist\Block\Catalog\Product\View\AddTo\Wishlist" name="view.addto.wishlist" template="Magento_Catalog::product/view/addto/wishlist.phtml" />
 </referenceBlock>

 For Configurable Product
  <referenceBlock name="product.info.addtocart.additional">
     <block class="Magento\Wishlist\Block\Catalog\Product\View\AddTo\Wishlist" name="view.addto.wishlist.bottom" template="Magento_Catalog::product/view/addto/wishlist.phtml" />
 </referenceBlock>

Wednesday 1 April 2020

Magento2 : How to change product thumbnail image gallery horizontal to vertical?

You can configure slider in view.xml file.
It located in /app/design/frontend/vendor_name/theme_folder/etc/view.xml.
There you can write vars for gallery. For luma theme it looks like this
change this tag <var name="navdir">horizontal</var> 


-------------------------------------------------------------------------------------------
<?xml version="1.0"?>
<!--
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<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="small_image">
                <width>240</width>
                <height>300</height>
            </image>
            <image id="cart_page_product_thumbnail" type="small_image">
                <width>165</width>
                <height>165</height>
            </image>
            <image id="category_page_grid" type="small_image">
                <width>240</width>
                <height>300</height>
            </image>
            <image id="category_page_grid-1" type="small_image">
                <width>240</width>
                <height>300</height>
            </image>
            <image id="category_page_list" type="small_image">
                <width>240</width>
                <height>300</height>
            </image>
            <image id="customer_account_my_tags_tag_view" type="small_image">
                <width>100</width>
                <height>100</height>
            </image>
            <image id="customer_account_product_review_page" type="image">
                <width>285</width>
                <height>285</height>
            </image>
            <image id="customer_shared_wishlist" type="small_image">
                <width>113</width>
                <height>113</height>
            </image>
            <image id="gift_messages_checkout_small_image" type="small_image">
                <width>75</width>
                <height>75</height>
            </image>
            <image id="gift_messages_checkout_thumbnail" type="thumbnail">
                <width>100</width>
                <height>100</height>
            </image>
            <image id="mini_cart_product_thumbnail" type="thumbnail">
                <width>75</width>
                <height>75</height>
            </image>
            <image id="new_products_content_widget_grid" type="small_image">
                <width>240</width>
                <height>300</height>
            </image>
            <image id="new_products_content_widget_list" type="small_image">
                <width>270</width>
                <height>340</height>
            </image>
            <image id="new_products_images_only_widget" type="small_image">
                <width>78</width>
                <height>78</height>
            </image>
            <image id="product_base_image" type="image">
                <width>265</width>
                <height>265</height>
            </image>
            <image id="product_comparison_list" type="small_image">
                <width>140</width>
                <height>140</height>
            </image>
            <image id="product_page_image_large" type="image"/>
            <image id="product_page_image_medium" type="image">
                <width>700</width>
                <height>700</height>
            </image>
            <image id="product_page_image_small" type="thumbnail">
                <width>88</width>
                <height>110</height>
            </image>
            <image id="product_swatch_image_large" type="image"/>
            <image id="product_swatch_image_medium" type="image">
                <width>240</width>
                <height>300</height>
            </image>
            <image id="product_swatch_image_small" type="thumbnail">
                <width>88</width>
                <height>110</height>
            </image>
            <image id="product_page_main_image" type="image">
                <width>700</width>
                <height>560</height>
            </image>
            <image id="product_page_main_image_default" type="image">
                <width>700</width>
                <height>560</height>
            </image>
            <image id="product_page_more_views" type="thumbnail">
                <width>88</width>
                <height>110</height>
            </image>
            <image id="product_stock_alert_email_product_image" type="small_image">
                <width>76</width>
                <height>76</height>
            </image>
            <image id="product_small_image" type="small_image">
                <width>135</width>
                <height>135</height>
            </image>
            <image id="product_thumbnail_image" type="thumbnail">
                <width>75</width>
                <height>75</height>
            </image>
            <image id="recently_compared_products_grid_content_widget" type="small_image">
                <width>240</width>
                <height>300</height>
            </image>
            <image id="recently_compared_products_images_names_widget" type="thumbnail">
                <width>75</width>
                <height>90</height>
            </image>
            <image id="recently_compared_products_images_only_widget" type="thumbnail">
                <width>76</width>
                <height>76</height>
            </image>
            <image id="recently_compared_products_list_content_widget" type="small_image">
                <width>270</width>
                <height>340</height>
            </image>
            <image id="recently_viewed_products_grid_content_widget" type="small_image">
                <width>240</width>
                <height>300</height>
            </image>
            <image id="recently_viewed_products_images_names_widget" type="small_image">
                <width>75</width>
                <height>90</height>
            </image>
            <image id="recently_viewed_products_images_only_widget" type="small_image">
                <width>76</width>
                <height>76</height>
            </image>
            <image id="recently_viewed_products_list_content_widget" type="small_image">
                <width>270</width>
                <height>340</height>
            </image>
            <image id="related_products_list" type="small_image">
                <width>152</width>
                <height>190</height>
            </image>
            <image id="review_page_product_image" type="small_image">
                <width>285</width>
                <height>285</height>
            </image>
            <image id="rss_thumbnail" type="thumbnail">
                <width>75</width>
                <height>75</height>
            </image>
            <image id="sendfriend_small_image" type="small_image">
                <width>75</width>
                <height>75</height>
            </image>
            <image id="shared_wishlist_email" type="small_image">
                <width>135</width>
                <height>135</height>
            </image>
            <image id="side_column_widget_product_thumbnail" type="thumbnail">
                <width>75</width>
                <height>90</height>
            </image>
            <image id="upsell_products_list" type="small_image">
                <width>152</width>
                <height>190</height>
            </image>
            <image id="wishlist_sidebar_block" type="thumbnail">
                <width>75</width>
                <height>90</height>
            </image>
            <image id="wishlist_small_image" type="small_image">
                <width>113</width>
                <height>113</height>
            </image>
            <image id="wishlist_thumbnail" type="small_image">
                <width>240</width>
                <height>300</height>
            </image>
        </images>
    </media>
    <vars module="Magento_Catalog">

        <!-- Gallery and magnifier theme settings. Start -->
        <var name="gallery">
            <var name="nav">thumbs</var> <!-- Gallery navigation style (false/thumbs/dots) -->
            <var name="loop">true</var> <!-- Gallery navigation loop (true/false) -->
            <var name="keyboard">true</var> <!-- Turn on/off keyboard arrows navigation (true/false) -->
            <var name="arrows">true</var> <!-- Turn on/off arrows on the sides preview (true/false) -->
            <var name="caption">false</var> <!-- Display alt text as image title (true/false) -->
            <var name="allowfullscreen">true</var> <!-- Turn on/off fullscreen (true/false) -->
            <var name="navdir">horizontal</var> <!-- Sliding direction of thumbnails (horizontal/vertical) -->
            <var name="navarrows">true</var> <!-- Turn on/off on the thumbs navigation sides arrows(true/false) -->
            <var name="navtype">slides</var> <!-- Sliding type of thumbnails (slides/thumbs) -->
            <var name="transition">
                <var name="effect">slide</var> <!-- Sets transition effect for slides changing (slide/crossfade/dissolve) -->
                <var name="duration">500</var> <!-- Sets transition duration in ms -->
            </var>
            <var name="fullscreen">
                <var name="nav">thumbs</var> <!-- Fullscreen navigation style (false/thumbs/dots) -->
                <var name="loop">true</var> <!-- Fullscreen navigation loop (true/false/null) -->
                <var name="arrows">true</var> <!-- Turn on/off arrows on the sides preview in fullscreen (true/false/null) -->
                <var name="caption">false</var> <!-- Display alt text as image title in fullscreen(true/false) -->
                <var name="navdir">horizontal</var> <!--Sliding direction of thumbnails in fullscreen(horizontal/vertical)  -->
                <var name="navarrows">false</var> <!-- Turn on/off on the thumbs navigation sides arrows(true/false) -->
                <var name="navtype">slides</var> <!-- Sliding type of thumbnails (slides/thumbs) -->
                <var name="transition">
                    <var name="effect">slide</var> <!-- Sets transition effect for slides changing (slide/crossfade/dissolve) -->
                    <var name="duration">500</var> <!-- Sets transition duration in ms -->
                </var>
            </var>
        </var>

        <var name="magnifier">
            <var name="fullscreenzoom">20</var>  <!-- Zoom for fullscreen (integer)-->
            <var name="top"></var> <!-- Top position of magnifier -->
            <var name="left"></var> <!-- Left position of magnifier -->
            <var name="width"></var> <!-- Width of magnifier block -->
            <var name="height"></var> <!-- Height of magnifier block -->
            <var name="eventType">hover</var> <!-- Action that atcivates zoom (hover/click) -->
            <var name="enabled">false</var> <!-- Turn on/off magnifier (true/false) -->
            <var name="mode">outside</var> <!-- Zoom type (outside/inside) -->
        </var>

        <var name="breakpoints">
            <var name="mobile">
                <var name="conditions">
                    <var name="max-width">767px</var>
                </var>
                <var name="options">
                    <var name="options">
                        <var name="nav">dots</var>
                    </var>
                </var>
            </var>
        </var>
        <!-- end. Gallery and magnifier theme settings -->

        <var name="product_small_image_sidebar_size">100</var>  <!-- Override for small product image -->
        <var name="product_base_image_size">275</var>           <!-- Override for base product image -->
        <var name="product_base_image_icon_size">48</var>       <!-- Base product image icon size -->

        <var name="product_list_image_size">166</var>           <!-- New Product image size used in product list -->
        <var name="product_zoom_image_size">370</var>           <!-- New Product image size used for zooming -->

        <var name="product_image_white_borders">1</var>
    </vars>
    <vars module="Magento_Bundle">
        <var name="product_summary_image_size">58</var>         <!-- New Product image size used for summary block-->
    </vars>

    <vars module="Magento_ConfigurableProduct">
        <var name="gallery_switch_strategy">prepend</var>
    </vars>

    <vars module="Js_Bundle">
        <var name="bundle_size">1MB</var>
    </vars>
    <exclude>
        <item type="file">Lib::jquery/jquery.min.js</item>
        <item type="file">Lib::jquery/jquery-ui-1.9.2.js</item>
        <item type="file">Lib::jquery/jquery.details.js</item>
        <item type="file">Lib::jquery/jquery.hoverIntent.js</item>
        <item type="file">Lib::jquery/colorpicker/js/colorpicker.js</item>
        <item type="file">Lib::requirejs/require.js</item>
        <item type="file">Lib::requirejs/text.js</item>
        <item type="file">Lib::legacy-build.min.js</item>
        <item type="file">Lib::mage/captcha.js</item>
        <item type="file">Lib::mage/dropdown_old.js</item>
        <item type="file">Lib::mage/list.js</item>
        <item type="file">Lib::mage/loader_old.js</item>
        <item type="file">Lib::mage/webapi.js</item>
        <item type="file">Lib::mage/zoom.js</item>
        <item type="file">Lib::mage/translate-inline-vde.js</item>
        <item type="file">Lib::mage/requirejs/mixins.js</item>
        <item type="file">Lib::mage/requirejs/static.js</item>
        <item type="file">Magento_Customer::js/zxcvbn.js</item>
        <item type="file">Magento_Catalog::js/zoom.js</item>
        <item type="file">Magento_Ui::js/lib/step-wizard.js</item>
        <item type="file">Magento_Ui::js/form/element/ui-select.js</item>
        <item type="file">Magento_Ui::js/form/element/file-uploader.js</item>
        <item type="file">Magento_Ui::js/form/components/insert.js</item>
        <item type="file">Magento_Ui::js/form/components/insert-listing.js</item>
        <item type="directory">Magento_Ui::js/timeline</item>
        <item type="directory">Magento_Ui::js/grid</item>
        <item type="directory">Magento_Ui::js/dynamic-rows</item>
        <item type="directory">Magento_Ui::templates/timeline</item>
        <item type="directory">Magento_Ui::templates/grid</item>
        <item type="directory">Magento_Ui::templates/dynamic-rows</item>
        <item type="directory">Magento_Swagger::swagger-ui</item>
        <item type="directory">Magento_Tinymce3::tiny_mce</item>
        <item type="directory">Lib::modernizr</item>
        <item type="directory">Lib::tiny_mce</item>
        <item type="directory">Lib::varien</item>
        <item type="directory">Lib::jquery/editableMultiselect</item>
        <item type="directory">Lib::jquery/jstree</item>
        <item type="directory">Lib::jquery/fileUploader</item>
        <item type="directory">Lib::css</item>
        <item type="directory">Lib::lib</item>
        <item type="directory">Lib::extjs</item>
        <item type="directory">Lib::prototype</item>
        <item type="directory">Lib::scriptaculous</item>
        <item type="directory">Lib::less</item>
        <item type="directory">Lib::mage/adminhtml</item>
        <item type="directory">Lib::mage/backend</item>
    </exclude>
</view>

Tuesday 17 March 2020

How to set default custom option selected in magento 2

<script>
require(['jquery', 'jquery/ui'], function($){
  $('.product-add-form .field select').each(function(i, obj) {
    $(obj).find('option:eq(1)').prop('selected', true);
  });
});
</script>

OR
$('.product-add-form .field select').each(function(i, obj) {
  $(obj).find('option:eq(1)').prop('selected', true);
 });

Friday 7 February 2020

Magento 2 get product custom option details in phtml file

protected $_customOption;

\Magento\Catalog\Model\Product\Option $customOption,

$this->_customOption = $customOption;

public function customOption($product)
{
$custom = $this->_customOption->getProductOptionCollection($product);

if(!empty($custom)):
foreach($custom as $option):
$values = $option->getValues();
if(!empty($values)):
foreach($values as $value):
$valueData[] = $value->getData();
endforeach;
return $valueData;
else:
return 'Product has no custom option value';
endif;
endforeach;
else:
return 'Product does not have custom options';
endif;
}

Thursday 6 February 2020

How to remove product custom option '+' symbol in magento 2

/app/design/frontend/venderName/softtouch/Magento_Catalog/templates/product/view/options/type/select.phtml

<script>
  require([
   'jquery',
   'domReady!'
   ], function ($) {
       $(document).ready(function () {
           $('select.product-custom-option').change(function(){
               $('option').each(function(){
                   var selectedOption = $(this).text();
                 
                   if (selectedOption.indexOf('+') > -1) {
                        var replaced = selectedOption.replace('+', ' ');
                       // selectedOption = selectedOption.substring(0, selectedOption.indexOf('+'));
                        $(this).text(replaced);
                   } else if (selectedOption.indexOf('-') > -1) {
                        //selectedOption = selectedOption.substring(0, selectedOption.indexOf('-'));
                        var replaced = selectedOption.replace('+', ' ');
                        $(this).text(replaced);
                   }
               });   
           });   
       });
    });
</script>

Monday 13 January 2020

How To Migrate From Magento 1 To Magento 2 Without Breaking Anything.

You migration the latest magento 2 version . Mention the vertion for example data-migration-tool:2.3.3

composer config repositories.magento composer https://repo.magento.com
composer require magento/data-migration-tool:2.3.3


Edit config.xml file :-
Path: /vendor/magento/data-migration-tool/etc/opensource-to-opensource/1.9.2.
 <source>
        <database host="localhost" name="rene_copy_db" user="root" password="nopass" />
    </source>
    <destination>
        <database host="localhost" name="rene_m2_db" user="root" password="nopass" />
    </destination>
Also added this value crypt_key (from magento 1.9):
<crypt_key>sony</crypt_key>

From version mention  for example :/opensource-to-opensource/1.9.2.4/config.xml

Path: /vendor/magento/data-migration-tool/etc/opensource-to-opensource/1.9.2.4
map.xml

copy magento 1.9 media folder  to magento 2  media folder (pub/)

php bin/magento migrate:settings vendor/magento/data-migration-tool/etc/opensource-to-opensource/1.9.2.4/config.xml
php bin/magento migrate:data -a vendor/magento/data-migration-tool/etc/opensource-to-opensource/1.9.2.4/config.xml




Saturday 11 January 2020

Installing composer in Ubuntu / Linux

Step 1: sudo apt-get remove composer
Step 2: php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
Step 3: php -r "if (hash_file('sha384', 'composer-setup.php') === 'baf1608c33254d00611ac1705c1d9958c817a1a33bce370c0595974b342601bd80b92a3f46067da89e3b06bff421f182') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer

Step 4: php -r "unlink('composer-setup.php');"

Step 5: sudo service apache2 restart
Step 6: System restart