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 : Product minimum amount which restrict customer to proceed checkout

    If you want restrict customer to checkout based on your min product amount, then here are the steps to create module.

    Here we are using Magemonkeys as Vendor name and CheckoutRestriction as the name of a module. You can change this according to your Vendor and Module name.

    Step 1: Create Registration

    Create registration.php file in the app/code/Magemonkeys/CheckoutRestriction folder with the following code.

    <?php
    MagentoFrameworkComponentComponentRegistrar::register(
        MagentoFrameworkComponentComponentRegistrar::MODULE,
        'Magemonkeys_CheckoutRestriction',
        __DIR__
    );

    Step 2: Create a module

    Create a module.xml file in the app/code/Magemonkeys/CheckoutRestriction/etc folder with the following code.

    <?xml version="1.0" ?>
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
        <module name="Magemonkeys_CheckoutRestriction" setup_version="1.0.0">
            <sequence>
                <module name="Magento_Checkout"/>
            </sequence>
        </module>
    </config>

    Step 3: Create a helper

    Create a Restriction.php file in the app/code/Magemonkeys/CheckoutRestriction/Helper folder with the following code.

    <?php 
    namespace MagemonkeysCheckoutRestrictionHelper;
    
    use MagentoFrameworkRegistry;
    
    class Restriction extends MagentoFrameworkAppHelperAbstractHelper
    {
    
        protected $cart;
        protected $product;
        
        public function __construct(
            MagentoFrameworkAppHelperContext $context,
            MagentoCheckoutModelCart $cart,
            MagentoCatalogModelProductFactory $product
        ) {
            $this->cart = $cart;
            $this->product = $product;
            
            parent::__construct($context);
        }
        
        public function getProductMinPrice()
        {
            $grandTotal = $this->cart->getQuote()->getGrandTotal();
            $items = $this->cart->getQuote()->getAllItems();
    
            $itemData = array();
            foreach($items as $item) {
                $product = $this->getLoadProduct($item->getProduct()->getId());
    
                if ($allow_flag = $product->getCustomAttribute("min_order_allow_amount")){
                    if((int)$product->getCustomAttribute("min_order_allow_amount")->getValue() > 0) {
                        $rowTotal = $item->getQty() * $item->getPriceInclTax();
                        if(isset($itemData[$product->getSku()]['row_total'])){
                            $itemData[$product->getSku()]['row_total'] += $rowTotal;
                        }else{
                            $itemData[$product->getSku()]['row_total'] = $rowTotal;
                            $itemData[$product->getSku()]['p_name'] = $product->getName();
                        }
                        $itemData[$product->getSku()]['allow_checkout'] = 0;
                        $itemData[$product->getSku()]['min_amt'] = 0;
                        if ($allow_amount = $product->getCustomAttribute("min_order_allow_amount")){
                            $itemData[$product->getSku()]['min_amt'] = $product->getCustomAttribute("min_order_allow_amount")->getValue();
                            $itemData[$product->getSku()]['min_amount_meaasge'] = "The total price of any combination of this board must be more then ".$itemData[$product->getSku()]['min_amt'];
                            if($product->getCustomAttribute("min_order_allow_amount")->getValue() <= $itemData[$product->getSku()]['row_total']) {
                                $itemData[$product->getSku()]['allow_checkout'] = 1;
                            }
                        }
                    }
                }
            }
    
            $message_checkout = "";
            $message_checkout_flag = 0;
            if(!empty($itemData)){
                foreach($itemData as $it => $d){
                    if($d['allow_checkout'] == 0){
                        $message_checkout_flag = 1;
                        $message_checkout .= "Min amount <b>$".$d['min_amt']."</b> require for Product <b>".$d['p_name']."</b><br>";
                    }
                }
            }
            return array('message_checkout' =>$message_checkout , 'message_checkout_flag' =>$message_checkout_flag, 'itemData' => $itemData);
        }
    
        public function getLoadProduct($id)
        {
            return $this->product->create()->load($id);
        }
    
        public function checkMinAmountByProductID($p_id)
        {
            $product = $this->getLoadProduct($p_id);
            $restric_data = $this->getProductMinPrice();
    
            if(!empty($restric_data) && isset($restric_data['message_checkout_flag']) && $restric_data['message_checkout_flag'] == 1 && array_key_exists($product->getSku(), $restric_data['itemData'])){
                return $restric_data['itemData'][$product->getSku()]['min_amount_meaasge'];
            }
            return '';
        }
    }

    Step 4: Create a Plugin file

    Create a Restrict.php file in the app/code/Magemonkeys/CheckoutRestriction/Plugin/Checkout/Controller with the following code.

    <?php
     
    namespace MagemonkeysCheckoutRestrictionPluginCheckoutController;
     
    use MagentoFrameworkControllerResultRedirectFactory;
    use MagentoFrameworkMessageManagerInterface;
    use MagentoFrameworkUrlFactory;
    use MagentoCheckoutControllerIndexIndex;
    use MagemonkeysCheckoutRestrictionHelperRestriction;
     
    class Restrict
    {
        private $urlModel;
        private $resultRedirectFactory;
        private $messageManager;
     
        public function __construct(
            UrlFactory $urlFactory,
            RedirectFactory $redirectFactory,
            ManagerInterface $messageManager,
            Restriction $checkout_helper
        ) {
        
            $this->urlModel = $urlFactory;
            $this->resultRedirectFactory = $redirectFactory;
            $this->messageManager = $messageManager;
            $this->checkout_helper = $checkout_helper;
        }
     
        public function aroundExecute(
            Index $subject,
            Closure $proceed
        ) {
        
            $this->urlModel = $this->urlModel->create();
    
            //add your logic here
            $restrict_data = $this->checkout_helper->getProductMinPrice();
            if(!empty($restrict_data) && isset($restrict_data['message_checkout_flag']) && $restrict_data['message_checkout_flag'] == 1){
                $this->messageManager->addErrorMessage(__("Unable to checkout as one or more products have not met their minimum purchase theshold."));
                $defaultUrl = $this->urlModel->getUrl('checkout/cart/', ['_secure' => true]);
                $resultRedirect = $this->resultRedirectFactory->create();
                return $resultRedirect->setUrl($defaultUrl);
            }
              
            return $proceed();
        }
    }

    Step 5: Override checkout_cart_item_renderers.xml

    Create a checkout_cart_item_renderers.xml file in the app/code/Magemonkeys/CheckoutRestriction/view/frontend/layout folder with the following code.

    <?xml version="1.0"?>
    <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
        <update handle="checkout_item_price_renderers"/>
        <body>
            <referenceBlock name="checkout.cart.item.renderers">
                <block class="MagentoCheckoutBlockCartItemRenderer" name="checkout.cart.item.renderers.simple" as="simple" template="Magemonkeys_CheckoutRestriction::cart/item/default.phtml"> 
                    <block class="MagentoCheckoutBlockCartItemRendererActions" name="checkout.cart.item.renderers.simple.actions" as="actions">
                        <block class="MagentoCheckoutBlockCartItemRendererActionsEdit" name="checkout.cart.item.renderers.simple.actions.edit" template="Magento_Checkout::cart/item/renderer/actions/edit.phtml"/>
                        <block class="MagentoCheckoutBlockCartItemRendererActionsRemove" name="checkout.cart.item.renderers.simple.actions.remove" template="Magento_Checkout::cart/item/renderer/actions/remove.phtml"/>
                    </block>
                </block>
            </referenceBlock>
        </body>
    </page>

    Step 6: Override default.phtml

    Create a default.phtml file in the app/code/Magemonkeys/CheckoutRestriction/view/frontend/templates/cart/item folder with the following code.

    <?php
    /**
     * Copyright © Magento, Inc. All rights reserved.
     * See COPYING.txt for license details.
     */
    
    /** @var $block MagentoCheckoutBlockCartItemRenderer */
    
    $_item = $block->getItem();
    $product = $_item->getProduct();
    $isVisibleProduct = $product->isVisibleInSiteVisibility();
    /** @var MagentoMsrpHelperData $helper */
    $helper = $this->helper(MagentoMsrpHelperData::class);
    $canApplyMsrp = $helper->isShowBeforeOrderConfirm($product) && $helper->isMinimalPriceLessMsrp($product);
    
    $checkout_helper = $this->helper('MagemonkeysCheckoutRestrictionHelperRestriction');
    $min_amount_message = $checkout_helper->checkMinAmountByProductID($product->getId());
    ?>
    <tbody class="cart item">
        <tr class="item-info">
            <td data-th="<?= $block->escapeHtmlAttr(__('Item')) ?>" class="col item">
                <?php if ($block->hasProductUrl()) :?>
                    <a href="<?= $block->escapeUrl($block->getProductUrl()) ?>"
                       title="<?= $block->escapeHtmlAttr($block->getProductName()) ?>"
                       tabindex="-1"
                       class="product-item-photo">
                <?php else :?>
                    <span class="product-item-photo">
                <?php endif;?>
                <?= $block->getImage($block->getProductForThumbnail(), 'cart_page_product_thumbnail')->toHtml() ?>
                <?php if ($block->hasProductUrl()) :?>
                    </a>
                <?php else :?>
                    </span>
                <?php endif; ?>
                <div class="product-item-details">
                    <strong class="product-item-name">
                        <?php if ($block->hasProductUrl()) :?>
                            <a href="<?= $block->escapeUrl($block->getProductUrl()) ?>"><?= $block->escapeHtml($block->getProductName()) ?></a>
                        <?php else :?>
                            <?= $block->escapeHtml($block->getProductName()) ?>
                        <?php endif; ?>
                    </strong>
                    <?php if ($_options = $block->getOptionList()) :?>
                        <dl class="item-options">
                            <?php foreach ($_options as $_option) :?>
                                <?php $_formatedOptionValue = $block->getFormatedOptionValue($_option) ?>
                                <dt><?= $block->escapeHtml($_option['label']) ?></dt>
                                <dd>
                                    <?php if (isset($_formatedOptionValue['full_view'])) :?>
                                        <?= $block->escapeHtml($_formatedOptionValue['full_view']) ?>
                                    <?php else :?>
                                        <?= $block->escapeHtml($_formatedOptionValue['value'], ['span', 'a']) ?>
                                    <?php endif; ?>
                                </dd>
                            <?php endforeach; ?>
                        </dl>
                    <?php endif;?>
                    <?php if ($messages = $block->getMessages()) :?>
                        <?php foreach ($messages as $message) :?>
                            <div class= "cart item message <?= $block->escapeHtmlAttr($message['type']) ?>">
                                <div><?= $block->escapeHtml($message['text']) ?></div>
                            </div>
                        <?php endforeach; ?>
                    <?php endif; ?>
                    <?php $addInfoBlock = $block->getProductAdditionalInformationBlock(); ?>
                    <?php if ($addInfoBlock) :?>
                        <?= $addInfoBlock->setItem($_item)->toHtml() ?>
                    <?php endif;?>
                </div>
            </td>
    
            <?php if ($canApplyMsrp) :?>
                <td class="col msrp" data-th="<?= $block->escapeHtmlAttr(__('Price')) ?>">
                    <span class="pricing msrp">
                        <span class="msrp notice"><?= $block->escapeHtml(__('See price before order confirmation.')) ?></span>
                        <?php $helpLinkId = 'cart-msrp-help-' . $_item->getId(); ?>
                        <a href="#" class="action help map"
                           id="<?= ($block->escapeHtmlAttr($helpLinkId)) ?>"
                           data-mage-init='{"addToCart":{
                                                "helpLinkId": "#<?= $block->escapeJs($block->escapeHtml($helpLinkId)) ?>",
                                                "productName": "<?= $block->escapeJs($block->escapeHtml($product->getName())) ?>",
                                                "showAddToCart": false
                                                }
                                            }'
                        >
                            <span><?= $block->escapeHtml(__("What's this?")) ?></span>
                        </a>
                    </span>
                </td>
            <?php else :?>
                <td class="col price" data-th="<?= $block->escapeHtmlAttr(__('Price')) ?>">
                    <?= $block->getUnitPriceHtml($_item) ?>
                </td>
            <?php endif; ?>
            <td class="col qty" data-th="<?= $block->escapeHtmlAttr(__('Qty')) ?>">
                <div class="field qty">
                    <div class="control qty">
                        <label for="cart-<?= $block->escapeHtmlAttr($_item->getId()) ?>-qty">
                            <span class="label"><?= $block->escapeHtml(__('Qty')) ?></span>
                            <input id="cart-<?= $block->escapeHtmlAttr($_item->getId()) ?>-qty"
                                   name="cart[<?= $block->escapeHtmlAttr($_item->getId()) ?>][qty]"
                                   data-cart-item-id="<?= $block->escapeHtmlAttr($_item->getSku()) ?>"
                                   value="<?= $block->escapeHtmlAttr($block->getQty()) ?>"
                                   type="number"
                                   size="4"
                                   step="any"
                                   title="<?= $block->escapeHtmlAttr(__('Qty')) ?>"
                                   class="input-text qty"
                                   data-validate="{required:true,'validate-greater-than-zero':true}"
                                   data-role="cart-item-qty"/>
                        </label>
                    </div>
                </div>
            </td>
    
            <td class="col subtotal" data-th="<?= $block->escapeHtmlAttr(__('Subtotal')) ?>">
                <?php if ($canApplyMsrp) :?>
                    <span class="cart msrp subtotal">--</span>
                <?php else :?>
                    <?= $block->getRowTotalHtml($_item) ?>
                <?php endif; ?>
            </td>
        </tr>
        <?php if(!empty($min_amount_message)){ ?>
            <tr class="min-amount-message-box">
                <td colspan="4">
                    <div role="alert" class="messages">
                        <div class="message-error error message" data-ui-id="message-error">
                            <div><?= $min_amount_message ?></div>
                        </div>
                    </div>
                </td>
            </tr>
        <?php } ?>
        <tr class="item-actions">
            <td colspan="4">
                <div class="actions-toolbar">
                    <?= /* @noEscape */ $block->getActions($_item) ?>
                </div>
            </td>
        </tr>
    </tbody>

    After adding above files here are some extra step

    1. You need to create product attribute from admin and assign it to attribute set.

    2. Add product min amount to validate.

    Note: Attribute code must be “min_order_allow_amount”

    Here is the screenshot which shows error message for product min amount.

    Is your eCommerce store facing any page speed issues?

    If ‘YES’, then it is time you consider the matter seriously as low page speed can hurt your eCommerce business and lead to losses.

    Improving page speed offers a number of benefits to the eCommerce store and so investing in the right Magento agency is the right move to make for your online business.

    • Increase in conversions and sales

    When it comes to conversions, page speed plays a key role for eCommerce stores. If you build an appealing eCommerce store but fail to focus on improving the site speed then chances are high that your potential customers will stop visiting your store after failing to get a good experience. This can hurt your sales and conversion rate dearly.

    • Improves SEO rankings

    Google loves sites with good speed. This means if your eCommerce store has a fast load page speed then it will have the advantage of ranking better on Google results. eCommerce stores that will be present in the top places in the search results will be clicked and explored by the maximum online visitors.

    • Offers impressive user experience

    The speed of the eCommerce store will decide what the user will think about the brand and how they will proceed to use it. Humans are more inclined towards following eCommerce stores that are faster as they consider them to be more reliable. Offering such a positive experience for your first-timers can definitely help your eCommerce store in many ways.

    • Reduce bounce rates

    If your shoppers find your eCommerce store has slow page speed then chances are high that they will get frustrated and leave your store at once. Increased bounce rate is definitely going to hurt your revenue.

    If you are looking for a Magento partner to help you improve the speed of your Magento store then choose Mage Monkeys. Our team will audit your eCommerce store to list out the issues before getting ahead with the page speed optimization services.

    So, all you have to do is to fill-up the form below and our team of experts will contact you soon.

    How Can Website Design Improve Sales?

    A clean and modern website will make visitors feel comfortable browsing or shopping on your page. As a result, they’re more likely to purchase from your business.

    As per research, 68% of people stop engaging with a website if it’s unattractive. If that’s true, you need to focus more on your web design.

    A website design should have the below characteristics:

    – It should be Responsive
    – It should be Light weighted
    – It should be Neat and Clean
    – It should have proper CTAs
    – It should match the business
    – It should load Faster
    – & other numerous factors

    If a website will have the above characteristics then you will surely notice an improvement in sales.

    But, unfortunately, businesses don’t upgrade their websites from time to time and fail to adopt the above characteristics.

    At Mage monkeys, we have helped numerous eCommerce stores to adopt web design with all sales-focused characteristics that result in sales improvement.

    If you are stuck to gear up your sales cycle or if you feel your website isn’t awesome, then let’s discuss your website.

    How to mass update product attribute pragmatically?

    Update product attribute value programmatically in Magento 2 .

    <?php
    
    namespace VendoreModuleHelper;
    
    use MagentoCatalogModelProductAction as ProductAction;
    use MagentoCatalogModelResourceModelProductCollectionFactory;
    use MagentoFrameworkAppHelperAbstractHelper;
    use MagentoFrameworkAppHelperContext;
    use MagentoStoreModelStoreManagerInterface;
    
    class Data extends AbstractHelper
    {
        protected $messageManager;
        private $productCollection;
        private $productAction;
        private $storeManager;
    
        public function __construct(
            Context $context,
            CollectionFactory $collection,
            ProductAction $action,
            StoreManagerInterface $storeManager
        )
        {
            $this->productCollection = $collection;
            $this->productAction = $action;
            $this->storeManager = $storeManager;
            parent::__construct($context);
        }
    
        public function setcustomAttributeData($param)
        {
            try {
                $collection = $this->productCollection->create()->addFieldToFilter('*');
                $storeId = $this->storeManager->getStore()->getId();
                $ids = [];
                $i = 0;
                foreach ($collection as $item) {
                    $ids[$i] = $item->getEntityId();
                    $i++;
                }
                $this->productAction->updateAttributes($ids, array('attribute' => $param), $storeId);
    
            } catch (Exception $e) {
                $this->messageManager->addError($e->getMessage());
            }
        }
    }

     

    Is your Magento store facing any technical issues? Let’s talk

    An eCommerce store is not a small website that can be managed easily.

    As there are numerous technical factors involved with eCommerce, so it is very natural that you may face technical issues while managing your eCommerce store. However, solving them should be your top priority.

    Not solving your technical issues can

    – Slowdown your site
    – Deliver a bad user experience
    – Drop your order counts
    – Create difficulties to manage admin task
    – Impact on your sales NEGATIVELY

    Apart from the above-listed five, there are numerous problems that can be created if you don’t solve issues and bugs in your site. Sometimes merchants may have the feeling that there are no issues on their sites, but to make sure, one should always run a technical audit.

    If you want to solve all technical issues on your site or want to run a tech audit then fill out the below form and our Magento experts will guide you further.

    Can you downgrade the Magento edition without compromising your functionalities?

    Well, the answer is a big YES.

    Many Magento stores have opted for Magento enterprise commerce versions. But in the long run, they have realized that their store can operate and deliver the same output with the community edition too.

    You can consider downgrading your Magento store from enterprise to community edition when you, as a merchant, feel that the license fee is expensive and does not leverage any of the enterprise features.

    The fees of the enterprise edition are not something one can ignore as 25K USD / year is a heavy price for one to pay.

    What’s the alternative?

    The alternative is to consult a Magento expert and ask him to avail of enterprise-level benefits in the community edition by using plugins. This could be a good solution adopted by numerous Magento store merchants. By this way, you can save up to 90%

    If you want to save 25000 USD per annum, then downgrade your enterprise edition to community level, which comes at no cost.

    Contact us, and we can help you save money.

    Do you have a TRUSTED Magento agency?

    It surprised us when our Magento clients revealed their tech stories and experience with previous Magento agencies.

    They were quoted almost 70% more as compared to the market standards and the results didn’t match their expectations.

    That’s the reason they had to search for a trusted Magento agency and finally got to shake hands with us.

    Why do Magento merchants need a trusted Magento agency?

    – Trusted Magento agency won’t charge them blindly.

    – No unnecessary long-term contract that bounds Merchants.

    – Quicker solution with 24*7 developer availability.

    – Professionalism and dedication are the keys.

    – You can save on tech audit. As the trusted agency will write the best codes.

    – No tech worries when you hire a trusted Magento agency.

    Apart from the above points, there are many reasons why Magento merchants should not pick just any Magento agency, but a trusted one.

    Our clients want to stay with us for the long term. We don’t push our clients for unnecessary contracts, rather we focus on trust-building.

    If you are looking for a trustable solution, let’s talk ONCE.

    Fill out the below form if you are looking for Magento support or solution by a trusted Magento agency.

    Is your sales going down due to technical problems?

    We all know that doing an eCommerce business is not as easy as it used to be. Competitors are increasing day by day.

    If eCommerce merchants don’t focus on solving technical problems, then they increase the chances of turning their visitors down.

    Sometimes merchants ignore technical problems, but it is not something worth a skip as it impacts your SALES directly.

    It is noted by many researchers that stores with technical problems mostly fail to meet the sales target.

    If you don’t want to drag your sales go down due to technical issues, then get them solved by technical experts.

    We helped numerous eCommerce stores to increase their sales by solving their technical problem and performing technical audits.

    Fill out the below form if you want us to solve all technical problems in your store or want us to do a tech audit.

    Get Particular Attribute Options Values from Specific Store

    Please follow the below methods to get the attribute options values from a particular store in Magento.

    I’ve used my code and logic for implementation. You can use your way to implement this thing.

    <?php
    namespace MagemonkeysOptionsBlock;
    
    class Options extends MagentoFrameworkViewElementTemplate
    {    
        protected $eavConfig;
            
        public function __construct(
            .....
            MagentoEavModelConfig $eavConfig,
            .....
        )
        {    
            .......
            $this->eavConfig = $eavConfig;
            .......
        }
        
        public function getAttributeOptionsCollection()
        {
            $attribute = $this->eavConfig->getAttribute('catalog_product', 'Attribute Code Here');
            $attribute->setStoreId(3); // Set Store ID to get options from Particular store.
            $allOptions = $attribute->getSource()->getAllOptions();
    
        }
    }
    ?>

    You can add another classes as per your requirement in the construct method and use them in the same class.

    Looking support for your Magento store? Let’s talk

    eCommerce business is like a car, if it’s not regularly maintained and serviced, it will eventually break down.

    Many eCommerce merchants FAIL to maintain their sites as they are more focused on operations and other business areas.

    Eventually, they need Magento support to solve numerous bugs and improve store performance to achieve MORE SALES.

    At Mage Monkeys, we helped our clients to INCREASE SALES by offering them unconditional Magento support.

    Our sales based support includes:

    – Solving tech issues faced by the client
    – Performing technical audit
    – Improving web speed
    – Adopting the latest technology
    – Helping clients with SEO based technical solutions
    – & sharing many more suggestions through which sales can get improved.

    Our support is not only limited to the problem faced by the client, but we also suggest our client technical suggestions that can help them to increase sales and other performance-based matrices.

    Fill out the below form if you are looking for Magento support.