0
私はショッピングカートを持っており、オファー機能を構築する必要があります。すでにパーセンテージを完了しており、数量プロモーションに何らかの助けが必要です。「3を買って2を支払う」という計算方法を教えてください。
たとえば、顧客が3つのアイテムを購入した場合、2つしか支払うことはできませんが、5つのアイテムを購入する場合は、3つのアイテムのみをプロモーションに適用する必要があり、2つは満額です。
ここで、それは私のコード
$quand_in_cart = '5'; //quantity for product X in the cart
$prod_price = '1.5'; //product price
$percentage_off = NULL;
$buy_any = 3; //promotion on 3 items
$for_the_price = 2; //pay only 2
if($percentage_off and $quand_in_cart >= $buy_any){
$price_discount = ($percentage_off/100) * $quand_in_cart; //works percentage done.
} elseif ($buy_any && $for_the_price) {
if($quand_in_cart >= $buy_any){
//here i need some help
}
}
最初に最も多い数量チェックから始めてください。 'if(quantity> = 5){} else if(quantity> = 3)... ' – aynber
' $ fullPrice = $ quand_in_cart%$ buy_any; $ discounted = $ quand_in_cart - $ fullPrice; ' –