我想将购物车的foreach存储在模型中的某个位置,并在许多控制器功能中进行检索,所以这是可能的
public function deleteProducts($rowId)
{
Cart::remove($rowId);
$products = Cart::content();
//Here what I want to retrive without writing this code many times
foreach($products as $Product){
echo '<div class="OrderItem_root styles_base styles_spacing-base">
<div class="OrderItem_quantity styles_just-right styles_base styles_spacing-base">'.$Product->qty.'</div>
<div class="OrderItem_container">
<div class="OrderItem_category"></div>
<div class="OrderItem_itemHeader">
<div id="titletest" class="OrderItem_name styles_just-right styles_base styles_spacing-base">'.$Product->name.'</div>
<div id="cartprice" class="OrderItem_total">$'.$Product->price*$Product->qty.'</div>
<input id="mycartprice" type="text" name="mycartprice" value="'.$Product->price.'" hidden="">
</div>
<div>
</div>
<div>
<input id="mycart" type="text" name="mycartprice" value="'.Cart::subtotal().'" hidden="">
<button class="remove_item OrderItem_action Button_root" data-id="'.$Product->rowId.'" data-price="'.$Product->price*$Product->qty.'" data-qty="'.$Product->qty.'" type="submit">Remove</button>
</div>
</div>
</div>';
}
}
答案 0 :(得分:0)
使用您产品模型的函数(例如,调用函数 showOrder )而不是您的控制器返回html,那么您可以这样做
'a':3
'b':1
'a':3
'a':3