Ich habe einen Einkaufswagen und ich muss die Angebotsfunktion erstellen, ich habe bereits den Prozentsatz aus und ich brauche etwas Hilfe mit Mengenpromotionen.Wie mache ich "Buy 3 und Pay 2" Mathe?
Zum Beispiel, wenn der Kunde 3 Artikel kauft, zahlt er nur für 2, aber wenn er 5 Artikel kaufen möchte, muss ich für die Förderung nur für 3 Artikel bewerben und 2 sind zum vollen Preis.
Hier ist es mein Code
$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
}
}
Beginnen Sie mit der höchsten Mengenprüfung zuerst: 'if (Menge> = 5) {} sonst if (Menge> = 3) ...' – aynber
'$ fullPrice = $ quand_in_cart% $ buy_any; $ diskontiert = $ quand_in_cart - $ fullPrice; ' –