I making a promo on Magento 2.4.5 Like buy any specific 5 products and get 1 free. We have products having FPT on them. I want to add this FPT product to cart with 0 price and 0 FPT when someone buy 5 products.

I have achieved this promo by using this event


and using this code

$product = $this->productRepository->get($productSku);
// If the product is not in the cart, create a new item
$item = $this->quoteItemFactory->create();
$item->setQty($freeQtyToAdd); // Set the quantity

// Set the final price of the item to 0
 // Remove FPT
$item->setName('text name');
// Add the item to the cart
$quote->collectTotals(); // Recalculate totals

Product price get 0 and its adding to cart but the issue I am having is the price is 0 but its still showing FPT on this product. I want to remove PFT as well.

enter image description here

1 Answer 1


try it like this etc/di.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Quote\Model\Quote">
        <plugin name="check_six_products" type="YourVendor\YourModule\Plugin\Quote" sortOrder="1" disabled="false" />

namespace YourVendor\YourModule\Plugin;

class Quote
    public function afterAddProduct(\Magento\Quote\Model\Quote $subject, $result, $product, $info = null)
        $cartItems = $subject->getAllItems();

        // Check if all 5 previously added products have 'in_offer' flag set to 'yes'
        $inOfferProductCount = 0;
        foreach ($cartItems as $item) {
            $itemProduct = $item->getProduct();
            if ($itemProduct->getData('in_offer') === 'yes') {

        if ($inOfferProductCount >= 5) {
            // If all 5 products have 'in_offer' flag set to 'yes', find the 6th product and remove its FPT
            foreach ($cartItems as $item) {
                $itemProduct = $item->getProduct();
                if ($itemProduct->getData('in_offer') === 'yes' && $item->getSku() === $product->getSku()) {

        return $result;

you can modify the code accordingly

i have not tested this code, but do let me know if it works.

  • I already did the 0 price part i have issue with remove FPT. FPT is not removing tried many things
    – OBAID
    Nov 6, 2023 at 15:12
  • check updated ans
    – Pramod
    Nov 6, 2023 at 15:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.