Skip to main content

magento

How to redirect a customer to another URL from Observer

In order to redirect a customer from observer you need to use another way than the Controller 

 

protected $_response;
protected $_objectManager;
public function __construct(
    \Magento\Framework\App\ResponseInterface $response,
    \Magento\Framework\ObjectManagerInterface $objectManager,
    ) {
        $this->_response = $response;
       $this->_objectManager = $objectManager;
   }

 

then in your function you can use this 

 

Magento2- How Magento cache clearing works with Varnish

According to Varnish documentation, “A purge is what happens when you pick out an object from the cache and discard it along with its variants.” A Varnish purge is very similar to a Magento cache clean command (or clicking Flush Magento Cache in the Magento Admin).

In fact, as discussed in this section, when you clean, flush, or refresh the Magento cache, Varnish purges as well.

 

Configure Magento to purge Varnish

execute this code 

bin/magento setup:config:set --http-cache-hosts=192.0.2.100,192.0.2.155:6081

Magento 2 Allowed Memory exhausted error when compile code

you need to increase the memory_limit in php.ini

and as a quick solution you can use these commands directly in the command line

 

php -dmemory_limit=5G bin/magento setup:di:compile

and 

php -dmemory_limit=5G bin/magento setup:static-content:deploy

 

 

another code for the composer update

php -dmemory_limit=5G composer.phar update

php -d memory_limit=-1 /usr/local/bin/composer update
 

 

Getting error when try to save shipping information for user using magento 2 api

Unable to save address. Please check input data.

It's a strange error we have it sometime, to solve it in some cases you execute this query 

SELECT entity_id, customer_id FROM quote WHERE customer_id != 0 AND customer_is_guest = 1;

and then update the records by this query 

UPDATE quote SET customer_is_guest = 0 WHERE customer_id != 0 AND customer_is_guest = 1;

reference url :

https://stackoverflow.com/a/58086757/4135373

Magento2- Remove plus sign from the configurable product attributes that have additional price

To do this we need to work on the design area it is the easiest way 

firs Create new folder under your theme 

Folder Name: Magento_ConfigurableProduct\web\js

Copy this file "configurable.js" from this path

vendor/magento/module-configurable-product/view/frontend/web/js/configurable.js 

in the line 407 you need to modify this part

 

Magento2 use equal in email template

In this wiki we will find a way to use "==" equal in the email template, actually there is no equal in the email template itself but we can refer to a phtml file and pass a variable to it then use the if/equal in the phtml file to do this you can easily add this code to the template 

in the below example we will check if the payment method is bank transfer then we will write something