Martin – Magento Blog https://blog.extendware.com by ExtendWare Fri, 13 Dec 2024 08:39:49 +0000 en-US hourly 1 https://wordpress.org/?v=6.6.2 https://blog.extendware.com/wp-content/uploads/2022/02/cropped-android-chrome-384x384-1-32x32.png Martin – Magento Blog https://blog.extendware.com 32 32 Magento High Speed Import Scheduler For Magento 2 https://blog.extendware.com/magento-high-speed-import-scheduler-for-magento-2/ Fri, 13 Dec 2024 08:39:48 +0000 https://blog.extendware.com/?p=2312 Read more]]> Managing product data efficiently is crucial for running a successful Magento 2 store, especially if you have a large inventory or need to update products regularly. That’s where the Magento High Speed Import Scheduler for Magento 2 comes in! It combines all the powerful features of MHSI Pro to make product imports faster, simpler, and more efficient. This tool is perfect for store owners looking to save time and streamline their data import process.

Why Choose Magento High Speed Import Scheduler ?

Magento’s built-in import feature can be slow, especially when dealing with complex data like configurable products or category assignments. With Magento High Speed Import Scheduler For Magento 2, you can manage imports directly from your Magento admin panel, speeding up the process and making it easier to handle large data volumes.

Key Features

  • Easy-to-Use Interface: Manage all your import tasks from a simple, user-friendly interface in the Magento admin panel. You can quickly create, edit, and run import profiles without needing complex setups.
  • Visual Field Mapping: Upload your CSV or XML files and visually map fields to Magento system fields. This makes sure your data is imported correctly without any guesswork or errors.
  • Automated Scheduled Imports: Set up automatic imports using CronJob, so you don’t have to manually update your inventory. You can schedule imports to run at specific times, keeping your product data up to date effortlessly.
  • Import All Product Types: Easily import both simple and configurable products, along with related items like upsells and cross-sells. You can also import customer group-specific pricing, giving you full control over your catalog.
  • Advanced Image Handling: Import images directly from URLs, including those that require login credentials. The tool supports WebP images, assigns images based on product SKUs, and can reuse existing images, saving you time and storage space.
  • Category Management: Assign products to categories by their IDs or names. It even supports nested categories (subcategories) and can automatically create new categories if they don’t exist in your store.
  • Detailed Error Reporting: If something goes wrong during the import process, you’ll receive clear error messages to help you fix the issues quickly. This saves time and helps keep your imports running smoothly.
  • Support for Multiple File Formats: The tool handles both CSV and XML files, allowing you to import data from different sources without extra conversions.
  • Customizable Import Profiles: Create different profiles for various data formats, making it easy to import data from multiple suppliers or sources.
  • Real-Time Import Logs: Keep track of all your import activities in one place. The tool provides real-time logs, so you can see what’s happening during each import and quickly identify any issues.

Enhanced Control and Automation

  • Admin Role Management: Control who can access and manage import tasks, ensuring secure and organized handling.
  • Email Alerts: Receive notifications if an import job gets stuck, so you can quickly take action.
  • Auto-Clean Import History: Automatically delete old import logs to keep your system running smoothly.
  • Set Maximum Run Time: Limit how long each import can take, preventing server slowdowns.

The Ultimate Solution for Fast Magento Imports

The Magento High Speed Import Scheduler with MHSI Pro is designed for Magento 2 store owners who want to streamline their data imports. It combines ease of use with powerful features, allowing you to update your product catalog quickly and efficiently. Whether you manage a large store with frequent updates or need to handle complex product data, this tool will save you time and help keep your store up to date.

Ready to Upgrade Your Magento Import Process?

Don’t let slow and complicated imports hold you back. Enhance your Magento 2 store with Magento High Speed Import Scheduler and unlock the full potential of MHSI Pro features.

]]>
Understanding Preferences in Magento 2 https://blog.extendware.com/understanding-preferences-in-magento-2/ Fri, 29 Nov 2024 14:52:59 +0000 https://blog.extendware.com/?p=2373 Read more]]> Magento 2 offers developers several ways to customize and extend its functionality. One of the most powerful tools for this is Preferences, which allow you to override or rewrite existing classes and methods. This blog will explain what Preferences are, how they work, and when to use them effectively. Let’s dive in!

What Are Preferences in Magento 2?

Preferences in Magento 2 let the Object Manager replace one class with another. This means you can customize the behavior of core classes or even classes from other modules without editing their files. When a class is called, Magento checks the di.xml configuration for a Preference. If it finds one, it replaces the original class with your custom implementation.

Where Can Preferences Be Used?

Preferences can be used to override the following

  • Models
  • Blocks
  • Helpers
  • Controllers
  • Custom Module Classes

Whether you’re working on a public method or a protected one, Preferences make it easy to implement your changes globally.

How to Create a Preference in Magento 2

Here’s a step-by-step guide

Setp-1: Create the di.xml File

Define your Preference in the di.xml file inside your module.

Example Path:
app/code/MyCompany/ModuleName/etc/di.xml

Example Code:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
   <preference for="Magento\Catalog\Model\Product" type="MyCompany\ModuleName\Model\Product" />
</config>

The for attribute specifies the original class.

The type attribute points to your custom class.

Setp-2: Create the Custom Class

Extend the original class and override the desired method.

Example Path:

app/code/MyCompany/ModuleName/Model/Product.php

Example Code:

<?php
namespace MyCompany\ModuleName\Model;
class Product extends \Magento\Catalog\Model\Product
{
   public function getName()
   {
        return "Customized Product Name";
   }
}

Setp-3: Compile Dependency Injection

Run the following CLI command:

bin/magento setup:di:compile

Setp-4: Test the Results

For instance, if you override the getName() method, the product names on your site will now reflect the new logic.

Benefits of Using Preferences

  • Customizable Logic: You can rewrite any method globally without touching core files.
  • Maintainability: By isolating your customizations in a separate module, you avoid problems during Magento upgrades.
  • Flexibility: Preferences work on public and protected methods, making them highly versatile.

Challenges and Limitations

  • Conflict Risks: If two modules define Preferences for the same class, only one will take effect, which may cause conflicts.
  • Complete Override: Preferences replace the entire class. This means all original logic is bypassed, which can sometimes lead to bugs.
  • Heavy-Handed: For simple tweaks, Preferences might be overkill. Use Plugins when possible for a less intrusive approach.

Best Practices for Using Preferences

  • Use When Necessary: Preferences should only be used if Plugins cannot achieve the desired result.
  • Document Your Changes: Clearly explain why a Preference is used and what it does to help with future maintenance.
  • Test Extensively: Ensure your changes don’t unintentionally break other parts of the application.

Example: Overriding a Core Method

Here’s a practical example. Let’s rewrite the getName() method from Magento\Catalog\Model\Product.

di.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <preference for="Magento\Catalog\Model\Product" type="MyCompany\ModuleName\Model\Product" />
</config>

Custom Class : Product.php

<?php
namespace MyCompany\ModuleName\Model;
class Product extends \Magento\Catalog\Model\Product
{
    public function getName()
    {
        return "Preference Demo";
    }
}

Result: All product names will display as “Preference Demo” on the frontend.

Conclusion

Preferences in Magento 2 are a powerful way to customize core functionality, offering flexibility for global changes. However, they come with risks, such as conflicts and bypassing original logic. Always weigh the pros and cons before using Preferences, and consider alternatives like Plugins when appropriate.

]]>
How to Add ACL (Access Control Lists ) in Magento 2: A Step-by-Step Guide https://blog.extendware.com/how-to-add-acl-access-control-lists-in-magento-2-a-step-by-step-guide/ Fri, 22 Nov 2024 10:46:20 +0000 https://blog.extendware.com/?p=2335 Read more]]> In Magento 2, the Access Control List (ACL) system helps store owners manage user permissions for various actions in the admin panel. This ensures that only authorized users can access certain sections or perform specific tasks. However, you might have situations where you want to add actions to the ACL that are not part of the menu system. In this blog post, we will walk through the process of adding such actions to the ACL in Magento 2 and how to check user permissions programmatically.

What is ACL in Magento 2?

ACL is a security feature in Magento 2 that controls what each user role can access or modify in the admin area. It defines which pages, actions, and resources a user is allowed to interact with, providing a way to manage permissions and secure your store’s backend. Magento uses ACL rules to govern permissions in both the admin panel and web API calls.

Step 1: Create the menu.xml File

The first step is to create a menu for your custom functionality. Even if you don’t have a menu item but still want to restrict access to certain actions, creating a menu.xml file will help you manage your module’s admin interface.

Here’s an example of a simple menu.xml file that adds a menu item to your module:

<?xml version="1.0" encoding="UTF-8"?>
<menu xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/menu.xsd">
    <add id="Vendor_CustomModule::main_menu"
         title="Custom Module"
         module="Vendor_CustomModule"
         sortOrder="100"
         parent="Magento_Backend::content"
         action="Vendor_CustomModule::index"/>
</menu>

This XML file creates a new menu item in the admin panel. When an admin creates a new role, they can assign permissions to this menu item.

Step 2: Define ACL Rules in acl.xml

Once the menu is set up, the next step is to define ACL rules. This is done in the acl.xml file, which is used to declare resources required for accessing actions in the admin panel.

Here’s an example acl.xml for defining ACL rules in your module:

<?xml version="1.0" encoding="UTF-8"?>
<acl xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Acl/etc/acl.xsd">
    <resources>
        <resource id="Magento_Backend::admin">
            <resource id="Vendor_CustomModule::config" title="Manage Custom Module Configuration" />
        </resource>
    </resources>
</acl>

In this example, the Vendor_CustomModule::config resource is defined, which controls access to the configuration page of your module. Admin users can be assigned permission to this resource when creating roles.

Step 3: Programmatically Check ACL Permissions

Now that your ACL rules are defined, you can check if the logged-in user has permission to access specific actions. Magento provides a service called Magento\Framework\AuthorizationInterface to check if a user has permission for a given resource.

Here’s how to use it in your code:

public function __construct(
    \Magento\Framework\AuthorizationInterface $authorization
) {
    $this->authorization = $authorization;
}

public function checkPermission()
{
    if ($this->authorization->isAllowed('Vendor_CustomModule::config')) {
        // User is allowed to access the configuration page
    } else {
        // User does not have permission
    }
}

In this example, the code checks if the user has permission for the Vendor_CustomModule::config resource, which is defined in the acl.xml file.

Step 4: Secure Non-Menu Actions

Sometimes, you may want to secure actions that are not part of the menu, like custom actions or API endpoints. You can still protect these actions using ACL by declaring them in acl.xml and checking permissions before allowing access.

Here’s how to check permissions for a custom API action:

public function someApiAction()
{
    if ($this->_authorization->isAllowed('Vendor_CustomModule::api_action')) {
        // Proceed with the action
    } else {
        // Deny access
    }
}

Conclusion

Adding actions to the ACL in Magento 2 is an effective way to ensure that only authorized users can access certain parts of your admin panel, even if those actions are not part of the standard menu. By following the steps outlined in this guide, you can secure your custom functionalities and protect sensitive actions from unauthorized access.

Magento’s ACL system provides a flexible and powerful way to manage user permissions. Whether you’re adding menu-based actions or securing non-menu actions, Magento’s ACL system ensures that your admin panel remains secure and controlled.

]]>
Magento 2 Create Custom Module https://blog.extendware.com/magento-2-create-custom-module/ Mon, 18 Nov 2024 12:50:13 +0000 https://blog.extendware.com/?p=2050 Read more]]> Magento 2 comes with many default features and functionalities such as customer management, product management, category management, CMS pages, widgets, static blocks, reports, and more. Nowadays, customers and administrators often desire new functionalities and improvements to existing ones. Magento has a well-established structure for customizing existing functionalities and adding new ones through custom modules.

Today, we will learn how to create a custom module in Magento 2. Before we begin creating a custom module, let’s go over some important points regarding custom modules. Magento 2 modules are located in the ‘app/code’ or ‘vendor/’ folder. Modules can be installed using Composer, which places the module in the ‘vendor’ directory, or you can put the module’s ZIP file in the ‘app/code’ folder. We need to check the namespace of the module because it must be unique for each module, and it’s imported in each file within the module. Therefore, we advise using meaningful and concise names.

Let’s create a custom module for a better understanding. The ‘VendorName_Modulename‘ structure is used, where the ‘VendorName’ represents the main company name and ‘ModuleName’ signifies the specific function of the module in Magento 2. For instance, we’ll create a custom module named ‘Extendware_DemoModule‘.

Step-1: Begin by creating a folder inside the ‘app/code’ directory that corresponds to the structure of our module’s name.

app -> code -> Extendware -> DemoModule

Step-2: Create a ‘registration.php‘ file at ‘app/code/Extendware/DemoModule’ and add the following code.

<?php
/**
 * @category Extendware
 * @copyright Copyright (c) 2022-present Extendware (https://www.extendware.com/)
 * @package Extendware_DemoModule
 */
\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'Extendware_DemoModule',
    __DIR__
);

Here, it’s crucial to ensure that you add the proper module name, which should match the folder name you’ve created within ‘app/code.

Step-3: Create a ‘module.xml‘ file at ‘app/code/Extendware/DemoModule/etc’ and add the following code.

<?xml version="1.0"?>
<!--
   @category Extendware
   @copyright Copyright (c) 2022-present Extendware (https://www.extendware.com/)
   @package Extendware_DemoModule
  -->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Extendware_DemoModule">
        <sequence>
            <module name="Magento_Backend"/>
        </sequence>
    </module>
</config>

The two files mentioned above are essential for registering your module within the Magento architecture, enabling you to interact with the system.

Step-4: create a ‘composer.json‘ file at ‘app/code/Extendware/DemoModule’ and add the following code.

{
   "name":"extendware/demomodule",
   "description":"Magento 2 - creates a new page",
   "type":"magento2-module",
   "version":"0.0.1",
   "license":&#91;
      "OSL-3.0",
      "AFL-3.0"
   ],
   "autoload":{
      "files":&#91;
         "registration.php"
      ],
      "psr-4":{
         "extendware\\DemoModule\\":""
      }
   }
}

Here, you must include the ‘type’ value as ‘magento2-module’. The file is particularly important when your module supports Composer installation. Nowadays, many modules are compatible with Composer installation, and Composer reads this information to install them into the Magento system.

After adding the above files, you need to run a Magento command to install the module into your Magento system. The command is as follows:

php -d memory_limit=-1 bin/magento setup:upgrade

Once the above command runs successfully, you can find the module name listed below, and it will also appear in the main configuration file located at ‘app/etc/config.php.

'Extendware_DemoModule' => 1,

Please note that when you install any module in Magento for the first time, it is enabled by default.

Have a question or need more information? Contact us, and we’ll be happy to help.
Follow us for daily inspiration and updates.

]]>