Magento2
Power your online business with the most flexible and scalable ecommerce platform
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
Get on Sales Product between dates Magento2
Referene Class is : {magento root}\vendor\magento\module-catalog-widget\Block\Product\ProductsList.php
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
}
Install Magento2.4.x using command line
Install Magento2.4.x using command line
You must use the command line to install Magento.
This example assumes that the Magento install directory is named magento2ee, the db-host is on the same machine (localhost), and that the db-name, db-user, and db-password are all magento:
Edit Magento Local Cache Storage Offline (Magento2)
Edit Magento Local Cache Storage Offline (Magento2)
Sometimes we might need to change something in the Local storage of Magento , the local storage is saved in this key ("mage-cache-storage")
I will put now an example to edit the selected shipping address in the checkout shipping section
Magento 2 search results relevance with elasticsearch?
Magento 2.3 still use "OR" logic for mysql and elasticsearch. Plus "should" conditions (query to ES) are wrong. That's why relevance almost same. But ES significantly improve performance of search and catalog (layered navigation).
you have to set AND operator in your elastic search json queries, Override the module-elasticsearch/SearchAdapter/Query/Builder/Match.php. file in your custom module and then The code you have to edit in the build function in line no 75
Database backup missing table information "inventory_stock_1" #19542
Database backup missing table information "inventory_stock_1"
The CREATE ALGORITHM statement requires elevated MySQL access.
It is likely that the server you are working on does not have this and will halt the import process.
This line needs to come out of the SQL being migrated.
Instead run the following to create the view
Magento2 Configuration values per deafferent scopes
in order to get any value per specific scope you can use the below parameters
First you need to initialize scopeConfig
* @var \Magento\Framework\App\Config\ScopeConfigInterface */ protected $_scopeConfig;
in the constrructer of your class
Get total weight of the cart in Magento2
Get total weight of the cart in Magento2
in order to get the total weight of the cart you can use two main methods, we will list them here
First Method
$weight = {getQuote()}
->getShippingAddress()
->getWeight();
Second method
$items = {getQuote()}->getAllItems();
$weight = 0;
foreach($items as $item) {
$weight += ($item->getWeight() * $item->getQty()) ;
}
echo $weight;