magento
Programmatically Assign Attribute to All Attribute Sets in Magento 2
I will put here the way to add an attribute group then assign an attribute into all attribute set with this group, please note I am using the dirty way to add it so you will need to follow the Dependency injection in your code to have the same result
Error after upgrade Magento into version 2.4.4 with PHP 8.1
After upgrading Magento to version 2.4.4 and PHP 8.1, you might have this error
Type Error occurred when creating object: Magento\Framework\Communication\Config\Data, Magento\Framework\Reflection\TypeProcessor::resolveFullyQualifiedClassName(): Argument #2 ($typeName) must be of type string, null given, called in /{magento_root}/vendor/magento/framework/Reflection/TypeProcessor.php on line 550
Magento 2 – How to identify current page in phtml file?
Magento 2 – How to identify current page in phtml file?
$currentFullAction = $block->getRequest()->getFullActionName();
$catpages= array('catalog_category_view','catalog_product_view');
if(in_array($currentFullAction, $catpages)){
//Catalog page
}
How do you add translation for extensions in Magento2?
How do you add translation for extensions in Magento2?
Then generate the dictionary with magento shell tool; from :
php bin/magento i18n:collect-phrases -o app/code/{Vendor}/{Module}/i18n/en_US.csv app/code/{Vendor}/{Module}/
do not forget to replace {Vendor} and {Module} with your correct information
Disable Coupon in Magento2 in the cart and in the checkout
The best approche is to add these files "checkout_cart_index.xml" and "checkout_index_index.xml" in this directory
app/design/frontend/{Vendor}/{theme}/Magento_Checkout/layout/
with this content
checkout_cart_index.xml
Magento 2 static files are not working
How many times you tried to install Magento 2 and later you could not see the website working !!, How many times you tried to search for these sentences
"Magento 2 css not working"
"Magento 2 js not working"
"Magento 2 404 page not found" because of the static files?
Now here is the solution, and easily it is the missed .htaccess (for apache)
by quick look at this path "{magento root}/pub/static", you will see that you missed the .htaccess file
Magento 2 how to configure Nginx to allow execute phpinfo.php files in root folder
Go to the Nginx configuration then you need to edit the line similar to this line
location ~ (index|get|static|report|404|503)\.php$ {
to be like this
location ~ (index|get|static|report|404|503|phpinfo)\.php$ {
then restart Nginx
Change Magento search engine using CLI
You can use the Magento 2 CLI to do it, you can check your current search engine using:
php -f bin/magento config:show catalog/search/engine
if you want to change the engine to Elasticseach version 6 then use this command
php -f bin/magento config:set catalog/search/engine 'elasticsearch6'
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