朋友们,我有这个方法来检查购物车中是否已经存在该产品。同样,他补充说,如果产品存在,则更改数量,但他也让产品再次发送。
.
.
$order = $this->Orders->newEntity();
if ( $this->request->is( 'post' ) ) {
$order = $this->Orders->patchEntity( $order, $this->request->getData() );
$order->order = $this->Orders->Products->get( $order->product_id, ['contain' => ['Users']] );
$session = $this->request->getSession();
$cart = $session->read( 'cart' );
$counter = 0;
foreach((array) $cart as $cartOne){
if($cartOne['product_id'] == $order->product_id){
$cartOne['quantity'] += 1;
$counter++;
break;
}
}
$cart[] = $order;
$session->write('cart', $cart);
如果有人能分析一下我将不胜感激!我真的无法制作这个过滤器。
繁星coding