Skip to content

Commit

Permalink
trace cart更改
Browse files Browse the repository at this point in the history
  • Loading branch information
fancyecommerce committed May 7, 2018
1 parent d9b594e commit 12ffab3
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions services/cart/QuoteItem.php
Expand Up @@ -87,28 +87,31 @@ public function addItem($item)
// 重新计算购物车的数量,并写入sales_flat_cart表存储
Yii::$service->cart->quote->computeCartInfo();
}
$his->sendTraceAddToCartInfoByApi($item);

$item['afterAddQty'] = $item_one->qty;
$this->sendTraceAddToCartInfoByApi($item);

}
/**
* @property $item | Array, example:
* $item = [
* 'product_id' => 22222,
* 'custom_option_sku' => red-xxl,
* 'qty' => 22,
* 'qty' => 22, // 添加购物车的产品个数
* 'sku' => 'xxxx',
* 'afterAddQty' => 33, // 添加后,该产品在sku中的个数,这个个数是为了计算购物车中产品的价格
* ];
* 将加入购物车的操作,加入trace
*/
public function sendTraceAddToCartInfoByApi($item){
if (Yii::$service->page->trace->traceJsEnable) {
$product_price_arr = Yii::$service->product->price->getCartPriceByProductId($item['product_id'], $item['qty'], $item['custom_option_sku'], 2);
$product_price_arr = Yii::$service->product->price->getCartPriceByProductId($item['product_id'], $item['afterAddQty'], $item['custom_option_sku'], 2);
$base_product_price = isset($product_price_arr['base_price']) ? $product_price_arr['base_price'] : 0;
$price = $base_product_price * $item['qty'];
// $price = $base_product_price * $item['qty'];
$trace_cart_info = [
[
'sku' => $item['sku'],
'price' => $price,
'price' => $base_product_price,
'qty' => $item['qty'],
]
];
Expand Down Expand Up @@ -328,9 +331,10 @@ public function addOneItem($item_id)
'custom_option_sku' => $one['custom_option_sku'],
'qty' => $changeQty,
'sku' => $product['sku'],
'afterAddQty' => $one['qty'],
];
// 购物车数据加1
$his->sendTraceAddToCartInfoByApi($item);
$this->sendTraceAddToCartInfoByApi($item);
return true;
}
}
Expand Down

0 comments on commit 12ffab3

Please sign in to comment.