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.

    Steps to disable payment method by specific customer group in Magento 2

    Successful e-commerce store demands to provide better user experience to grow their sales by offering and managing various payment methods at checkout page according to the needs of the specific customer as every customer has different demands. For example, the merchant which offers the cash on delivery for the local region may not be offered to international customers; In some cases, payment gateway requires certain taxes and fees for the different part which cannot be borne by the merchant.TO solve those issues, it has become vital for Magento store owners to optimize their payment methods according to different customer groups

    To enable the payment process between customers and Magento store, we can restrict the payment methods by different customers groups by following the steps below.

    1. Create an events.xml in : /app/code/Magemonkeys/PaymentMethod/etc

    <?xml version="1.0"?>
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
     <event name="payment_method_is_active">
     <observer name="Magemonkeys_PaymentMethod_DisabledPgByCustomergroup" instance="MagemonkeysPaymentMethodObserverDisabledPgByCustomergroup" />
     </event>
    </config>

    2. Create an DisabledPgByCustomergroup.php in : /app/code/Magemonkeys/PaymentMethod/Observer

    <?php
    namespace MagemonkeysPaymentMethodObserver;
    use MagentoFrameworkEventObserverInterface;
    use MagentoFrameworkAppRequestDataPersistorInterface;
    use MagentoFrameworkAppObjectManager;
    
    class DisabledPgByCustomergroup implements ObserverInterface
    {
     
     public function execute(MagentoFrameworkEventObserver $observer)
     { 
        $helper = MagentoFrameworkAppObjectManager::getInstance()->get('MagemonkeysPaymentMethodHelperData'); 
        if($helper->isEnable()){
          $customer_grp = $helper->isActiveGroup(); 
          $result = $observer->getEvent()->getResult();
          $method_instance = $observer->getEvent()->getMethodInstance();
          $quote = $observer->getEvent()->getQuote(); 
           if (null !== $quote && $quote->getCustomerGroupId() != 'CUSTOMER_GROUP_ID') { 
            if ($method_instance->getCode() == 'PAYMENT_METHOD_CODE') {
              $result->setData('is_available', false);
            } 
          }
        }
      }
    } 
    ?>

    By following the above steps, you can restrict the payment methods in Magento 2 store.
    If you have any doubt regarding the above method, feel free to ask me the comment section.

    I would be happy to help you.

    All You Need To Know About Magento 1 End Of Life

    When is the Magento 1 End of Life date?

    Nothing is confirmed yet but the official end of life date given by Magento is June 2020. After June 2020, Magento 1 websites will no longer get any support, security patches or updates. Further, merchants will not receive any new functionalities or extension in terms of security and customer requirements.

    Why it is important to migrate from Magento 1?

    You should migrate from Magento 1 as from June 2020 there will not be any further support and to remain on Magento 1 will not give you further development. No further updates and patches will be released so this will increase the risk of security breaches for your Magento 1 website.

    Are there any issues of staying on Magento 1 after the end of life?

    Yes, there are several issues of staying on Magento 1 after the end of life.

    Security risks

    After June 2020, Magento 1 Community and Enterprise editions will no longer have patch updates which means your website will have no protection against vulnerabilities. This will put your website as well as your customers’ data at risk of falling into the wrong hands.

    Out of date modules

    Developers in the community give more focus on optimising modules and plugins for Magento 2 and the modules built particularly for Magento 1 may be unsupported and go out of date. This will harm the performance of your Magento 1 website.

    Lack of resources

    You will have fewer options in terms of developers if you stay on Magento 1 for long. The most in-demand agencies will have clients on their books well in advance of the end of life date. There are chances that some agencies will not opt for problematic Magento 1 sites instead they will allow developers to gain more experience on Magento 2.

    Increased liability

    If you continue to use Magento 1 after June 2020 then there are chances that your agency will no longer maintain or host your website as it may become a liability to them. As a result, your website will become your responsibility for keeping it updated and secure which is even more difficult with the absence of any official updates.

    Time’s running out

    Migrating from Magento 1 to Magento 2 is a time-consuming process as it takes on average between 3 and 6 months. (It depends on the complexity of your website’s functionality and the depth of your product catalogue) Considering the availability of developers, seasonal trends and peak period, time is the most important factor here.

    What are the key benefits of Magento 2?

    Better performance

    Full-page caching, allowing for better site speed

    Improved server response time

    Minified JavaScript, CSS and HTML as well as image compression to provide faster load speeds

    Ease of purchase

    Easily integrated upsell, cross-sell and recommendations functionality

    Reduced risk of basket abandonment thanks to a shortened checkout process

    Integration with the world’s leading payment gateways, couriers and third party fulfilment software

    Mobile-first design

    Responsive and mobile-friendly designs adaptable to any screen resolution

    Dedicated content management sections to provide customised mobile designs

    Improved mobile usability for both front-end customers and back-end administrators

    Integrated marketing functionality

    Easy creation of landing pages through the CMS and PageBuilder

    Improved on-site search and SEO functionality

    Including metadata, category descriptions and search engine friendly URLs

    Third-party module integrations

    Easily integrated omnichannel selling with the likes of Amazon and eBay

    Improved retargeting, marketing messaging and abandoned basket functionality through Dotdigital

    Easier to manage admin

    Improved admin panel layout provides a better experience for merchants

    Customisable dashboard show metrics that matter to you – including recent orders, best-sellers and AOV

    Product catalogues, SKUs and uploads are much easier to manage

    Enhanced B2B functionality

    Allow customers to submit quote requests, based on uploading a list of SKUs via CSV

    Easy re-ordering functionality for repeat customers

    Customised pricing and catalogues for B2B customers behind a password-protected gateway

    How do you prepare for a Magento 1 to Magento 2 migration?

    Migrating from Magento 1 to Magento 2 is not at all an easy task. To make the best choice for your business, you have to consider multiple variables. Magento 1 and Magento 2 work on completely separate systems. So migrating to Magento 2 will be more straightforward but there are few risks to keep in mind.

    First, you have to be clear about your business needs. Migrating to Magento 2 is a large financial investment; therefore your resources should ready to help out with day-to-day operations.

    What if as a merchant one wants to stick with Magento 1 only?

    Magento development agencies like Mage Monkeys offers M1 Support. You should opt for it to avoid any trouble.

    Hire the right Magento agency for a smooth migration

    If you want professional help with 100% satisfaction, you can always ask for Magento 1 to Magento 2 Migration Service that guarantees Magento 2 migration with zero downtime and no data loss!

    How to Optimize Magento 2 Website Product Pages to Improve Conversion?

    If you are the owner of an online store, you always have to think of different ways to boost your online sales. To convert more visitors into paying customers, you have to pay attention to your website product page.

    A recent study states that 53 percent of businesses spend less than 5 percent of their total marketing budget on conversion optimization and 35 percent of the businesses report a conversion rate of less than 1 percent.

    Website conversion optimization is the most neglected part of digital marketing. eCommerce website owners hardly get time to invest in conversion optimization.

    The question here is…

    What should be the conversion rate of your Magento online store? 

    Achieve better than the present one. We have mentioned some effective ways which will increase your conversion rates. Use these tips collectively to see the difference.

    Product Images

    Using high-resolution quality photos of your product is the main part of product details. The hero of boosting your eCommerce conversion rate is to show the best candy product images. Take the pictures with different angles and zoom feature.

    Images say a lot about the product than a product description. Good quality images can help you sell products even without any description of it. Always use fully optimized product images so that it doesn’t make your pages loading slowly. Ask your Magento eCommerce Developer to optimize product images.

    Product Description

    A complete description of products is very important and it also helps in your SEO efforts. Providing enough information to customers can convince them to proceed to the checkout page. Your products should have the full and short version of description moreover you can also provide a comparison chart.

    Product Videos

    Images have their limitations but videos are essential as it’s the future. Create good quality videos to convince your customer to trust your products

    Product Personalization

    Customers love to personalize stuff as they want their belonging to be unique and to have a feeling of owning something that nobody else has. Convince visitors to purchase your products by implementing some personalization functionality. Hire Magento 2 developers from us to make this happen for you.

    Product Reviews by Customers

    Product reviews and customer’s opinions help in building visitor’s trust. Magento platform has a default review and rating functionality for the products, even without login or registers your customers can write their feedback and opinion.

    Ensure that your showcase good reviews for each product on their respective product pages. The review should have the full name and photo of the customer. You will see an increase in the conversion rate by 30-50 percent.

    Shipping Charges

    More than half of the merchants offer free shipping. A survey stated that 47 percent of customers leave the website if they find shipping charges on the checkout page.

    Your sale can be affected by a hidden cost. Be clear about the shipping charges and mention it where customers can see them before buying. Instead of charging the shipping price of each item you can charge a flat shipping rate.

    Sales and Special Offers

    Consumers love endless sales and coupons. As per well-known research, 47 percent of customers only buy products with discounted prices or special offers whereas 62 percent are searching for a specific sale and special section. Your site should have a separate “sales” section on the website on the homepage and sidebars.

    Shopping Cart Abandonment

    Some factors which give rise to cart abandonment and what you can do about them:

    Hassle before purchase: Make sure that you do not ask for too much data or force them for registration before checkout.

    Page loading speed: Make sure that your website is fast and efficient so that consumers do not have to wait while your web pages get loaded. Optimize your site speed with the help of an Expert Magento Developers

    Customer query: It will suit me or not? Is it returnable? Have a live chat box feature to solve your customer’s concerns and answer their questions.

    High Product Price: You will likely lose sales if your prices are higher than your competitors. You must convey why your product is worth purchasing.

    Shipping charges: provide free shipping to turn a visitor into a customer.

    Follow up

    To reduce the shopping cart abandonment rate, you should follow up with a customer through email. It is one of the most effective ways to boost conversion rates.

    What do you need to do?

    Ask for their email address before checkout. You can send follow-up emails for incomplete orders.

    Make sure to send the first follow-up emails as soon as possible. You can even send free coupons if the purchase haven not taken place.

    Keep track of sent emails so that you can measure their effectiveness.

    Offer Live Chat & Show Contact Info

    Practice good and timely communication to achieve a higher conversion rate. Visitors expect a quick reply so ensure you cover all the bases. Build initial trust for your new website visitors by mentioning a phone number for direct contact. A survey suggests that 77 percent of e-retailers consider live chat as a critical communication method.

    Analytics

    With Google Analytics you can track your online store traffic and live data along with product page and also cart-checkout pages. Instead of manually adding tags to each page you can use the Google Remarketing tag on all your website pages. This will help in reaching specific audiences. After adding your tag, you just have to launch the remarketing campaign with your AdWords account by filtered dynamic ads based on visited pages and actions taken on site.

    Social Media

    You will see a significant change in conversion rate by integrating social media into your online store. Here you have to try and see which feature works best for you.

    Customers do not like Facebook like Google Plus or the Tweet button on product pages. Instead of the like and share feature, you can show Twitter feed and Facebook page timeline. You can also be considered social logins for your Magento 2 webshop.

    Try these features on some of the products and compare them to conclude which feature works best for your Magento web store. Make the best of the above-mentioned tips to boost the conversion rate of your Magento store.

    Magento 2: Add VAT and Company Number in footer of invoice and shipment PDF

    In this article, I will guide you on, how to add VAT and Company Number in invoice and shipment PDF in Magento 2?

    Follow the below steps:

    You need to override two models in custom extension.

    I assume you know about how to override model.

    Step 1

    Create di.xml file in your module’s etc folder and put below code in it

    <?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="MagentoSalesModelOrderPdfInvoice" type="[vendername][modulename]ModelOrderPdfinvoice" />
     <preference for="MagentoSalesModelOrderPdfShipment" type="[vendername][modulename]OrderPdfshipment" />
    </config>

    Step 2

    Create new model file Pdfinvoice.php in your Model/Order folder and put below code in it.

    <?php
    namespace [vendername][modulename]ModelOrder;
    class Pdfinvoice extends MagentoSalesModelOrderPdfInvoice
    {
     /**
     * Return PDF document
     *
     * @param array|Collection $invoices
     * @return Zend_Pdf
     */
     public function getPdf($invoices = [])
     {
     $this->_beforeGetPdf();
     $this->_initRenderer('invoice');
    
     $pdf = new Zend_Pdf();
     $this->_setPdf($pdf);
     $style = new Zend_Pdf_Style();
     $this->_setFontBold($style, 10);
    
     foreach ($invoices as $invoice) {
     if ($invoice->getStoreId()) {
     $this->_localeResolver->emulate($invoice->getStoreId());
     $this->_storeManager->setCurrentStore($invoice->getStoreId());
     }
     $page = $this->newPage();
     $order = $invoice->getOrder();
     /* Add image */
     $this->insertLogo($page, $invoice->getStore());
     /* Add address */
     $this->insertAddress($page, $invoice->getStore());
     /* Add head */
     $this->insertOrder(
     $page,
     $order,
     $this->_scopeConfig->isSetFlag(
     self::XML_PATH_SALES_PDF_INVOICE_PUT_ORDER_ID,
     MagentoStoreModelScopeInterface::SCOPE_STORE,
     $order->getStoreId()
     )
     );
     
     /* Add document text and number */
     $this->insertDocumentNumber($page, __('Invoice # ') . $invoice->getIncrementId());
     /* Add table */
     $this->_drawHeader($page);
     /* Add body */
     foreach ($invoice->getAllItems() as $item) {
     if ($item->getOrderItem()->getParentItem()) {
     continue;
     }
     /* Draw item */
     $this->_drawItem($item, $page, $order);
     $page = end($pdf->pages);
     }
     /* Add totals */
     $this->insertTotals($page, $invoice);
     if ($invoice->getStoreId()) {
     $this->_localeResolver->revert();
     }
     $this->_drawFooter($page);
     }
     $this->_afterGetPdf();
     return $pdf;
     }
    
     protected function _drawFooter(Zend_Pdf_Page $page)
     {
     $this->y = 50; 
     $page->setFillColor(new Zend_Pdf_Color_RGB(1, 1, 1));
     $page->setLineColor(new Zend_Pdf_Color_GrayScale(0.5));
     $page->drawRectangle(25, $this->y, 570, $this->y -30);
     $page->setLineWidth(0.5);
    
     $page->setFillColor(new Zend_Pdf_Color_RGB(0.1, 0.1, 0.1));
     $this->_setFontRegular($page, 10);
     $this->y -=16;
     $page->drawText(__('VAT # xxxxxxxx'), 220, $this->y, 'UTF-8');
     $page->drawText(__('Company # xxxxxxxxx'), 320, $this->y, 'UTF-8');
    
     } 
    }

    Step 3

    Create another new model file Pdfshipment.php in your Model/Order folder and put below code in it.

    <?php
    namespace [vendername][modulename]ModelOrder;
    class Pdfshipment extends MagentoSalesModelOrderPdfShipment
    {
     /**
     * Return PDF document
     *
     * @param MagentoSalesModelOrderShipment[] $shipments
     * @return Zend_Pdf
     */
     public function getPdf($shipments = [])
     {
     $this->_beforeGetPdf();
     $this->_initRenderer('shipment');
    
     $pdf = new Zend_Pdf();
     $this->_setPdf($pdf);
     $style = new Zend_Pdf_Style();
     $this->_setFontBold($style, 10);
     foreach ($shipments as $shipment) {
     if ($shipment->getStoreId()) {
     $this->_localeResolver->emulate($shipment->getStoreId());
     $this->_storeManager->setCurrentStore($shipment->getStoreId());
     }
     $page = $this->newPage();
     $order = $shipment->getOrder();
     /* Add image */
     $this->insertLogo($page, $shipment->getStore());
     /* Add address */
     $this->insertAddress($page, $shipment->getStore());
     /* Add head */
     $this->insertOrder(
     $page,
     $shipment,
     $this->_scopeConfig->isSetFlag(
     self::XML_PATH_SALES_PDF_SHIPMENT_PUT_ORDER_ID,
     MagentoStoreModelScopeInterface::SCOPE_STORE,
     $order->getStoreId()
     )
     );
     /* Add document text and number */
     $this->insertDocumentNumber($page, __('Packing Slip # ') . $shipment->getIncrementId());
     /* Add table */
     $this->_drawHeader($page);
     /* Add body */
     foreach ($shipment->getAllItems() as $item) {
     if ($item->getOrderItem()->getParentItem()) {
     continue;
     }
     /* Draw item */
     $this->_drawItem($item, $page, $order);
     $page = end($pdf->pages);
     }
     if ($shipment->getStoreId()) {
     $this->_localeResolver->revert();
     }
     $this->_drawFooter($page);
     }
     $this->_afterGetPdf();
     return $pdf;
     }
    
     protected function _drawFooter(Zend_Pdf_Page $page)
     {
     $this->y = 50; 
     $page->setFillColor(new Zend_Pdf_Color_RGB(1, 1, 1));
     $page->setLineColor(new Zend_Pdf_Color_GrayScale(0.5));
     $page->drawRectangle(25, $this->y, 570, $this->y -30);
     $page->setLineWidth(0.5);
    
     $page->setFillColor(new Zend_Pdf_Color_RGB(0.1, 0.1, 0.1));
     $this->_setFontRegular($page, 10);
     $this->y -=16;
     $page->drawText(__('VAT # xxxxxxxxx'), 220, $this->y, 'UTF-8');
     $page->drawText(__('Company # xxxxxxxxx'), 320, $this->y, 'UTF-8');
    
     }
    }

    Magento 2 : Get bundle child product description on bundle parent product detail page

    If you want to get bundle child product description on bundle parent product detail page in ‘DETAILS’ tab.

    You can override attribute.phtml file in your theme and put below code at bottom of the file

    <?php 
    if($_product->getTypeId() === 'bundle'){ 
     $objectManager = MagentoFrameworkAppObjectManager::getInstance();
     $product = $objectManager->get('MagentoCatalogModelProduct')->load($_product->getId()); 
     $selectionCollection = $product->getTypeInstance(true)->getSelectionsCollection($product->getTypeInstance(true)->getOptionsIds($product),$product);
     foreach ($selectionCollection as $proselection) { 
     $option_product = $objectManager->get('MagentoCatalogModelProduct')->load($proselection->getId()); ?>
     <div class="bundle-item-description"> 
     <h3><?php echo $option_product->getName() ?></h3>
     <p><?php echo $option_product->getDescription(); ?></p>
     </div>
     <?php }
    } ?>

    How to override block in Magento 2 using the plugin?

    In this article, I will guide you on how to use a plugin to block Override in Magento 2.

    Add di.xml file in app/code/Magemonkeys/HelloWorld/etc/ and copy the following code in it:

    <?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="MagentoCatalogBlockProductView">
            <plugin name="magemonkeys-helloworld-product-block" type="MagemonkeysHelloWorldPluginProductPlugin" sortOrder="5" />
        </type>
    </config>

     

    Here enable all the methods containing before, after, and around methods.

    • Firstly, beforeGetProduct method will be active.
    • Next, aroundGetPrduct will be active.
    • Finally, afterGetProduct method will be active. You can look into the var/log/debug.log and confirm the method execution sequence.

    Add ProductPlugin.php file in app/code/Magemonkeys/HelloWorld/Plugin/ and copy the following code in it:

    <?php
     
    namespace MagemonkeysHelloWorldPlugin;
     
    class ProductPlugin
    {    
        public function beforeGetProduct(MagentoCatalogBlockProductView $subject)
        {
            // logging to test override    
            $logger = MagentoFrameworkAppObjectManager::getInstance()->get('PsrLogLoggerInterface');
            $logger->debug(__METHOD__ . ' - ' . __LINE__);        
        }
        
        public function afterGetProduct(MagentoCatalogBlockProductView $subject, $result)
        {
            // logging to test override    
            $logger = MagentoFrameworkAppObjectManager::getInstance()->get('PsrLogLoggerInterface');
            $logger->debug(__METHOD__ . ' - ' . __LINE__);
            
            return $result;
        }
        
        public function aroundGetProduct(MagentoCatalogBlockProductView $subject, Closure $proceed)
        {
            // logging to test override    
            $logger = MagentoFrameworkAppObjectManager::getInstance()->get('PsrLogLoggerInterface');
            $logger->debug(__METHOD__ . ' - ' . __LINE__);
            
            // call the core observed function
            $returnValue = $proceed(); 
            
            // logging to test override        
            $logger->debug(__METHOD__ . ' - ' . __LINE__);
            
            return $returnValue;
        }    
    }
    ?>
    

     

    Hope this guide helped you to understand the process to block override using plugin. If you have any queries regarding the blog, please comment below. We will assist you as soon as possible.

    Magento 2.3 admin product view not working after migration

    I faced a problem after migration from Magento 1,

    When I go to the admin product page, I can’t see the product view just reloading the loader.

    When I check the log files gives me error like: PHP Fatal error: Method Magento\Ui\TemplateEngine\Xhtml\Result::__toString() must not throw an exception, caught TypeError: Argument 1 passed to Magento\InventorySalesAdminUi\Model\GetSalableQuantityDataBySku::execute() must be of the type string, null given, called in…

    After debugging I found the issue that stated SKU should be empty for migration products.

    As you know, in Magento, the SKU is a required field when you create a new product. So in migration, it might happened that store product SKU was blanked or not a string due to corrupted data.

    To resolve this issue, we need to run below query:

    UPDATE catalog_product_entity SET sku='' WHERE sku IS NULL;

    Simply, we set SKU as NULL and fix that where any SKU’s are store blank in the database.

    Error Solved : DateTime::__construct(): Failed to parse time string (11/08/2019) at position 0 (2): Unexpected char

    If you ever get below error  :
    DateTime::__construct(): Failed to parse time string (11/08/2019) at position 0 (2): Unexpected char

    Here is the solution

    Update this file : /vendor/magento/module-catalog/Controller/Adminhtml/Product/Initialization/Helper.php

    Add one line code :

    private function convertSpecialFromDateStringToObject($productData)
    {
        if (isset($productData['special_from_date']) && $productData['special_from_date'] != '')
        {
            $productData['special_from_date'] = $this->dateFilter->filter($productData['special_from_date']); /* Add this line */
        	$productData['special_from_date'] = new DateTime($productData['special_from_date']);
        }
        ...

    Hope my post is helpful. If you are facing problem during this process, then feel free to comment.

    Guide to remove or delete products of a particular attribute set in Magento 2.

    In this guide, I am going to show you, how to remove the product of a particular attribute set in Magento 2 programmatically?

    First of all, you have to create a file called “deleteProducts.php” on Magento 2 root directory.

    And then paste the below code into that file.

    <?php
    set_time_limit(0);
    ini_set('display_errors', 1);
    ini_set('memory_limit', -1);
    use MagentoFrameworkAppBootstrap;
    require __DIR__ . '/app/bootstrap.php';
    
    $bootstraps = Bootstrap::create(BP, $_SERVER);
    $objectManager = $bootstraps->getObjectManager();
    
    
    deleteAllProducts($objectManager);
     
    function deleteAllProducts($objectManager) {
     
        $objectManager->get('MagentoFrameworkRegistry')->register('isSecureArea', true);
    
        $attrSetName = 'Dress'; // Atribute set name
        $attribute_set_factoryCollection = $objectManager->get('MagentoEavModelResourceModelEntityAttributeSetCollectionFactory');
    
        $attribute_set_collection = $attribute_set_factoryCollection->create();
    
        $attribute_set_collection
        ->addFieldToFilter('entity_type_id',4)
        ->addFieldToFilter('attribute_set_name',$attrSetName);
    
        $att_set = current($attribute_set_collection->getData());
        $attribute_set_id = $att_set["attribute_set_id"];
    
        $productCollection = $objectManager->create('MagentoCatalogModelResourceModelProductCollectionFactory');
        $collection = $productCollection->create()->addAttributeToSelect('*')->addFieldToFilter('attribute_set_id',$attribute_set_id)->load();
        $app_state = $objectManager->get('MagentoFrameworkAppState');
        $app_state->setAreaCode('frontend');
    
        foreach ($collection as $product){
            try {
                echo 'Deleted '.$product->getName().PHP_EOL;
                $product->delete();
            } catch (Exception $e) {
                echo 'Failed to remove product '.$product->getName() .PHP_EOL;
                echo $e->getMessage() . "n" .PHP_EOL;
            }
        }      
    }

    And now you can run this file through cronjob and URL.

    So the URL will be like this : http://yourdomainname/deleteProducts.php

    That’s it.

    I hope my post is helpful. If you still need any assistance about that, please comment below.

    How to add extension attribute for quote field in Magento 2?

    Define the extension attribute in XML

    app/code/Vendor/Module/etc/extension_attributes.xml

    <?xml version="1.0"?>
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Api/etc/extension_attributes.xsd">
        <extension_attributes for="MagentoCheckoutApiDataShippingInformationInterface">
            <attribute code="address_two" type="string"/>
        </extension_attributes>
    </config>
    

    Assigning the value for extension attributes in knockout js 

    app/code/Vendor/Module/view/frontend/web/js/shipping-save-processor-default.js

    saveShippingInformation: function () {
                    var payload;
    
                    payload = {
                        addressInformation: {
                            shipping_address: quote.shippingAddress(),
                            billing_address: quote.billingAddress(),
                            shipping_method_code: quote.shippingMethod().method_code,
                            shipping_carrier_code: quote.shippingMethod().carrier_code,
                            extension_attributes: {
                                address_two: $('form.form-shipping-address input[name="address2"]').val()
                            }
                        }
                    };
    
                    return storage.post(
                        resourceUrlManager.getUrlForSetShippingInformation(quote),
                        JSON.stringify(payload)
                    ).done(
                        function (response) {
                            quote.setTotals(response.totals);
                            paymentService.setPaymentMethods(methodConverter(response.payment_methods));
                        }
                    ).fail(
                        function (response) {
                            errorProcessor.process(response);
                        }
                    );
                }

    Save Extension Attribute to quote table using beforeSaveAddressInformation method using Plugin

    app/code/Vendor/Module/Model/Checkout/ShippingInformationManagementPlugin.php

     

    namespace VendorModuleModelCheckout;
    /**
     * Class ShippingInformationManagementPlugin
     * @package OyeDeliverydateModelCheckout
     */
    class ShippingInformationManagementPlugin
    {
    
        protected $quoteRepository;
    
        /**
         * @param MagentoQuoteModelQuoteRepository $quoteRepository
         */
        public function __construct(
            MagentoQuoteModelQuoteRepository $quoteRepository
        ) {
            $this->quoteRepository = $quoteRepository;
        }
    
        /**
         * @param MagentoCheckoutModelShippingInformationManagement $subject
         * @param $cartId
         * @param MagentoCheckoutApiDataShippingInformationInterface $addressInformation
         */
        public function beforeSaveAddressInformation(
            MagentoCheckoutModelShippingInformationManagement $subject,
            $cartId,
            MagentoCheckoutApiDataShippingInformationInterface $addressInformation
        ) {
            $extAttributes = $addressInformation->getExtensionAttributes();
            $address2=$extAttributes->getAddressTwo();
    
            $quote = $this->quoteRepository->getActive($cartId);
            
            $quote->setShippingAddressTwo($shippngaddress2);    
            $this->quoteRepository->save($quote);;
    
        }
    }

     

    CONTACT US to get Magento programming solutions by hiring a certified Magento expert.