Skip to content

Commit

Permalink
最小购买个数,在购物没有限制的bug
Browse files Browse the repository at this point in the history
  • Loading branch information
fancyecommerce committed Nov 19, 2017
1 parent 72be603 commit 69aed0a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Expand Up @@ -208,6 +208,7 @@ public function actionUpdateinfo()
} else {
echo json_encode([
'status' => 'fail',
'content' => Yii::$service->helper->errors->get(',')
]);
$innerTransaction->rollBack();
}
Expand Down
12 changes: 11 additions & 1 deletion services/cart/QuoteItem.php
Expand Up @@ -284,9 +284,19 @@ public function lessOneItem($item_id)
'cart_id' => $cart_id,
'item_id' => $item_id,
])->one();
$lessedQty = $one['qty'] - 1;

$product = Yii::$service->product->getByPrimaryKey($one['product_id']);
if(isset($product['min_sales_qty']) && $product['min_sales_qty'] > 1){
if($lessedQty < $product['min_sales_qty']){
Yii::$service->helper->errors->add('product less buy qty is '.$product['min_sales_qty']);

return false;
}
}
if ($one['item_id']) {
if ($one['qty'] > 1) {
$one['qty'] = $one['qty'] - 1;
$one['qty'] = $lessedQty;
$one->save();
// 重新计算购物车的数量
Yii::$service->cart->quote->computeCartInfo();
Expand Down

0 comments on commit 69aed0a

Please sign in to comment.