magento2 – Limit Cart Items to Add in Cart

I want to limit cart items to be added in cart.
Limit Checkout Order or Add to Cart Limit to allow only 6 type of items.
These 6 items can have variable Qty value.

I have done the below code using Event/Observer but not working.

etc/events.xml

<?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="controller_action_predispatch_checkout_cart_add">
        <observer name="ishaq_limit_items_in_cart_checkout_before" instance="IshaqLimitCartItemsObserverCheckoutCartAdd" />
    </event>
</config>

Observer/Checkout/Cart/Add.php

<?php

namespace IshaqLimitCartItemsObserverCheckoutCart;

use MagentoCheckoutModelSession;
use MagentoFrameworkAppActionFlag;
use MagentoFrameworkAppResponseRedirectInterface as ResponseRedirect;
use MagentoFrameworkEventObserver;
use MagentoFrameworkEventObserverInterface;
use MagentoFrameworkMessageManagerInterface as MessageManager;

class Add implements ObserverInterface
{
    /** @var Session $session */
    private $session;

    /** @var ActionFlag $flag */
    private $flag;

    /** @var ResponseRedirect $redirect */
    private $redirect;

    /** @var MessageManager $messageManager */
    private $messageManager;

    /**
     * Add constructor.
     *
     * @param Session          $session
     * @param ActionFlag       $flag
     * @param ResponseRedirect $redirect
     * @param MessageManager   $messageManager
     */
    public function __construct(
        MagentoFrameworkAppRequestInterface $request,
        MagentoCheckoutModelCart $cart,
        ResponseRedirect $redirect,
        MessageManager $messageManager
    ) {
        $this->_request        = $request;
        $this->_cart           = $cart;
        $this->redirect        = $redirect;
        $this->messageManager  = $messageManager;
    }

    /**
     * @param Observer $observer
     *
     * @return $this|void
     * @throws MagentoFrameworkExceptionLocalizedException
     * @throws MagentoFrameworkExceptionNoSuchEntityException
     */
    public function execute(Observer $observer)
    {
        $controller = $observer->getControllerAction();
        $postValues = $this->_request->getPostValue();
        $cartQuote = $this->_cart->getQuote()->getData();
        $cartItemsCount = $this->_cart->getQuote()->getItemsCount();
        $cartItemsAll = $this->_cart->getQuote()->getAllItems();
 
        if($cartItemsCount > 6)
        {
            $observer->getRequest()->setParam('product', false);
            $observer->getRequest()->setParam('return_url', $this->redirect->getRefererUrl());
            $observer->getRequest()->setParam('backUrl', $this->redirect->getRefererUrl());
            $this->messageManager->addErrorMessage(
                __('Only 6 types of products per purchase allowed. Please complete this order first and place another order afterwards.')
            );
        }
    }
}


10 Proven Ways to Reduce E-commerce Shopping Cart Abandonment

1. Make good use of trust stamp

You want to reduce your website’s Shopping Cart Abandonment then use trust stamp. People leave your website at the end and abandon their cart because of the trust issues. Well be honest ask yourself you won’t trust anyone and if you don’t see any trust stamp or badge you won’t buy anything so for that put the trust sign on your cart page so that they can be assured that their money is in good hands and they won’t face any betrayal.

2. Your page loading speed

If you want to reduce your Shopping Cart Abandonment then make sure that your cart page speed is fast and it is responsive because if it is slow and taking time then your customers won’t spend a second there and will leave you. Make it fats and responsive so that your customers won’t leave your website.

3. Social proof marketing

This marketing is the best way to reduce your Shopping Cart Abandonment. Use Social Poof Marketing in giving social proof to your cart page from where your customers are buying your product. When they will the proof that others had bought the same product that they want to buy then this will give them the confidence and they will complete their purchase in an instance. This technique lets you use Social Proof Tools.

With so many, I will say use to use the best one which is Fizfy Social Proof Notification tool. It is the best place to create recent sales notifications which will benefit your website a lot. There are 40+ powerful widgets which you can use to create Notification widgets.

4. Give them fewer choices

Keep this in mind the more time they will spend in selecting the product the more are the chances that they will abandon your product because they aren’t able to decide what to buy and they might want to check out some other website. So if you don’t want this to happen then give them limited and fewer choices so that they can make their choice early and fast.

5. Let them buy as a guest

Don’t make them register when your customers want to buy something from your website because it becomes a lengthy and tiring thing for them and they end up leaving your website. So let them come as your guest and let them complete their purchase like this only.

6. Charge nothing for shipping the product
SEMrush

Why people leave at the end even after liking everything about your product, it is because sometimes when they are surprised with huge shipping charges and they end ditching your product. If you want to reduce your Shopping Cart Abandonment then offer them free shipping and in this way, they will be able to trust your product more and will complete their purchase.

7. Let them ask

It is one of the best ways to reduce your Shopping Cart Abandonment. Let them ask what they want to even if it seems stupid question because everyone has their own share of doubts and wants to resolve them before buying something. It is your duty to answer them and reach out to them and clear whatever problem they are facing.

8. Use the popup

You can stop them from leaving and make them stay and reduce your Shopping Cart Abandonment by using exit intent pop up. This pop up comes into action when people are going to leave your website and then suddenly this pop up comes and stops them by giving irresistible offers like gifts or discount on the purchase.

9. Accept different payment methods

You have to think that everyone isn’t the same. Some are comfortable paying online, some are through credit or debit card and some like to pay when they occupy and lay their hand on the products so accept the payment in different ways and give them lots of payment modes so that you can reduce your Shopping Cart Abandonment.

10. Money back guarantee

It is one of the keys to reducing your Shopping Cart Abandonment. It may not sound that important but it is because when people see this option they are able to trust you and instead of leaving your product they will buy it. It shows that you are taking the responsibility that your product is good and if it is not the way it seemed than you are ready to pay them back and this gives them a lot of confidence.

 

magento2 – Magento 2.4.1 If shopping cart is not empty place a Go To Shopping Cart button next to Add To Cart on Product Detail page

When the shopping cart is NOT empty, I want a button next to the Add To Cart button on the product detail page and have it go to the Shopping Cart

File using to override is:
/app/design/frontend/THEME/default/Magento_Catalog/product/view/addtocart.phtml

Below is my current code without the check shopping cart for items code. I want to only show the Go To Cart button if something is in the cart.

<div class="actions">
        <button type="submit"
                title="<?= $block->escapeHtmlAttr($buttonTitle) ?>"
                class="action primary tocart"
                id="product-addtocart-button"
                 style="width:50%;" disabled>
            <span><?= $block->escapeHtml($buttonTitle) ?></span>
        </button>
        <button type="button" onclick="location.href="https://magento.stackexchange.com/checkout/cart/"" class="action secondary tocart"
                id="product-addtocart-button"
                 style="width:49%; margin-right:0;">
            <span>Go To Cart</span>
        </button>
        <?= $block->getChildHtml('', true) ?>
    </div>

I’ve tried the various solutions out there including Magento 2 add custom button next to cart button and even checking it using the cart helper like https://www.mageplaza.com/devdocs/how-get-data-shopping-cart-items-subtotal-grand-total-billing-shipping-address-magento-2.html and

$helper = $this->helper('MagentoCheckoutHelperCart');
$helper->getItemsCount(); ?>

Definitely not working.

magento2.3 – How to enable ajax for adding to cart up-sell, cross-sell and related products in Magento 2.3.6?

Replace the below code in items.phtml,

path : app/design/frontend/(your_theme)/Magento_catalog/templates/product/list

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

// phpcs:disable Magento2.Templates.ThisInTemplate.FoundThis
// phpcs:disable Generic.WhiteSpace.ScopeIndent.Incorrect

/* @var $block MagentoCatalogBlockProductAbstractProduct */
use MagentoFrameworkAppActionAction;
?>

<?php
switch ($type = $block->getType()) {

    case 'related-rule':
        if ($exist = $block->hasItems()) {
            $type = 'related';
            $class = $type;

            $image = 'related_products_list';
            $title = __('Related Products');
            $items = $block->getAllItems();
            $limit = $block->getPositionLimit();
            $shuffle = (int) $block->isShuffled();
            $canItemsAddToCart = $block->canItemsAddToCart();

            $showAddTo = true;
            $showCart = false;
            $templateType = null;
            $description = false;
        }
        break;

    case 'related':
        /** @var MagentoCatalogBlockProductProductListRelated $block */
        if ($exist = $block->getItems()->getSize()) {
            $type = 'related';
            $class = $type;

            $image = 'related_products_list';
            $title = __('Related Products');
            $items = $block->getItems();
            $limit = 0;
            $shuffle = 0;
            $canItemsAddToCart = $block->canItemsAddToCart();

            $showAddTo = true;
            $showCart = false;
            $templateType = null;
            $description = false;
        }
        break;

    case 'upsell-rule':
        if ($exist = $block->hasItems()) {
            $type = 'upsell';
            $class = $type;

            $image = 'upsell_products_list';
            $title = __('We found other products you might like!');
            $items = $block->getAllItems();
            $limit = $block->getPositionLimit();
            $shuffle = (int) $block->isShuffled();

            $showAddTo = false;
            $showCart = false;
            $templateType = null;
            $description = false;
            $canItemsAddToCart = false;
        }
        break;

    case 'upsell':
        /** @var MagentoCatalogBlockProductProductListUpsell $block */
        if ($exist = count($block->getItemCollection()->getItems())) {
            $type = 'upsell';
            $class = $type;

            $image = 'upsell_products_list';
            $title = __('We found other products you might like!');
            $items = $block->getItemCollection()->getItems();
            $limit = $block->getItemLimit('upsell');
            $shuffle = 0;

            $showAddTo = false;
            $showCart = false;
            $templateType = null;
            $description = false;
            $canItemsAddToCart = false;
        }
        break;

    case 'crosssell-rule':
        /** @var MagentoCatalogBlockProductProductListCrosssell $block */
        if ($exist = $block->hasItems()) {
            $type = 'crosssell';
            $class = $type;

            $image = 'cart_cross_sell_products';
            $title = __('More Choices:');
            $items = $block->getItemCollection();

            $showAddTo = true;
            $showCart = true;
            $templateType = MagentoCatalogBlockProductReviewRendererInterface::SHORT_VIEW;
            $description = false;
            $canItemsAddToCart = false;
        }
        break;

    case 'crosssell':
        /** @var MagentoCatalogBlockProductProductListCrosssell $block */
        if ($exist = count($block->getItems())) {
            $type = 'crosssell';
            $class = $type;

            $image = 'cart_cross_sell_products';
            $title = __('More Choices:');
            $items = $block->getItems();

            $showAddTo = true;
            $showCart = true;
            $templateType = MagentoCatalogBlockProductReviewRendererInterface::SHORT_VIEW;
            $description = false;
            $canItemsAddToCart = false;
        }
        break;

    case 'new':
        if ($exist = $block->getProductCollection()) {
            $type = 'new';
            $mode = 'grid';
            $type = $type . ' ' . $mode;

            $class = 'widget' . ' ' . $type;

            $image = 'new_products_content_widget_grid';
            $title = __('New Products');
            $items = $exist;

            $showAddTo = true;
            $showCart = true;
            $templateType = MagentoCatalogBlockProductReviewRendererInterface::SHORT_VIEW;
            $description = ($mode == 'list') ? true : false;
            $canItemsAddToCart = false;
        }
        break;

    default:
        $exist = null;
}
?>

<?php if ($exist) :?>

<?php if ($type == 'related' || $type == 'upsell') :?>
<?php if ($type == 'related') :?>
<div class="block <?= $block->escapeHtmlAttr($class) ?>" data-mage-init='{"relatedProducts":{"relatedCheckbox":".related.checkbox"}}' data-limit="<?= $block->escapeHtmlAttr($limit) ?>" data-shuffle="<?= /* @noEscape */ $shuffle ?>">
    <?php else :?>
    <div class="block <?= $block->escapeHtmlAttr($class) ?>" data-mage-init='{"upsellProducts":{}}' data-limit="<?= $block->escapeHtmlAttr($limit) ?>" data-shuffle="<?= /* @noEscape */ $shuffle ?>">
        <?php endif; ?>
        <?php else :?>
        <div class="block <?= $block->escapeHtmlAttr($class) ?>">
            <?php endif; ?>
            <div class="block-title title">
                <strong id="block-<?= $block->escapeHtmlAttr($class) ?>-heading" role="heading" aria-level="2"><?= $block->escapeHtml($title) ?></strong>
            </div>
            <div class="block-content content" aria-labelledby="block-<?= $block->escapeHtmlAttr($class) ?>-heading">
                <?php if ($type == 'related' && $canItemsAddToCart) :?>
                    <div class="block-actions">
                        <?= $block->escapeHtml(__('Check items to add to the cart or')) ?>
                        <button type="button" class="action select" data-role="select-all"><span><?= $block->escapeHtml(__('select all')) ?></span></button>
                    </div>
                <?php endif; ?>
                <div class="products wrapper grid products-grid products-<?= $block->escapeHtmlAttr($type) ?>">
                    <ol class="products list items product-items">
                        <?php foreach ($items as $_item) :?>
                            <?php $available = ''; ?>
                            <?php if (!$_item->isComposite() && $_item->isSaleable() && $type == 'related') :?>
                                <?php if (!$_item->getRequiredOptions()) :?>
                                    <?php $available = 'related-available'; ?>
                                <?php endif; ?>
                            <?php endif; ?>
                            <?php if ($type == 'related' || $type == 'upsell') :?>
                                <li class="item product product-item" style="display: none;">
                            <?php else :?>
                                <li class="item product product-item">
                            <?php endif; ?>
                            <div class="product-item-info <?= /* @noEscape */ $available ?>">
                                <?= /* @noEscape */ '<!-- ' . $image . '-->' ?>
                                <a href="<?= $block->escapeUrl($block->getProductUrl($_item)) ?>" class="product photo product-item-photo">
                                    <?= $block->getImage($_item, $image)->toHtml() ?>
                                </a>
                                <div class="product details product-item-details">
                                    <strong class="product name product-item-name"><a class="product-item-link" title="<?= $block->escapeHtmlAttr($_item->getName()) ?>" href="<?= $block->escapeUrl($block->getProductUrl($_item)) ?>">
                                            <?= $block->escapeHtml($_item->getName()) ?></a>
                                    </strong>

                                    <?= /* @noEscape */ $block->getProductPrice($_item) ?>

                                    <?php if ($templateType) :?>
                                        <?= $block->getReviewsSummaryHtml($_item, $templateType) ?>
                                    <?php endif; ?>

                                    <?php if ($canItemsAddToCart && !$_item->isComposite() && $_item->isSaleable() && $type == 'related') :?>
                                        <?php if (!$_item->getRequiredOptions()) :?>
                                            <div class="field choice related">
                                                <input type="checkbox" class="checkbox related" id="related-checkbox<?= $block->escapeHtmlAttr($_item->getId()) ?>" name="related_products()" value="<?= $block->escapeHtmlAttr($_item->getId()) ?>" />
                                                <label class="label" for="related-checkbox<?= $block->escapeHtmlAttr($_item->getId()) ?>"><span><?= $block->escapeHtml(__('Add to Cart')) ?></span></label>
                                            </div>
                                        <?php endif; ?>
                                    <?php endif; ?>

                                    <?php if ($showAddTo || $showCart) :?>
                                        <div class="product actions product-item-actions">
                                            <?php if ($showCart) :?>
                                                <div class="actions-primary">
                                                    <?php if ($_item->isSaleable()) :?>
                                                        <?php if ($_item->getTypeInstance()->hasRequiredOptions($_item)) :?>
                                                            <button class="action tocart primary" data-mage-init='{"redirectUrl": {"url": "<?= $block->escapeUrl($block->getAddToCartUrl($_item)) ?>"}}' type="button" title="<?= $block->escapeHtmlAttr(__('Add to Cart')) ?>">
                                                                <span><?= $block->escapeHtml(__('Add to Cart')) ?></span>
                                                            </button>
                                                        <?php else :?>
                                                            <?php $postDataHelper = $this->helper(MagentoFrameworkDataHelperPostHelper::class);
                                                            $postData = $postDataHelper->getPostData($block->escapeUrl($block->getAddToCartUrl($_item)), ('product' => $_item->getEntityId()))
                                                            ?>
                                                    <form data-role="tocart-form" data-product-id="<?= $block->escapeHtml($_item->getId()) ?>" action="<?php /* @escapeNotVerified */ echo $postParams; ?>" method="post">
                                                        <input type="hidden" name="product" value="<?php /* @escapeNotVerified */ echo $postParams; ?>">
                                                        <input type="hidden" name="<?php /* @escapeNotVerified */ echo Action::PARAM_NAME_URL_ENCODED; ?>" value="<?php /* @escapeNotVerified */ echo $postParams; ?>">
                                                        <?php echo $block->getBlockHtml('formkey')?>

                                                        <button class="action tocart primary"
                                                                    data-post='<?= /* @noEscape */ $postData ?>'
                                                                    type="button" title="<?= $block->escapeHtmlAttr(__('Add to Cart')) ?>">
                                                                <span><?= $block->escapeHtml(__('Add to Cart')) ?></span>
                                                            </button>
                                                    </form>
                                                        <?php endif; ?>
                                                    <?php else :?>
                                                        <?php if ($_item->getIsSalable()) :?>
                                                            <div class="stock available"><span><?= $block->escapeHtml(__('In stock')) ?></span></div>
                                                        <?php else :?>
                                                            <div class="stock unavailable"><span><?= $block->escapeHtml(__('Out of stock')) ?></span></div>
                                                        <?php endif; ?>
                                                    <?php endif; ?>
                                                </div>
                                            <?php endif; ?>

                                            <?php if ($showAddTo) :?>
                                                <div class="secondary-addto-links actions-secondary" data-role="add-to-links">
                                                    <?php if ($addToBlock = $block->getChildBlock('addto')) :?>
                                                        <?= $addToBlock->setProduct($_item)->getChildHtml() ?>
                                                    <?php endif; ?>
                                                </div>
                                            <?php endif; ?>
                                        </div>
                                    <?php endif; ?>
                                </div>
                            </div>
                            </li>
                        <?php endforeach ?>
                    </ol>
                </div>
            </div>
        </div>
  <script type="text/x-magento-init">
    {
        "(data-role=tocart-form), .form.map.checkout": {
            "catalogAddToCart": {
                "product_sku": "<?= /* @NoEscape */ $_item->getSku() ?>"
            }
        }
    }
  </script>
        <?php endif;?>

plugins – Disable WooCommerce cart page

I’m building a WooCommerce website. I will be selling 4 packages and will be offering some upsells in the checkout using the WooCommerce Checkout Add-Ons plugin.

Here’s what I’m trying to achieve:

1. I would like to hide the WooCommerce cart page. Make it inaccessible.

2. I would like the cart to empty itself if the user navigates away from the checkout.

I have found a plugin, called Disable cart page for WooCommerce, that almost does what I want, but not quite. This plugin hides the cart page and empties the cart before another product is added. However, it disables the ability to add multiple products to an order which means users can not add any upsells to their order at checkout. It allows users to buy only 1 product at a time.

Here’s my situation:

I have created 1 variable product with 4 different variations and allow only 1 of this product to be purchased in a single order. These are the 4 main packages of my service that I offer on the website.

I have also created a bunch of simple products. These are the upsells that customers will be able to add to their order at checkout on top of the main package that they choose.

Here’s the issue:

If the customer navigates away from the checkout with the package and all of the upsells in the cart, the cart keeps the products inside the cart. Which means the cart will not allow the customer to select a different package because a package was already chosen and added to cart.

Therefore I need the cart to empty itself if the user navigates away from the checkout so he can add a different package to cart if he wants to.

The cart page is simply unnecessary because my customers get redirected straight to checkout after adding a package to their cart. So it would be great if customers trying to reach the cart page would simply get redirected to the checkout.

Is this possible?

linear programming – Minimize total cost of shopping cart with discount rules

Here is the problem I am trying to solve, given 2 items to purchase from 2 stores with a discount for Store 1, what is the cheapest way to purchase the items?

Discount for Store 1, 50% off with minimum spend of $15 capped at $6.

Item 1 Store 1 = $5
Item 1 Store 2 = $10
Item 2 Store 1 = $10
Item 2 Store 2 = $5

The obvious answer would be to purchase both items from Store 1, at a cost of $10 + $5 - $6 = $9

Here is my formulation, which I got stuck when the discount amount is less than $6 not calculating correctly.

Item 1 Store 1 = x1 = $5
Item 1 Store 2 = x2 = $10
Item 2 Store 1 = x3 = $10
Item 2 Store 2 = x4 = $5
Min Spend Discount Binary = x6
Max Spend Discount Binary = x7

Minimize
 obj: 5 x1 + 10 x2 + 10 x3 + 5 x4 - 6 x6 
+ ( - 5 x1*x5 + 5 x1*x6 - 10 x3*x5 + 10 x3*x6 ) / 2 # apply discount and compensate amount if exceeds capped discount

Subject To
 c1: x1 + x2 = 1 // need to purchase item 1 from either store
 c2: x3 + x4 = 1 // need to purchase item 2 from either store
 c3: 5 x1 + 10 x3 - 12 x5 >= 0 // min spend for item 1 and item 2 from store 1 needs to exceed $12
 c4: x5 - x6 = 0 // this is the part that I got stuck, this works when the total cost exceeds the discount cap but doesn't work when it's below the cap

Bounds
 0 <= x1 <= 1
 0 <= x2 <= 1
 0 <= x3 <= 1
 0 <= x4 <= 1
 0 <= x5 <= 1
 0 <= x6 <= 1

Binaries
 x1 x2 x3 x4 x5 x6
End 

I’m sure I’m missing something with the fourth constraint (c4), any ideas on how this problem should be formulated?

magento2 – Limit Add to Cart Items

I want to Limit Checkout Order or Add to Cart Limit to allow only 6 types of products/items.
These 6 items can have variable Qty value.
Eg:
One Checkout/AddCart Maximum 6 Items:
Item-1 25Qty, Item-2 125Qty, Item-3 Sample, Item-4 50Qty, Item-5 100Qty, Item-6 Sample,

So for I have created an extension using Event Observer but it is not working.

code of Vendor/Module/etc/events.xml

<?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="controller_action_predispatch_checkout_cart_add">
        <observer name="limit_items_in_cart_checkout_before" instance="VendorModuleObserverCheckoutCartAdd" />
    </event>
</config>

code of Vendor/Module/Observer/Checkout/Cart/Add.php

<?php

namespace VendorModuleObserverCheckoutCart;

use MagentoCheckoutModelSession;
use MagentoFrameworkAppActionFlag;
use MagentoFrameworkAppResponseRedirectInterface as ResponseRedirect;
use MagentoFrameworkEventObserver;
use MagentoFrameworkEventObserverInterface;
use MagentoFrameworkMessageManagerInterface as MessageManager;

class Add implements ObserverInterface
{
    /** @var Session $session */
    private $session;

    /** @var ActionFlag $flag */
    private $flag;

    /** @var ResponseRedirect $redirect */
    private $redirect;

    /** @var MessageManager $messageManager */
    private $messageManager;

    /**
     * Add constructor.
     *
     * @param Session          $session
     * @param ActionFlag       $flag
     * @param ResponseRedirect $redirect
     * @param MessageManager   $messageManager
     */
    public function __construct(
        Session $session,
        ActionFlag $flag,
        ResponseRedirect $redirect,
        MessageManager $messageManager
    ) {
        $this->session         = $session;
        $this->flag            = $flag;
        $this->redirect        = $redirect;
        $this->messageManager  = $messageManager;
    }

    /**
     * @param Observer $observer
     *
     * @return $this|void
     * @throws MagentoFrameworkExceptionLocalizedException
     * @throws MagentoFrameworkExceptionNoSuchEntityException
     */
    public function execute(Observer $observer)
    {
        $quote      = $this->session->getQuote();
        $itemsCount = $quote->getItemsCount();

        if ($itemsCount > 6) {
            $request = $observer->getRequest();
            $request->setParams((
                'product'    => false,
                'return_url' => $this->redirect->getRefererUrl(),
                'backUrl'    => $this->redirect->getRefererUrl()
            ));

            $this->messageManager->addErrorMessage(
                __('Only 6 types of products per purchase allowed. Please complete this order first and place another order afterwards.')
            );

            $action = $observer->getEvent()->getControllerAction();
            $this->flag->set('', MagentoFrameworkAppActionInterface::FLAG_NO_DISPATCH, true);
            $action->getResponse()->setRedirect('/checkout/cart');

            return $this;
        }
    }
}

plugins – Force variable product to be added to cart even if variation is not selected

I just updated woocommerce. before the update , i had an custom add to cart button in single-product that works fine and add my custom variation to card when user click on the button

for example :
i have an digital product that include demo , there is default add to cart for the full version of my product and a custom button for my demo
when user click on demo the url be like :

test.com/cart/?add-to-cart=" + add_to_cart + "&variation_name=demo" + "&attribute_pa_version=demo

but now , its not working anymore. i see this line in changelog 4.7.1 :

Prevent variable product to be added to cart until a valid variation is selected first

so , what should i do ?!

9 – Unable to fix my site after Commerce Promotion was enabled (no Commerce Cart enabled)

I installed the sub module Commerce Promotion and my Drupal 9 site crashed with the following message, plus debugging code:

The website encountered an unexpected error. Please try again later.
Error: Class 'Drupalcommerce_cartEventCartEvents' not found in Drupalcommerce_promotionEventSubscriberCartEventSubscriber::getSubscribedEvents() (line 16 of /var/www/html/drupal9test/modules/contrib/commerce/modules/promotion/src/EventSubscriber/CartEventSubscriber.php).

Drupalcommerce_promotionEventSubscriberCartEventSubscriber::getSubscribedEvents() (Line: 37)
DrupalCoreDependencyInjectionCompilerRegisterEventSubscribersPass->process() (Line: 94)
SymfonyComponentDependencyInjectionCompilerCompiler->compile() (Line: 762)
SymfonyComponentDependencyInjectionContainerBuilder->compile() (Line: 1293)
DrupalCoreDrupalKernel->compileContainer() (Line: 898)
DrupalCoreDrupalKernel->initializeContainer() (Line: 471)
DrupalCoreDrupalKernel->boot() (Line: 705)
DrupalCoreDrupalKernel->handle() (Line: 19)

I was able to find in Issues for Drupal Commerce the reason of my site crash, I enabled sub module Commerce Promotion without enabling Commerce Cart sub module.

I added the commit at the end of that post but my site is not fixed. Any suggestion to bring back my site?

magento2 – Magento 2 : API Get Customer Cart Data using customer ID

I am building custom magento 2 API. I want to get customer CART DATA using CUSTOMER_ID.

I have tried following code but its not working.

$params = $this->request->getPostValue();
$customerId = $params("customer_id");
        
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$customerData = $objectManager->create('MagentoCustomerModelCustomer')->load($customerId);

//Code to get customer cart data
$quote = $this->quoteFactory->create();
$customerQuote=$this->quoteModel->loadByCustomerId($quote,$customerId); // where `$customerId` is your `customer id`
return $items = $customerQuote->getAllItems();
    

I have also tried many other sample codes but they are not working anyone can help me here.
Thanks