'How to Set Special Price in Laravel?

I have product data in cart like this.

{
    "data": [
        {
            "seller_id": 1,
            "seller_name": "DStore",
            "products": [
                {
                    "id": 113,
                    "item_id": 61,
                    "name": "Kecap BCA",
                    "stock": 2344,
                    "weight": 200,
                    "quantity": 1,
                    "price": 2000,
                    "disc": null,
                    "promo": null,
                    "final_price": 2000
                },
                {
                    "id": 43,
                    "item_id": 60,
                    "name": "Kembang Goyang",
                    "stock": 4,
                    "weight": 200,
                    "quantity": 1,
                    "price": 13000,
                    "disc": null,
                    "promo": null,
                    "final_price": 13000
                },
                {
                    "id": 1,
                    "item_id": 64,
                    "name": "Sabrina - Tahu Tuna",
                    "stock": 2993,
                    "weight": 50,
                    "quantity": 2,
                    "price": 7500,
                    "disc": 16,
                    "promo": 6300,
                    "final_price": 12600
                }
            ]
        }
    ],
    "message": "Success",
    "status": "200"
}

And I have special price data if the quantity of the product in the cart has exceeded the quantity of the product at the special price that has been set.

{
    "data": [
        {
            "product_id": 113,
            "from": 10, //min qty
            "to": 20, //max qty
            "price": 1800
        },
        {
            "product_id": 113,
            "from": 21, //min qty
            "to": 30, //max qty
            "price": 1500
        }
    ],
    "message": "Success",
    "status": "200"
}

How to check it and change the total price in the cart automatically? I'm still confused with the logic or schematic how to check it. Thanks



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source