Magento 2
Category

By In Magento 2

Quickly Refresh Cache in Magento 2

If you are a developer that works with Magento 2, you surely know-how clearing cache in Magento can be a boring thing. Thanks to built-in full page cache Magento front-end works quite fast, however, in most cases, your changes will not be seen unless you don’t refresh the cache.

Even Magento will remind you to do that through a notification system when you make any significant change in the back-end.

OK, most of the developers will simply use CLI to clear cache, there are few commands that help.

Clean cache: php bin/magento cache:clean

Clean cache short version: php bin/magento c:c

Flush cache: php bin/magento cache:flush

Flush cache short version: php bin/magento c:f

In case you are not comfortable with shell, you might need to refresh the cache from your browser. While it is just a few clicks, it will soon become boring if you have to do that several times within an hour.

But, there is a really nice solution for such a case, a small add-on for Chrome that will allow you to clear cache in just one click.

Add-on can be installed from the link below:

Quick M2 Cache Refresh Tool

Features:

  • New refresh button in Cache Management page.
  • New keyboard shortcuts for the active Cache Management page.
  • All opened Cache Management pages listed in popup.
  • Quick and full refresh buttons available in popup.
  • Always visible number of open Cache Management pages.

Add-on support Magento from version 2.x and Chrome from version 79.x (any way you should always allow Chrome to update itself latest version).

Add-on is made by Nikola Tujković a full-time back-end developer from SMDesign Studio, all kudos go to him. If you like add-on be sure to leave a review and share it with your friends.

Cheers 🙂

Read more

By In Magento 2

White page issue – Magento 2

Another very common issue in Magento 2 are white pages in back end, error that I resolved was related to Credit Memo functionality but similar method can be applied to similar issues as well.

To describe issue a bit more, I went to Sales > Order Management > Orders and selected order that should be refunded. Issue was found on several orders and they were made using Authorize.net or PayPal payment), so I excluded possibility that custom payment method could cause issue.

In order screen I clicked Credit Memo button and landed on white page without any error message or notification. Since there were no errors in browser console (wanted to check for java script errors), I checked var/log/systemlog file and found error log:

main.CRITICAL: Broken reference: No element found with ID ‘before.body.end’.

After checking few topics about issue and suggested solutions I decided to try simplest one, to update XML file and add missing layout parameter.

For the sake of test I deiced to edit core file at line #8:

html/vendor/magento/module-sales/view/adminhtml/layout/sales_creditmemo_index.xml

and changed original code:

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">

to:

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">

After that change I was able to open all test orders and perform Credit Memo without any issues, also there were no errors in log files.
To prevent change to be deleted on next Magento update I suggest that you overwrite core layout file with your own.
Magento 2 devdocs provide solid guide how to do that:

Read more

By In Magento 2

Limit free shipping by total weight – Magento 2

Magento 2 basic installation have three ‘offline’ shipping methods included: free shipping, flat rate and table rates.

They are called ‘offline’ because all shipping rates will be calculated using offline resources, basically only ‘table rates’ use advanced math and calculate fee according to provided CSV file.

Magento 2 also comes with four more shipping methods, dimensional weight methods (DHL, FedEx, UPS, USPS), that use external data to calculate how much customers have to pay for shipping.

 

Most popular  ‘offline’ shipping method among customers is ‘free shipping’, everybody loves free shipping, they will pay just for products and there is no extra fee – great right 🙂

Now comes tricky part, free shipping has only one condition which is

One of our customers that have store based on Magento 2 platform noticed that among all stuff that they sell there are products that are heavy or bulky to be sent via regular shipping, however price of those products was high enough to enable free shipping. So his request was quite simple, to limit free shipping option to 120 lbs. of total cart weight, if items in cart go above that value ‘free shipping’ shouldn’t be available.

So we made small module that extend Magento ‘free shipping’ module by adding more field in Shipping Methods > Free Shipping tab, where admin can enter maximal weight for free shipping.

Here is the screen shot of admin section after we deployed our mini module:

Magento 2 - Free shipping method settings

Magento 2 – Free shipping method settings

Module simply extend condition that is located in Carrier file (notice that we added Rewrite folder to remeber that module overwrites core module):

app\code\Smdesign\FreeShipping\Model\Rewrite\Carrier\Freeshipping.php

so we now have too conditions that need to be fulfilled: Minimum Order Amount and 

Instead copying parts of code and explaining every  line I decided to provide module as package (please backup everything before deploy it) and I am quite sure that you will manage to grasp code in it.

 

Unpack archive into your Magento 2 installation root folder, navigate to /bin folder or use path in command line (as you like) and run commands in console:

magento module:enable Smdesign_FreeShipping

magento setup:upgrade

Please don’t hesitate to post comments I appreciate your feedback, any idea, improvement or reported bug/issue are more than welcome.

I am new to Magento 2 but eager to learn it and hope that will be able to post about it often.

Cheers 🙂



 

 

Read more