저는 shopping cart
->orders
->products
의 3 가지 클래스가 있습니다.php에서 쇼핑 카트에 상품을 넣는 데 문제가 있습니다.
먼저 두 번째 제품을 추가 할 때 orders
개체의 배열 products
에있는 다른 제품과 비교합니다. 내가 비교를 완료하면
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++;
}
}
}
, 나는 다음을 추가해야합니다 : if count($product)==0
다음, 전나무 제품 경우 count>0
을 추가, 내가 추가 할 새로운 제품과 함께 배열의 제품의 id's 비교 새 제품이지만 작동하지 않습니다. 내 실수는 무엇입니까?
는 "작동하지 않는"정의 0 요소에 대한 어떤 검사의 필요성에 대해 말씀. 오류가 있습니까? – ceejayoz