We sacrifice by not doing any other technology, so that you get the best of Magento.

We sacrifice by not doing any other technology, so that you get the best of Magento.

    Magento 2 : How to set custom product price while displaying at front end?

    If you want to change the main price with a custom price attribute. You can use the below method

    1. Create file di.xml on app/code/Magemonkeys/CustomPrice/etc/frontend

    <?xml version="1.0"?>
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
        <type name="MagentoCatalogModelProduct">
            <plugin name="change_product" type="MagemonkeysCustomPricePluginModelProduct" sortOrder="1" />
        </type>
    </config>

    2. Create file Product.php on app/code/Magemonkeys/CustomPrice/Plugin/Model

    <?php
    namespace MagemonkeysCustomPricePluginModel;
     
    class Product
    {
        public function afterGetPrice(MagentoCatalogModelProduct $subject, $result)
        {        
            $result = $subject->getCustomPrice(); // you can set custom attribute price
            return $result;
        }
    }

     

    Magento 2: Create custom GraphQL data

    We can create custom api for GraphQL.

    As per the app/code/ standard, our module name is Magemonkeys/Customgraphql

    We can create schema.graphqls file in module etc folder.

    Below is the code for that file.

    type Query
    {
        CustomGraphql (
            username: String @doc(description: "Email of the customer")
            password: String @doc(description: "Password")
            fieldtype: String @doc(description: "Field Type")
        ): CustomGraphqlOutput @resolver(class: "Magemonkeys\Customgraphql\Model\Resolver\ResolverGraphql") @doc(description:"Customgraphql Datapassing")
    }
    type CustomGraphqlOutput
    {
        username: String
        password: String
        fieldtype: String
    }

    After that we need to create Model Resolver file.

    Create file ResolverGraphql.php in this location of module
    Magemonkeys/Customgraphql/Model/Resolver/

    Below is the code for that file.

    <?php
    namespace MagemonkeysCustomgraphqlModelResolver;
    
    use MagentoFrameworkGraphQlConfigElementField;
    use MagentoFrameworkGraphQlExceptionGraphQlInputException;
    use MagentoFrameworkGraphQlQueryResolverInterface;
    use MagentoFrameworkGraphQlSchemaTypeResolveInfo;
    use MagentoFrameworkExceptionNoSuchEntityException;
    use MagentoFrameworkGraphQlExceptionGraphQlNoSuchEntityException;
    
    class ResolverGraphql implements ResolverInterface
    {
        public function resolve(
            Field $field,
            $context,
            ResolveInfo $info,
            array $value = null,
            array $args = null)
        {
            if (!isset($args['username']) || !isset($args['password']) || !isset($args['fieldtype'])||
                empty($args['username']) || empty($args['password']) || empty($args['fieldtype']))
            {
                throw new GraphQlInputException(__('Invalid arguments list please check.'));
            }
            $output = [];
            $output['username'] = $args['username'];
            $output['password'] = $args['password'];
            $output['fieldtype'] = $args['fieldtype'];
          
            return $output ;
        }
    }

    After that you can check API in Postman API tool.

    That’s it.

     

    Magento 2: Change customer group before saving the customer using plugin

    Create di.xml file your module and add the below code
    <?xml version="1.0"?>
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
        <type name="MagentoCustomerApiCustomerRepositoryInterface">
            <plugin name="save_customer_group" type="VendorModulePluginMagentoCustomerApiCustomerRepositoryPlugin" />
        </type>
    </config>
    Create plugin file under this directory Vendor/Module/Plugin/Magento/Customer/Api/CustomerRepositoryPlugin.php
    <?php
    namespace VendorModulePluginMagentoCustomerApi;
    
    use MagentoCustomerApiDataCustomerInterface;
    use MagentoCustomerApiCustomerRepositoryInterface;
    use MagentoFrameworkControllerResultFactory;
    use MagentoFrameworkUrlInterface;
    use MagentoFrameworkExceptionLocalizedException;
    
    class CustomerRepositoryPlugin
    {
        /**
         * @var Data
         */
        private $helper;
    
        /**
         * Constructor of class.
         *
         * @param Data $helper
         */
        public function __construct(
            MagentoFrameworkAppRequestInterface $request,
            MagentoCustomerModelResourceModelGroupCollectionFactory $groupCollection,
            MagentoFrameworkAppConfigScopeConfigInterface $scopeConfig,
            MagentoCustomerApiGroupRepositoryInterface $groupRepository,
            MagentoFrameworkMessageManagerInterface $messageManager,
            ResultFactory $resultFactory,
            UrlInterface $url
        ) {
            $this->request = $request;
            $this->groupCollection = $groupCollection;
            $this->scopeConfig = $scopeConfig;
            $this->groupRepository = $groupRepository;
            $this->messageManager = $messageManager;
            $this->resultFactory = $resultFactory;
            $this->url = $url;
        }
    
        /**
         *
         * @param CustomerRepositoryInterface $subject
         * @param CustomerInterface $customer
         * @return array
         */
        public function beforeSave(CustomerRepositoryInterface $subject, CustomerInterface $customer, $passwordHash = null)
        {
            $groupid = 5; //change customer group id here
            $customer->setGroupId($groupId);
            return [$customer, $passwordHash];
        }
    }
    

     

    Magento 2: Get customer data in GraphQL

    By using GraphQL, You can get data of logged in customers.

    Magento 2 can directly call api to get data by resolver.

    Module name : Magemonkeys::Custom

    create file schema.graphqls in etc folder in that module

    type Query
    {
        getCustomerData: Response 
        @resolver(class:"Magemonkeys\Custom\Model\Resolver\Getdataforcustomer")
    }
    
    type Response
    {
        customer_id: String
        customer_name: String
    }

    Create Getdataforcustomer.php in Model/Resolver Folder in that module

    namespace MagemonkeysCustomModelResolver;
    
    use MagentoFrameworkGraphQlQueryResolverInterface;
    use MagentoFrameworkGraphQlConfigElementField;
    use MagentoFrameworkGraphQlSchemaTypeResolveInfo;
    use MagentoFrameworkGraphQlExceptionGraphQlNoSuchEntityException;
    use MagentoFrameworkGraphQlExceptionGraphQlAuthorizationException;
    use MagentoCustomerGraphQlModelCustomerGetCustomer;
    
    class Getdataforcustomer implements ResolverInterface
    {
       private $getdataforCustomer;
         
       public function __construct(GetCustomer $getdataforCustomer)
       {
          $this->getCustomer = $getdataforCustomer;
       }
       public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
       {
          try
          {
             if (false === $context->getExtensionAttributes()->getIsCustomer())
             {
                throw new GraphQlAuthorizationException(__('The current customer not getting'));
             }
             $customerdata = $this->getCustomer->execute($context);
             $customername = $customerdata->getFirstName()." ".$customerdata->getLastName();
             $result = ['customer_id' => $customer->getId(),
                        'customer_name' => $customername
                       ];   
             return $result;
          }
          catch(Exception $exception)
          {
              throw new GraphQlNoSuchEntityException(__($exception->getMessage()));
          }
       }
    }

    After that run command to call api url

    That’s it.

     

    Magento 2 : How to USPS Shipping method title change programmatically?

    If you need some specific shipping title change, then use the below method

    For Ex. Priority Mail 1-Day instead of Priority Mail (2-3 Days)

    Firstly, you need to add the following file.

    1. Create file di.xml on app/code/Magemonkeys/UspsShipping/etc

    <?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="MagentoQuoteModelQuoteAddressRateResultMethod" type="MagemonkeysUspsShippingPluginModelQuoteAddressRateResultMethod" />
    </config>

    2. Create file Method.php on app/code/Magemonkeys/UspsShipping/Plugin/Model/Quote/Address/RateResult

    <?php
    namespace MagemonkeysUspsShippingPluginModelQuoteAddressRateResult;
    
    class Method extends MagentoQuoteModelQuoteAddressRateResultMethod
    {
        public function setPrice($price)
        {
            if (strpos($this->getMethodTitle(), "Priority Mail 1-Day") !== false) {
                $this->setMethodTitle("Priority Mail (2-3 Days)");
            }
            $this->setData('price', $this->priceCurrency->round($price));
            return $this;
        }
    
    } ?>

    Difference between filterable (with result) and Filterable (with no result) in Magento 2 Attributes

    Layered navigation Filterable (with results):

    – This attribute will be shown only if there are products matching any of its attributes-options value.
    – filter is shown on the category page Layered Navigation. However only options values, where products are available will be listed for the filter.
    – In this case, products list filtration works if selected filters change from currently shown options.

    Layered navigation Filterable (no results):

    – In this case, All attribute options will be shown even if there won’t be any products matching or associated with them.
    – filter is shown on the category page Layered Navigation. if the filter is set to ‘no results’, it will list all options, even no products are associated with specific options.
    – If any attribute options not Associated with any products then its show Zero counts. Ex: Color Attribute with options Red (0).

    For more understanding, you can check these options from admin and check the difference in the front end to get a better idea.

    Thanks!

    Pagination is not working after upgrading to Magento Version 2.4.3

    If you face pagination not working issue after upgrading Magento 2.4.3 then follow below few steps.

    Step 1 : Open your theme’s list.phtml file like app/design/frontend/Magemonkeys/CustomTheme/Magento_Catalog/templates/product/list.phtml

    Step 2 : Find below code in the bottom section of the list.phtml file

    <?= $block->getToolbarHtml() ?>

    Step 3 : Replace above code with below code in the bottom section of the list.phtml file

    <?= $block->getChildBlock('toolbar')->setIsBottom(true)->toHtml() ?>

    Step 4 : After place above code, please run below mentioned commands

    php bin/magento setup:upgrade
    php bin/magento setup:static-content:deploy
    php bin/magento cache:clean

    That’s it.

    Now when you will refresh the category page, you will find pagination on working condition.

    Benefits Of Choosing A Magento Development Agency Over A Freelancer

    There are numerous stores managed by individual freelancers. But, the trend has already started where this numbers are migrating from freelancer to professional agencies, as freelancer’s bandwidth & knowledge isn’t sufficient to handle Magento stores.

    There are some good reasons to choose a Magento development agency over freelancers and they are:

    Diverse expertise & professionalism
    When you hire a Magento development company as compared to a freelancer, you will be able to find a professional who is an expert in his/her area. Such a professional will work according to project deadlines and will ensure customer requirements are met.

    Ease of project management
    Unlike in the case of freelancers, a good Magento development company will provide you with a reliable project manager to collaborate between the teams and manage all tasks. Such a project manager will keep all the stakeholders updated with the progress of the project.

    Good for start-ups and enterprises equally
    A Freelancer won’t have enough time, knowledge, energy, and bandwidth to handle enterprise level stores. On the other hand, a good Magento development company is capable to serve the needs of a business of any size. They will help you with everything right from consultation to analysis and evaluation of the business idea to development and final deployment.

    Adoption of latest technologies and trends
    For a business to stay competitive, it is important to implement the latest technologies and a good Magento development company can help you with the task. They keep up with the latest trends and go for the newer development methodologies to improve solutions and have a lesser turnaround time.

    If you are planning to invest in a serious Magento solution then it would be better to go for a Magento development company than choose freelancers. If you’re still using Freelancer to operate your store, we suggest you to hire an agency instead to fulfill your tech requirements. Fill the below form to hire Magento certified agency

    Why Should You Hire A Creative Designer For Your Magento Store?

    It is no longer a secret that adopting latest UI/UX touch in your site can improve the sales. Designing is not only about giving an attracting look to your site, but it’s also about placing web elements such as product images and buttons at their best places in a way that user engages with them.

    That’s why having an experience and creative designer will bring below pros for your store:

    • Better usability and accessibility

    Creative designers will look for ways to turn your Magento store more accessible to the users thus boosting conversions. This will help with improved user-friendliness, consistency, and visibility of your store. Again, they will include the fonts, colors, images, videos, etc. that resonate well with the store vision for better usability.

    • Higher ROI

    A creative designer will focus on coming up with a Magento store design that is intuitive in nature. Many studies suggest that your Magento store will be able to target higher ROI by ensuring intuitive UX.

    • Higher customer retention rate

    A creative Magento designer will focus on the main need of the business is to bring in more customers as well as boost customer retention rate to boost sales. A good designer will access your Magento store and come up with proper user acquisition and retention strategy that will focus on the looks and functionalities of the store.

    • Capability to load site faster

    An experienced web designer has capability to reuse CSS & other codes. He/She can also optimize web medias such a way that the eCommerce will load smoother and faster. This will directly impact on sales, positively.

    Conclusion

    Neglecting Magento designer’s consultation will not help you achieve your sales goals. So, hire an experienced eCommerce designer who can help you run UI/UX audit and give you design level guidance.