Page 6 - Monthly Archives: 2021
- 2 min read
When developing an online store based on Magento 2, you might face the problem of extending the standard Magento 2 or functionality.
Editing Magento core files or modules is not allowed because these changes will be overwritten during the .
So, how to make changes to the storefront (frontend) template file, css, js?
WARNING! The following instructions cannot be used to override the layout files.
Override module view-files in the app/code folder.
Let's say you need to change this file:
app/code/Magefan/Blog/view/frontend/templates/post/view.phtml
Make its copy in the theme folder with the following path:
app/design/frontend/ThemeVendor/themename/Magefan_Blog/templates/post/view.phtml
Make the necessary changes to the newly created theme file.
If your own theme is missing from your Magento installation, create new theme.
Override module view-files in the vendor folder.
Let's say you need to change this file:
vendor/magefan/module-blog/view/frontend/web/css/blog-custom.css
Make its copy inihor
- 2 min read
If you get an error "An element with a “root” ID already exists" in your Magento 2, it is, most likely, related to a third-party extension that calls methods to re-render a page.
To fix the "An element with a “root” ID already exists" error:
1. Find a PHP file and a line that throws an exception.
2. Open CLI (terminal), navigate to the Magento root directory, and run the following commands to find the proper file:
grep vendor/ -re ' ID already exists'grep app/ -re ' ID already exists'
As a result, you will get an output similar to this:
vendor/magento/framework/Data/Form.php: 'An element with a "' . $elementId . '" ID already exists.'vendor/magento/framework/Data/Test/Unit/FormTest.php: $this->expectExceptionMessage('An element with a "1" ID already exists.');vendor/magento/framework/Data/Structure.php: new \Magento\Framework\Phrase('An element with a "%1" ID already exists.', [$elementId])
3. Then open each file (except *Test.php) and put a and exit function before each throws an exceptionihor
- 2 min read
If you want to change type from dropdown to text in Magento 2, all you need to do is to run the following SQL queries (please make a Database backup before execution):
1. This query will change the attribute settings and convert it to a text attribute.
UPDATE eav_attribute SET backend_type = "varchar", frontend_input = "text", source_model = ""WHERE attribute_code = "MY_ATTRIBUTE_CODE";
2. This query will copy dropdown attribute data to the text attribute value table and replace the option IDs with their actual labels (text).
INSERT INTO catalog_product_entity_varchar SELECT null as value_id, pei.attribute_id, pei.store_id, pei.entity_id, aov.value as value FROM catalog_product_entity_int pei LEFT JOIN eav_attribute_option ao ON pei.attribute_id = ao.attribute_id LEFT JOIN eav_attribute_option_value aov ON ao.option_id = aov.option_id WHERE pei.value IS NOT NULL AND pei.attribute_id = (SELECT attribute_id FROM eav_attribute WHERE attribute_code = "MY_ATTRIBUTE_CODE") AND aov.store_id =ihor
- 2 min read
Sometimes, during you need to get the store Information programmatically. You may need to get a current Store ID, Store Code, Name, Website ID, or .
To retrieve this data use the singleton instance of the following class:
\Magento\Store\Model\StoreManagerInterface
For example, you can include it in your class constructor and then call:
<?phpnamespace \MyCompany\ExampleModule\Model;class Example{ private $storeManager;
public function __construct(
...
\Magento\Store\Model\StoreManagerInterface $storeManager,
...
) { ...
$this->storeManager = $storeManager;
...
}
/** * Examples */ public function execute() { /* Get Current Store ID */ $storeId = $this->storeManager->getStore()->getId(); /* Get Current Store Code */ $storeCode = $this->storeManager->getStore()->getCode(); /* Get Current Store Name */ $storeName = $this->storeManager->getStore()->getName(); /* Get Current Storeihor
- 1 min read
Get URL in the .phtml template files
1. Get URL of the store homepage (http://domain.com/):
<?= $this->getUrl() ?>
2. Get URL of some page, e.g. "Contact Us" (http://domain.com/contacts/):
<?= $this->getUrl('contacts') ?>
3. Get URL of the theme static file, e.g.:
app/design/frontend/ThemeVendor/theme_name/web/css/custom.cssapp/design/frontend/ThemeVendor/theme_name/Magefan_Blog/web/js/lazyload.jsapp/code/Magefan_Blog/view/frontend/web/js/lazyload.jsvendor/magefan/module-blog/view/frontend/web/js/lazyload.js
use the following code:
<?= $this->getViewFileUrl('css/custom.css') ?><?= $this->getViewFileUrl('Magefan_Blog::js/lazyload.js') ?>
4. Get URL of the static file in pub/media:
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();$mediaUrl = $objectManager->get(Magento\Store\Model\StoreManagerInterface::class) ->getStore() ->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA);
<?= $mediaUrl ?>wysiwyg/image.png
Attention! You should not use media files in the themeihor
- 2 min read
Hello there, Magento fans!
Hey hey! It's been a while since we last shared the Magefan updates. Are you ready for the January compilation of news?
Then, let's start!
We would like to begin with the new module that has been released recently. With the extension you can forget about a broken website and increased bounce rates during the deployment time.
There is no need for you to lose profits or choose the most inconvenient time to run deployment commands when you can do this harmlessly with this module.
— extension that helps you increase your website loading speed and boost performance — is even more beneficial now. We have improved HTML tags style attribute background parsing and module compatibility with MGS themes. Moreover, we have fixed the following error:
TypeError: strtolower() expects parameter 1 to be string, null given in app/code/Magefan/WebP/Plugin/Magento/Framework/View/Element/AbstractBlock.php:69 .
We encourage those of you who haven’t yet updated to v2.1.1ihor
- 3 min read
One of the most unique Magento 2 offers you to create is a virtual product. But what is virtual product in Magento, and why is it so special?
It stands out because you can neither feel it tangibly, set the weight, or download a virtual product in Magento 2. Some of the common examples of this product type are memberships, services, subscriptions, and warranties.
They can be sold individually or as a part of or . The configuration section contains the familiar fields you can fill out easily. Today, you'll learn how to do it in more detail.
What is a Virtual Product in Magento 2?
Magento 2 virtual product is nontangible and doesn't have a physical representation. Thus, it can be neither shipped nor delivered. The only indication that a customer bought such a product is the confirmation email.
Some of the most popular examples of virtual products are subscriptions, warranties, memberships, etc. You can sell virtual products individually or as a part of other product types.
How to Create Virtualihor
- 3 min read
The popularity of downloadable products has increased drastically, both globally and in Magento in particular. It is not a surprising fact, though. Such products as eBooks, music, videos, , updates, or instruction manuals are being actively sold. They don’t require additional manufacturing or shipping, which is an advantage.
Together with other , the platform allows you to create downloadable products with free samples. The process doesn’t differ much from that of a simple product. However, you have to configure the before creating a downloadable product.
But let’s sort everything out. Keep reading to learn how to create a downloadable product in Magento 2.
What is a Magento Downloadable Product?
Magento downloadable product is a digital type of Magento product customers can download from your store. As mentioned above, E-books, manuals, and applications are the best examples of this product type.
When creating downloadable products, you have an extensive set of options to set and makeihor
- 1 min read
In case you use some Geo IP modules (like our Magento 2 and Extensions) and have the Varnish installed, then you need to make some additional configurations for it.
The simplest configuration is to add the following lines to the varnish config file:
if (req.http.cookie !~ "PHPSESSID=" && req.http.User-Agent !~ "bot" && req.http.User-Agent !~ "loader") { return (pass); }
In this case, the first customer visit will not be cached by varnish, the php Magento will generate the right cookies, switch to the right store view and change the currency.
However, the drawback of this approach is that the store view will be displayed without varnish cache during the first visit. If you want to avoid this you can configure the varnish cache to have different caches for different countries
To achieve that you have to configure the Geo IP with Varnish. Follow this link for step-by-step instructions.
- 4 min read
One of the many perks of Magento 2 is the variety of products it allows you to create. Yet, Magento 2 bundle products definitely stand out. It's a unique since it allows customers to customize product attributes available in a bundle.
Many of you would find a huge similarity between bundle and and there is some. However, these two types of products still have some differences you should know about.
If all these concepts confuse you a bit, you've landed on the right page. Today you'll not only learn more details about Magento bundle products but find out how to create them in Magento 2.
Difference Between Magento 2 Bundle Product and Grouped Products
When buying grouped products a customer can remove or add some items to the set (group), but not choose any product option. Magento 2 bundle products work the other way around. Besides, they consist of simple and .
e.g. If you have a grouped product that consists of a sports bag, uniform, and sneakers, customers can easily remove one ofihor
- 2 min read
No one likes to see their website broken during the since it scares off the potential customers and causes them to bounce. Not exactly the prospective successful Magento 2 store owners look for.
Fortunately, there is the extension that fixes this and reduces the downtime to zero. It allows you to run the deployment commands with no website breakage. Speaking of which, here is the list of the deployment commands you have to run to reduce the downtime to ZERO.In order to redeploy Magento completely, you have to run
bin/magento magefan:zero-downtime:deploy
If you only want to deploy dependency injection (bin/magento setup:di:compile), then use
bin/magento magefan:zero-downtime:deploy -d
To run the Magento static content (bin/magento setup:static-content:deploy) use
bin/magento magefan:zero-downtime:deploy -s
In case you want to run multiple parameters script, use the following command
bin/magento magefan:zero-downtime:deploy -d -s
If you want to pull data and switch to a specificihor
- 2 min read
is the extension that solves your problems with the 503 maintenance pages during deployment time. It prevents your website from breaking and you from losing potential customers even when running the commands. Moreover, the configuration is really simple. So let's get to it.
Zero Downtime Deployment configuration has 4 different sections: General, Instance Files and Folders, Composer and Git within which you can find different options.
Following steps to configure Magento 2 Zero Downtime Deployment extension:
General
1. Navigate to Stores > Configuration > Magefan Extensions > Zero Downtime Deployment.
2. Enable the extension.
3. Select the Static Content Deploy option. You can Deploy Only Enabled Themes or Deploy All Themes.
4. Define how many jobs you want to be processed parallelly during deployment in the Count of Jobs For Parallel Processing Of Static Content Deploy field.
5. Choose whether to Enable all Caches After Deploy since sometimes some of them can be disabled after deploymentihor
- 1 min read
If you decided to remove , please follow the steps below. You can contact our team for a free consultation in case you have any issues with Magefan's extension.
Remove Extension Files
Removing files instruction depends on the way the Zero Downtime Deployment extension has been installed in.
1. If you can find the extension files in the folder
app/code/Magefan/ZeroDowntimeDeploy
then remove this folder.
2. If the extension was installed via the composer and its files located in the folder
vendor/magefan/module-zero-downtime-deploy
then run composer CLI command to remove it
composer remove magefan/module-zero-downtime-deploy
Once extension files have been removed, run these Magento CLI commands:
php bin/magento setup:upgradephp bin/magento setup:di:compilephp bin/magento setup:static-content:deploy
Note: if you don't want your website to be down during deployment, try these .
Remove Extension Data (optional)
Attention! This will clean all Zero Downtime Deployment configurations.
1. Justihor
- 1 min read
If you need to update by Magefan, please follow the steps below.
Note: the updating instructions depend on the method the Zero Downtime Deployment extension was installed with.
Update using composer
If the zero downtime deployment module was installed via the composer (check if vendor/magefan/module-zero-downtime-deploy folder exists), then you need to run these simple CLI commands in Magento 2 directory:
composer remove magefan/module-zero-downtime-deploycomposer require magefan/module-zero-downtime-deploy ^x.x.x# replace x.x.x with the version you want to usephp bin/magento setup:upgradephp bin/magento setup:di:compilephp bin/magento setup:static-content:deploy
Note: if you don't want your website to be down during deployment, try these .
Update using archive and FTP
If the zero downtime deployment module was installed via FTP (check if app/code/Magefan/ZeroDowntimeDeploy folder exists), then follow these commands:
1. Download the latest version of the zero downtime deploymentihor
- 1 min read
You can install by Magefan, using composer or archive installation methods.
Installation via composer (recommended)
Please navigate to your Magefan Account > Downloads > Install via Composer to get the composer installation instructions.
Installation using archive and FTP
Download Zero Downtime Deployment ZIP-Archive from magefan.com website (not GitHub or other sources).
Extract files.
Copy app folder from the archive to your Magento 2 folder.
In a command line, using "cd", navigate to your Magento 2 root directory.
Run CLI commands:
php bin/magento setup:upgradephp bin/magento setup:di:compilephp bin/magento setup:static-content:deploy
Note: if you don't want your website to be down during deployment, try these .
Once you have installed the Magento 2 Zero Downtime Deployment module you can proceed to the .
- 2 min read
Magento 2 grouped product is one of many the platform offers. As you might know, it features a set of different related simple products to increase the chances of customers buying more items.
In this case, every can be purchased either separately or as a group. However, every item is listed as a separate product in a shopping cart.
Since Magento grouped products are relatively easy to create you'll learn all the necessary steps in this guide.
To create Magento grouped products:
1. Navigate to Catalog > Products and choose Grouped Product from the Add Products dropdown.
2. Enable the grouped product and choose the Attribute Set for it.
3. Enter the Product Name, specify the SKU, and set its Stock Status.
Note: you can't set the Price and Quantity since they are set separately for each product of the group.
4. Choose a Category Magento grouped product.
5. Set the Visibility of the grouped product.
6. Enter the date range in the Set Product as New From/To field to determine how long theihor
- 7 min read
A configurable product is one of the many the platform offers. It's called Magento configurable product since it allows customers to "configure", choose different options, such as size, colour, or material, to buy a product.
It gives people more flexibility when shopping. No wonder it's the most popular product type in Magento, you definitely need to know how to use.
So in this guide, you'll learn more about configurable products, how they work and how to set them up in your store.
Simple vs Configurable Products: What's the Difference?
People often confuse Magento simple products with configurable ones. That's why, before we get to creating configurable products, we should make this one clear.
Although they look similar at first, simple and configurable products play different roles. Besides, they influence both customer experience and backend management in different ways.
A simple product in Magento 2 is the basic product type. It represents a single item which has its own SKU (Stockihor
- 4 min read
Magento 2 simple products are the most basic and essential Magento products. The simple product has no variations. It is sold individually since it has a single SKU. However, it can also be purchased as a part of a , or .
Following steps to create a simple product in Magento 2:
1. Navigate to Catalog > Products and choose Simple Product from the Add Product dropdown.
2. Enable or disable a simple product.
3. Choose the Attribute Set you want this product to have. Magento provides the default attribute set. However, you are able to choose from various other options. Besides you can add a or a .
4. Set the Product Name and SKU.
5. Set the product Price.
There are cases like sales, promotions or any other kind of offers when you need to set an Advanced Pricing for a product.
e.g. you might use it to or for configuring catalog price rules
Set Special Price, a price customer will see during sales or under other conditions.
Choose the Special Price From and To Date.
Set the Cost, the priceihor
