我有這3個類:shopping cart
- >orders
- >products
。在購物車中添加產品的PHP中的問題
首先我添加一個產品,當我添加第二個產品時,我將與products
中對象orders
中的其他產品進行比較。 if count($product)==0
,然後添加杉杉產品 如果count>0
,我比較產品的id's新產品陣列中的我要補充:
public function setProduct($product,$new_quantity){
if($this->num_product == 0) {
$this->product[$this->num_product]=$product;
$this->num_product++;
} else if($this->num_product > 0) {
for($i=0; $i < $this->num_product; $i++) {
if($this->product[$i]->getIdproduct() == $product->getIdproduct()) {
$this->product[$i]->setQuantity($this->product[$i]->getquantity()+$new_quantity);
break;
} else {
continue;
}
$this->product[$this->num_product]=$product;
$this->num_product++;
}
}
}
當我完成的比較,我一定要添加這些新產品,但這不起作用。我的錯誤是什麼?
定義「不工作」的需要沒有檢查。你有錯誤嗎? – ceejayoz