提交 41dde25c 编写于 作者: R root

产品加入购物车,失败后的报错反馈部分

上级 d7d872de
......@@ -52,6 +52,14 @@ class CartController extends AppfrontController
'items_count' => Yii::$service->cart->quote->getCartItemsCount(),
]);
exit;
}else{
$errors = Yii::$service->helper->errors->get(',');
echo json_encode([
'status' => 'fail',
'content'=> $errors,
//'items_count' => Yii::$service->cart->quote->getCartItemsCount(),
]);
exit;
}
}
}
......
......@@ -242,7 +242,9 @@
$("#js_cart_items").html(items_count);
window.location.href="<?= Yii::$service->url->getUrl("checkout/cart") ?>";
}else{
alert('add to cart fail');
content = data.content;
$(".addProductToCart").removeClass("dataUp");
alert(content);
}
},
......
......@@ -51,7 +51,7 @@ class Info extends Service
# 验证:1.上架状态, 2.库存个数是否大于购买个数
# 该验证方式是默认验证方式
if(!Yii::$service->product->stock->productIsInStock($product,$qty ,$custom_option_sku)){
Yii::$service->helper->errors->add('product is Stock Out');
Yii::$service->helper->errors->add('the qty of product stocks is less than your purchase qty');
return false;
}
......@@ -63,9 +63,7 @@ class Info extends Service
return false;
}
}
# 验证产品是否
# 验证产品是否是激活状态
if($product['status'] != 1){
Yii::$service->helper->errors->add('product is not active');
return false;
......
......@@ -29,12 +29,21 @@ class Errors extends Service
}
}
public function get($arrayFormat=false){
/**
* @property $separator 如果是false,则返回数组,
* 如果是true则返回用| 分隔的字符串
* 如果是传递的分隔符的值,譬如“,”,则返回用这个分隔符分隔的字符串
*
*/
public function get($separator=false){
if($this->_errors){
$errors = $this->_errors;
$this->_errors = false;
if(!$arrayFormat){
return implode('|',$errors);
if(!$separator){
if($separator === true){
$separator = '|';
}
return implode($separator,$errors);
}else{
return $errors;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册