提交 9b561cb5 编写于 作者: T Terry

service 添加注释

上级 bc6a5016
......@@ -58,7 +58,7 @@ class CartController extends AppfrontController
if ($addToCart) {
echo json_encode([
'status' => 'success',
'items_count' => Yii::$service->cart->quote->getCartItemsCount(),
'items_count' => Yii::$service->cart->quote->getCartItemCount(),
]);
$innerTransaction->commit();
exit;
......@@ -67,7 +67,7 @@ class CartController extends AppfrontController
echo json_encode([
'status' => 'fail',
'content'=> $errors,
//'items_count' => Yii::$service->cart->quote->getCartItemsCount(),
//'items_count' => Yii::$service->cart->quote->getCartItemCount(),
]);
$innerTransaction->rollBack();
exit;
......
......@@ -58,7 +58,7 @@ class CartController extends AppfrontController
if ($addToCart) {
echo json_encode([
'status' => 'success',
'items_count' => Yii::$service->cart->quote->getCartItemsCount(),
'items_count' => Yii::$service->cart->quote->getCartItemCount(),
]);
$innerTransaction->commit();
exit;
......@@ -67,7 +67,7 @@ class CartController extends AppfrontController
echo json_encode([
'status' => 'fail',
'content'=> $errors,
//'items_count' => Yii::$service->cart->quote->getCartItemsCount(),
//'items_count' => Yii::$service->cart->quote->getCartItemCount(),
]);
$innerTransaction->rollBack();
exit;
......
......@@ -12,7 +12,7 @@ namespace fecshop\services;
use Yii;
/**
* AdminUser services.
* AdminUser services. 用来给后台的用户提供数据。
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
......
......@@ -13,6 +13,8 @@ use Yii;
use yii\base\InvalidConfigException;
/**
* 此对象就是Yii::$service,通过魔术方法__get , 得到服务对象,服务对象是单例模式。
* 对于fecshop服务的介绍,可以参看文档:http://www.fecshop.com/doc/fecshop-guide/develop/cn-1.0/guide-fecshop-service-abc.html
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
......@@ -20,7 +22,12 @@ class Application
{
public $childService;
public $_childService;
/**
* @property $config | Array 注入的配置数组
* 在@app/web/index.php 入口文件处。会调用 new fecshop\services\Application($config['services']);
* Yii::$service 就是该类实例化的对象,注入的配置保存到 $this->childService 中
*/
public function __construct($config = [])
{
Yii::$service = $this;
......@@ -29,6 +36,7 @@ class Application
/**
* 得到services 里面配置的子服务childService的实例.
* 单例模式,懒加载,使用的时候才会被实例化。类似于Yii2的component原理。
*/
public function getChildService($childServiceName)
{
......@@ -44,7 +52,11 @@ class Application
return $this->_childService[$childServiceName];
}
/**
* @property $attr | String , service的name。
* 魔术方法,当调用一个属性,对象不存在的时候就会执行该方法,然后
* 根据构造方法注入的配置,实例化service对象。
*/
public function __get($attr)
{
return $this->getChildService($attr);
......
......@@ -10,7 +10,7 @@
namespace fecshop\services;
/**
* Blog.
* Blog. 博客部分功能,未做。
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
......
......@@ -10,7 +10,11 @@
namespace fecshop\services;
/**
* Cart services.
* Cart services. 此部分是缓存配置的读取,各个页面譬如首页,产品,分类页面
* 调用这里的方法读取具体配置,然后来决定缓存的开启和过期时间。
* 整页缓存的具体使用,还是在相应的controller中,譬如 @appfront/modules/Catalog/controllers/CategoryController.php 中 behaviors() 方法中的使用,Yii2是通过行为的方式做绑定的。
* 对于Yii2全页缓存在controller中的使用,可以参看文档:http://www.yiichina.com/doc/guide/2.0/caching-page
* 对于fecshop缓存的使用,可以参看文档:http://www.fecshop.com/doc/fecshop-guide/instructions/cn-1.0/guide-fecshop_cache.html
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
......@@ -24,6 +28,7 @@ class Cache extends Service
/**
* @property $cacheKey | String , 具体的缓存名字,譬如 product category
* @return boolean, 如果enable为true,则返回为true
* 根据传递的$cacheKey,从配置中读取是否开启cache
*/
public function isEnable($cacheKey)
{
......@@ -37,6 +42,7 @@ class Cache extends Service
/**
* @property $cacheKey | String , 具体的缓存名字,譬如 product category
* @return int, 如果enable为true,则返回为true
* 得到$cacheKey 对应的超时时间
*/
public function timeout($cacheKey)
{
......
......@@ -12,7 +12,7 @@ namespace fecshop\services;
use Yii;
/**
* Cart services.
* Cart services. 购物车service, 执行购物车部分对应的方法。
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
......@@ -53,13 +53,19 @@ class Cart extends Service
// service 里面不允许有事务,请在调用层使用事务。
$beforeEventName = 'event_add_to_cart_before';
$afterEventName = 'event_add_to_cart_after';
/**
* 此处属于fecshop自造的简单事件event,比较简洁
* 详情参看:http://www.fecshop.com/doc/fecshop-guide/instructions/cn-1.0/guide-fecshop_event.html
*/
Yii::$service->event->trigger($beforeEventName, $item); // 触发事件 - 加购物车前事件
Yii::$service->cart->quoteItem->addItem($item);
Yii::$service->event->trigger($afterEventName, $item); // 触发事件 - 加购物车事件
Yii::$service->event->trigger($afterEventName, $item); // 触发事件 - 加购物车事件
return true;
}
// 得到购物车中产品的个数
/**
* 得到购物车中产品的个数,详情参看调用的函数注释
*/
protected function actionGetCartItemQty()
{
return Yii::$service->cart->quote->getCartItemCount();
......@@ -69,7 +75,7 @@ class Cart extends Service
* @property $shipping_method | String 货运方式code
* @property $country | String 国家code
* @property $region | String 省市code
* 得到购物车中的信息。
* 得到购物车中的信息。详情参看调用的函数注释
*/
protected function actionGetCartInfo($shipping_method = '', $country = '', $region = '*')
{
......@@ -121,8 +127,9 @@ class Cart extends Service
}
/**
* 购物车合并:用户未登录账号,把一部分产品加入购物车,当用户
* 登录账号的时候,账号对应的购物车信息和用户未登录前的购物车产品信息进行合并的操作
* 购物车合并:对应的是用户登录前后购物车的合并
* 1. 用户未登录账号,把一部分产品加入购物车
* 2. 当用户登录账号的时候,账号对应的购物车信息和用户未登录前的购物车产品信息进行合并的操作
* 在用户登录账户的时候,会执行该方法。
*/
protected function actionMergeCartAfterUserLogin()
......@@ -134,7 +141,9 @@ class Cart extends Service
* @property $address|array
* @property $shipping_method | String 发货方式
* @property $payment_method | String 支付方式
* save cart address.like,, customer name,tel,email,address ,,etc,,.
* 此函数对应的是保存游客用户的购物车数据。
* 保存购物车中的货运地址保存购物车中的货运地址(姓名,电话,邮编,地址等),货运方式,支付方式等信息。
* 详细参看相应函数
*/
protected function actionUpdateGuestCart($address, $shipping_method, $payment_method)
{
......@@ -144,7 +153,7 @@ class Cart extends Service
* @property $address_id | Int
* @property $shipping_method | String 货运方式
* @property $payment_method | String 支付方式
* 更新登录用户的购物车
* 此函数对应的是登录用户的购物车数据的更新
*/
protected function actionUpdateLoginCart($address_id, $shipping_method, $payment_method)
{
......@@ -176,16 +185,16 @@ class Cart extends Service
}
/**
* 完全与当前购物车脱节,如果产品添加购物车,会创建新的cart_id
* 完全与当前购物车脱节,执行该函数后,如果产品添加购物车,会创建新的cart_id
* 目前仅仅在登录用户退出账号的时候使用。
* 该操作仅仅remove掉session保存的cart_id。
* 该操作仅仅remove掉session保存的cart_id,并没有删除购物车的数据
*/
protected function actionClearCart()
{
Yii::$service->cart->quote->clearCart();
}
/**
/** 该函数被遗弃
* add cart items by pending order Id
* 1. check if the order is exist ,and belong to current customer.
* 2. get all item sku and custom option.
......
......@@ -14,7 +14,7 @@ use fecshop\services\category\CategoryMysqldb;
use Yii;
/**
* Category Service is the component that you can get category info from it.
* Category Service 分类service
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
......
......@@ -14,7 +14,7 @@ use fecshop\services\Service;
use Yii;
/**
* Cart services.
* Cart services. 对购物车操作的具体实现部分。
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
......@@ -31,7 +31,9 @@ class Quote extends Service
/**
* @return int 得到cart_id
* Cart的session的超时时间由session组件决定。
* Cart的session的超时时间由session组件决定。
* 在执行$this->CreateCart $this->mergeCartAfterUserLogin,都会执行 $this->setCartId,执行 Yii::$app->session->set(self::SESSION_CART_ID,'xxxx'); 给其赋值。
* 当新用户没有任何购物车操作,则返回为空值。
*/
public function getCartId()
{
......@@ -44,7 +46,7 @@ class Quote extends Service
}
/**
* @property $address|array 地址信息数组
* @property $address|array 地址信息数组,详细参看下面函数显示的字段。
* @property $shipping_method | String 货运方式
* @property $payment_method | String 支付方式
* @property bool
......@@ -54,19 +56,19 @@ class Quote extends Service
{
$cart = $this->getCurrentCart();
if ($cart) {
$cart->customer_firstname = $address['first_name'];
$cart->customer_lastname = $address['last_name'];
$cart->customer_email = $address['email'];
$cart->customer_telephone = $address['telephone'];
$cart->customer_firstname = $address['first_name'];
$cart->customer_lastname = $address['last_name'];
$cart->customer_email = $address['email'];
$cart->customer_telephone = $address['telephone'];
$cart->customer_address_street1 = $address['street1'];
$cart->customer_address_street2 = $address['street2'];
$cart->customer_address_country = $address['country'];
$cart->customer_address_city = $address['city'];
$cart->customer_address_state = $address['state'];
$cart->customer_address_zip = $address['zip'];
$cart->customer_address_city = $address['city'];
$cart->customer_address_state = $address['state'];
$cart->customer_address_zip = $address['zip'];
$cart->shipping_method = $shipping_method;
$cart->payment_method = $payment_method;
$cart->shipping_method = $shipping_method;
$cart->payment_method = $payment_method;
return $cart->save();
}
......@@ -87,9 +89,9 @@ class Quote extends Service
{
$cart = $this->getCurrentCart();
if ($cart && $address_id) {
$cart->customer_address_id = $address_id;
$cart->shipping_method = $shipping_method;
$cart->payment_method = $payment_method;
$cart->customer_address_id = $address_id;
$cart->shipping_method = $shipping_method;
$cart->payment_method = $payment_method;
return $cart->save();
}
......@@ -97,8 +99,8 @@ class Quote extends Service
/**
* @return object
* 得到当前的cart,如果当前的cart不存在,
* 则返回为空(注意,这个就是 getCurrentCart() 和 getCart()两个函数的区别)
* 得到当前的cart,如果当前的cart不存在,则返回为空
* 注意:这是getCurrentCart() 和 getCart()两个函数的区别,getCart()函数在没有cart_id的时候会创建cart。
*/
public function getCurrentCart()
{
......@@ -150,15 +152,19 @@ class Quote extends Service
}
/**
* 得到购物车中产品的个数。头部的ajax请求一般访问这个.
* @return $items_count | Int , 得到购物车中产品的个数。头部的ajax请求一般访问这个.
* 目前是通过表查询获取的。
*/
public function getCartItemCount()
{
$items_count = 0;
if ($cart_id = $this->getCartId()) {
$one = MyCart::findOne(['cart_id' => $cart_id]);
if ($one['items_count']) {
$items_count = $one['items_count'];
if($cart_id ){
$cart = $this->getCart();
//$one = MyCart::findOne(['cart_id' => $cart_id]);
if (isset($cart['items_count']) && $cart['items_count']) {
$items_count = $cart['items_count'];
}
}
}
......@@ -166,10 +172,10 @@ class Quote extends Service
}
/**
* @property $item_qty | Int ,当$item_qty 不等于null时,代表
* 已经知道购物车中产品的个数,不需要去cart_item表中查询
* 譬如清空购物车操作,直接就知道产品个数肯定为零。
* 当购物车的产品变动后,更新cart表的产品总数
* @property $item_qty | Int
* 当$item_qty为null时,从cart items表中查询产品总数
* 当$item_qty 不等于null时,代表已经知道购物车中产品的个数,不需要去cart_item表中查询,譬如清空购物车操作,直接就知道产品个数肯定为零。
* 当购物车的产品变动后,会调用该函数,更新cart表的产品总数
*/
public function computeCartInfo($item_qty = null)
{
......@@ -183,33 +189,6 @@ class Quote extends Service
return true;
}
/**
* 得到购物车中 产品的总数.
*/
public function getCartItemsCount()
{
$cart = $this->getCart();
return $cart->items_count;
}
/**
* 返回当前的购物车Db对象
*/
/*
public function getMyCart(){
if(!$this->_my_cart){
if($cart_id = $this->getCartId()){
if(!$this->_my_cart){
$this->_my_cart = MyCart::findOne(['cart_id'=>$cart_id]);
}
}else{
$this->createCart();
}
}
return $this->_my_cart;
}
*/
/**
* @property $cart_id | int
......@@ -242,70 +221,34 @@ class Quote extends Service
$myCart->created_at = time();
$myCart->updated_at = time();
if (!Yii::$app->user->isGuest) {
$identity = Yii::$app->user->identity;
$id = $identity['id'];
$firstname = $identity['firstname'];
$lastname = $identity['lastname'];
$email = $identity['email'];
$myCart->customer_id = $id;
$myCart->customer_email = $email;
$identity = Yii::$app->user->identity;
$id = $identity['id'];
$firstname = $identity['firstname'];
$lastname = $identity['lastname'];
$email = $identity['email'];
$myCart->customer_id = $id;
$myCart->customer_email = $email;
$myCart->customer_firstname = $firstname;
$myCart->customer_lastname = $lastname;
$myCart->customer_is_guest = 2;
$myCart->customer_lastname = $lastname;
$myCart->customer_is_guest = 2;
} else {
$myCart->customer_is_guest = 1;
$myCart->customer_is_guest = 1;
}
$myCart->remote_ip = \fec\helpers\CFunc::get_real_ip();
$myCart->app_name = Yii::$service->helper->getAppName();
$myCart->remote_ip = \fec\helpers\CFunc::get_real_ip();
$myCart->app_name = Yii::$service->helper->getAppName();
if ($defaultShippingMethod = Yii::$service->shipping->getDefaultShippingMethod()) {
$myCart->shipping_method = $defaultShippingMethod;
}
$myCart->save();
$cart_id = Yii::$app->db->getLastInsertId();
$cart_id = $myCart['cart_id'];
$this->setCartId($cart_id);
$this->setCart(MyCart::findOne($cart_id));
}
/*
public function addCustomerDefautAddressToCart(){
if(!Yii::$app->user->isGuest){
$cart = $this->getCart();
# 购物车没有customer address id,则
# 使用登录用户的默认address
$identity = Yii::$app->user->identity;
//echo $cart['customer_id'] ;
//echo "##";
//echo $identity['id'];
//exit;
if($cart['customer_id'] == $identity['id']){
if(!isset($cart['customer_address_id']) || empty($cart['customer_address_id'])){
$defaultAddress = Yii::$service->customer->address->getDefaultAddress();
if(is_array($defaultAddress) && !empty($defaultAddress)){
$cart->customer_telephone = isset($defaultAddress['telephone']) ? $defaultAddress['telephone'] : '';
$cart->customer_email= isset($defaultAddress['email']) ? $defaultAddress['email'] : '';
$cart->customer_firstname= isset($defaultAddress['first_name']) ? $defaultAddress['first_name'] : '';
$cart->customer_lastname= isset($defaultAddress['last_name']) ? $defaultAddress['last_name'] : '';
$cart->customer_address_id= isset($defaultAddress['address_id']) ? $defaultAddress['address_id'] : '';
$cart->customer_address_country= isset($defaultAddress['country']) ? $defaultAddress['country'] : '';
$cart->customer_address_state= isset($defaultAddress['state']) ? $defaultAddress['state'] : '';
$cart->customer_address_city= isset($defaultAddress['city']) ? $defaultAddress['city'] : '';
$cart->customer_address_zip= isset($defaultAddress['zip']) ? $defaultAddress['zip'] : '';
$cart->customer_address_street1= isset($defaultAddress['street1']) ? $defaultAddress['street1'] : '';
$cart->customer_address_street2= isset($defaultAddress['street2']) ? $defaultAddress['street2'] : '';
$cart->save();
$this->setCart($cart);
}
}
}
}
}
*/
/**
/** 该函数已经废弃
* 购物车数据中是否含有address_id,address_id,是登录用户才会有的。
*/
/*
public function hasAddressId()
{
$cart = $this->getCart();
......@@ -314,10 +257,12 @@ class Quote extends Service
return true;
}
}
*/
/**
* 得到购物车中的用户地址信息.
*/
/** 该函数已经废弃
public function getCartAddress()
{
$email = '';
......@@ -359,20 +304,21 @@ class Quote extends Service
];
}
*/
/**
* @property $shipping_method | String 传递的货运方式
* @property $country | String 货运国家
* @property $region | String 省市
* @return bool OR array ,如果存在问题返回false
* 如果没有问题,返回购物车的信息。
* @return bool OR array ,如果存在问题返回false,对于返回的数组的格式参看下面$this->cartInfo[$cartInfoKey] 部分的数组。
* 返回当前购物车的信息。包括购物车对应的产品信息。
* 对于可选参数,如果不填写,就是返回当前的购物车的数据。
* 对于填写了参数,返回的是填写参数后的数据,这个一般是用户选择了了货运方式,国家等,然后
* 实时的计算出来数据反馈给用户,但是,用户选择的数据并没有进入cart表
*/
public function getCartInfo($shipping_method = '', $country = '', $region = '*')
{
//echo 333;exit;
// 根据传递的参数的不同,购物车数据计算一次后,第二次调用,不会重新计算数据。
$cartInfoKey = $shipping_method.'-shipping-'.$country.'-country-'.$region.'-region';
if (!isset($this->cartInfo[$cartInfoKey])) {
$cart_id = $this->getCartId();
......@@ -406,10 +352,6 @@ class Quote extends Service
$currShippingCost = $shippingCost['currCost'];
$baseShippingCost = $shippingCost['baseCost'];
}
//echo 333;
//var_dump([$base_product_total,$product_total]);
//exit;
//echo $coupon_code;exit;
$couponCost = $this->getCouponCost($base_product_total, $coupon_code);
$baseDiscountCost = $couponCost['baseCost'];
......@@ -419,23 +361,23 @@ class Quote extends Service
$base_grand_total = $base_product_total + $baseShippingCost - $baseDiscountCost;
$this->cartInfo[$cartInfoKey] = [
'store' => $cart['store'], // store nme
'items_count' => $cart['items_count'], // 购物车中的产品总数
'coupon_code' => $coupon_code, // coupon卷码
'shipping_method' => $shipping_method,
'store' => $cart['store'], // store nme
'items_count' => $cart['items_count'], // 购物车中的产品总数
'coupon_code' => $coupon_code, // coupon卷码
'shipping_method' => $shipping_method,
'payment_method' => $cart['payment_method'],
'grand_total' => $curr_grand_total, // 当前货币总金额
'shipping_cost' => $currShippingCost, // 当前货币,运费
'coupon_cost' => $currDiscountCost, // 当前货币,优惠券优惠金额
'product_total' => $product_total, // 当前货币,购物车中产品的总金额
'base_grand_total' => $base_grand_total, // 基础货币总金额
'base_shipping_cost' => $baseShippingCost, // 基础货币,运费
'base_coupon_cost' => $baseDiscountCost, // 基础货币,优惠券优惠金额
'base_product_total' => $base_product_total, // 基础货币,购物车中产品的总金额
'products' => $products, //产品信息。
'product_weight'=> $product_weight, //产品的总重量。
'grand_total' => $curr_grand_total, // 当前货币总金额
'shipping_cost' => $currShippingCost, // 当前货币,运费
'coupon_cost' => $currDiscountCost, // 当前货币,优惠券优惠金额
'product_total' => $product_total, // 当前货币,购物车中产品的总金额
'base_grand_total' => $base_grand_total, // 基础货币总金额
'base_shipping_cost'=> $baseShippingCost, // 基础货币,运费
'base_coupon_cost' => $baseDiscountCost, // 基础货币,优惠券优惠金额
'base_product_total'=> $base_product_total, // 基础货币,购物车中产品的总金额
'products' => $products, //产品信息。
'product_weight' => $product_weight, //产品的总重量。
];
}
}
......@@ -448,9 +390,9 @@ class Quote extends Service
* @property $shippingCost | Array ,example:
* [
* 'currCost' => 33.22, #当前货币的运费金额
* 'baseCost' => 26.44, #基础货币的运费金额
* 'baseCost' => 26.44, #基础货币的运费金额
* ];
* 设置快递运费金额。
* 设置快递运费金额。根据国家地址和产品重量等信息计算出来的运费
*/
public function setShippingCost($shippingCost)
{
......@@ -475,12 +417,8 @@ class Quote extends Service
$region = '*';
}
if (!$this->_shipping_cost) {
//echo "$shipping_method,$weight,$country,$region";
$shippingCost = Yii::$service->shipping->getShippingCost($shipping_method, $weight, $country, $region);
$this->_shipping_cost = $shippingCost;
//if(isset($shippingCost['currentCost'])){
// $this->_shipping_cost = $shippingCost['currentCost'];
//}
}
return $this->_shipping_cost;
......@@ -496,11 +434,7 @@ class Quote extends Service
*/
public function getCouponCost($base_product_total, $coupon_code)
{
//echo '###'; var_dump($product_total);exit;
//list($base_product_total,$product_total) = $product_total;
//$dc_price = Yii::$service->page->currency->getBaseCurrencyPrice($product_total);
$dc_discount = Yii::$service->cart->coupon->getDiscount($coupon_code, $base_product_total);
//var_dump($dc_discount);exit;
return $dc_discount;
}
......@@ -537,22 +471,22 @@ class Quote extends Service
public function mergeCartAfterUserLogin()
{
if (!Yii::$app->user->isGuest) {
$identity = Yii::$app->user->identity;
$customer_id = $identity['id'];
$email = $identity->email;
$identity = Yii::$app->user->identity;
$customer_id = $identity['id'];
$email = $identity->email;
$customer_firstname = $identity->firstname;
$customer_lastname = $identity->lastname;
$customer_cart = $this->getCartByCustomerId($customer_id);
$cart_id = $this->getCartId();
$customer_lastname = $identity->lastname;
$customer_cart = $this->getCartByCustomerId($customer_id);
$cart_id = $this->getCartId();
if (!$customer_cart) {
if ($cart_id) {
$cart = $this->getCart();
if ($cart) {
$cart['customer_email'] = $email;
$cart['customer_id'] = $customer_id;
$cart['customer_email'] = $email;
$cart['customer_id'] = $customer_id;
$cart['customer_firstname'] = $customer_firstname;
$cart['customer_lastname'] = $customer_lastname;
$cart['customer_is_guest'] = 2;
$cart['customer_lastname'] = $customer_lastname;
$cart['customer_is_guest'] = 2;
$cart->save();
}
}
......
......@@ -14,7 +14,7 @@ use fecshop\services\Service;
use Yii;
/**
* Cart services.
* Cart services. 对购物车产品操作的具体实现部分。
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
......@@ -48,7 +48,7 @@ class QuoteItem extends Service
}
$where = [
'cart_id' => $cart_id,
'product_id'=> $item['product_id'],
'product_id' => $item['product_id'],
];
if (isset($item['custom_option_sku']) && !empty($item['custom_option_sku'])) {
$where['custom_option_sku'] = $item['custom_option_sku'];
......@@ -61,15 +61,15 @@ class QuoteItem extends Service
Yii::$service->cart->quote->computeCartInfo();
} else {
$item_one = new MyCartItem();
$item_one->store = Yii::$service->store->currentStore;
$item_one->cart_id = $cart_id;
$item_one->created_at = time();
$item_one->updated_at = time();
$item_one->product_id = $item['product_id'];
$item_one->qty = $item['qty'];
$item_one->store = Yii::$service->store->currentStore;
$item_one->cart_id = $cart_id;
$item_one->created_at = time();
$item_one->updated_at = time();
$item_one->product_id = $item['product_id'];
$item_one->qty = $item['qty'];
$item_one->custom_option_sku = ($item['custom_option_sku'] ? $item['custom_option_sku'] : '');
$item_one->save();
// 重新计算购物车的数量
// 重新计算购物车的数量,并写入sales_flat_cart表存储
Yii::$service->cart->quote->computeCartInfo();
}
}
......@@ -84,14 +84,15 @@ class QuoteItem extends Service
* @return boolean;
* 将购物车中的某个产品更改个数,更改后的个数就是上面qty的值。
*/
/** 该函数已经被遗弃
public function changeItemQty($item)
{
$cart_id = Yii::$service->cart->quote->getCartId();
// 查看是否存在此产品,如果存在,则更改
$item_one = MyCartItem::find()->where([
'cart_id' => $cart_id,
'product_id'=> $item['product_id'],
'custom_option_sku' => $item['custom_option_sku'],
'cart_id' => $cart_id,
'product_id' => $item['product_id'],
'custom_option_sku' => $item['custom_option_sku'],
])->one();
if ($item_one['cart_id']) {
$item_one->qty = $item['qty'];
......@@ -106,6 +107,7 @@ class QuoteItem extends Service
return false;
}
}
*/
/**
* 通过quoteItem表,计算得到所有产品的总数
......@@ -118,7 +120,7 @@ class QuoteItem extends Service
$cart_id = Yii::$service->cart->quote->getCartId();
$item_qty = 0;
if ($cart_id) {
$data = MyCartItem::find()->where([
$data = MyCartItem::find()->asArray()->where([
'cart_id' => $cart_id,
])->all();
if (is_array($data) && !empty($data)) {
......@@ -143,9 +145,9 @@ class QuoteItem extends Service
*/
public function getCartProductInfo()
{
$cart_id = Yii::$service->cart->quote->getCartId();
$products = [];
$product_total = 0;
$cart_id = Yii::$service->cart->quote->getCartId();
$products = [];
$product_total = 0;
$product_weight = 0;
if ($cart_id) {
if (!isset($this->_cart_product_info[$cart_id])) {
......@@ -154,54 +156,53 @@ class QuoteItem extends Service
])->all();
if (is_array($data) && !empty($data)) {
foreach ($data as $one) {
$product_id = $one['product_id'];
$product_one = Yii::$service->product->getByPrimaryKey($product_id);
$product_id = $one['product_id'];
$product_one = Yii::$service->product->getByPrimaryKey($product_id);
if ($product_one['_id']) {
$qty = $one['qty'];
$custom_option_sku = $one['custom_option_sku'];
$product_price_arr = Yii::$service->product->price->getCartPriceByProductId($product_id, $qty, $custom_option_sku, 2);
$qty = $one['qty'];
$custom_option_sku = $one['custom_option_sku'];
$product_price_arr = Yii::$service->product->price->getCartPriceByProductId($product_id, $qty, $custom_option_sku, 2);
$curr_product_price = isset($product_price_arr['curr_price']) ? $product_price_arr['curr_price'] : 0;
$base_product_price = isset($product_price_arr['base_price']) ? $product_price_arr['base_price'] : 0;
$product_price = isset($curr_product_price['value']) ? $curr_product_price['value'] : 0;
$product_price = isset($curr_product_price['value']) ? $curr_product_price['value'] : 0;
$product_row_price = $product_price * $qty;
$product_total += $product_row_price;
$product_row_price = $product_price * $qty;
$product_total += $product_row_price;
$base_product_row_price = $base_product_price * $qty;
$base_product_total += $base_product_row_price;
$base_product_total += $base_product_row_price;
$p_wt = $product_one['weight'] * $qty;
$product_weight += $p_wt;
$productSpuOptions = $this->getProductSpuOptions($product_one);
$p_wt = $product_one['weight'] * $qty;
$product_weight += $p_wt;
$productSpuOptions = $this->getProductSpuOptions($product_one);
$products[] = [
'item_id' => $one['item_id'],
'item_id' => $one['item_id'],
'product_id' => $product_id,
'sku' => $product_one['sku'],
'name' => Yii::$service->store->getStoreAttrVal($product_one['name'], 'name'),
'qty' => $qty,
'sku' => $product_one['sku'],
'name' => Yii::$service->store->getStoreAttrVal($product_one['name'], 'name'),
'qty' => $qty,
'custom_option_sku' => $custom_option_sku,
'product_price' => $product_price,
'product_price' => $product_price,
'product_row_price' => $product_row_price,
'base_product_price' => $base_product_price,
'base_product_row_price' => $base_product_row_price,
'base_product_row_price'=> $base_product_row_price,
'product_name' => $product_one['name'],
'product_name' => $product_one['name'],
'product_weight' => $product_one['weight'],
'product_row_weight'=> $p_wt,
'product_url' => $product_one['url_key'],
'product_image' => $product_one['image'],
'custom_option' => $product_one['custom_option'],
'spu_options' => $productSpuOptions,
'product_url' => $product_one['url_key'],
'product_image' => $product_one['image'],
'custom_option' => $product_one['custom_option'],
'spu_options' => $productSpuOptions,
];
//var_dump($product_one['image']);exit;
}
}
$this->_cart_product_info[$cart_id] = [
'products' => $products,
'product_total' => $product_total,
'base_product_total' => $base_product_total,
'product_weight'=> $product_weight,
'products' => $products,
'product_total' => $product_total,
'base_product_total'=> $base_product_total,
'product_weight' => $product_weight,
];
}
}
......@@ -223,14 +224,8 @@ class QuoteItem extends Service
if (isset($productOb['attr_group']) && !empty($productOb['attr_group'])) {
$productAttrGroup = $productOb['attr_group'];
Yii::$service->product->addGroupAttrs($productAttrGroup);
//$attrInfo = Yii::$service->product->getGroupAttrInfo($productAttrGroup);
//if(is_array($attrInfo) && !empty($attrInfo)){
// $attrs = array_keys($attrInfo);
// \fecshop\models\mongodb\Product::addCustomProductAttrs($attrs);
//}
$productOb = Yii::$service->product->getByPrimaryKey((string) $productOb['_id']);
$spuArr = Yii::$service->product->getSpuAttr($productAttrGroup);
$productOb = Yii::$service->product->getByPrimaryKey((string) $productOb['_id']);
$spuArr = Yii::$service->product->getSpuAttr($productAttrGroup);
if (is_array($spuArr) && !empty($spuArr)) {
foreach ($spuArr as $spu_attr) {
if (isset($productOb[$spu_attr]) && !empty($productOb[$spu_attr])) {
......
<?php
/**
* FecShop file.
*
* @link http://www.fecshop.com/
* @copyright Copyright (c) 2016 FecShop Software LLC
* @license http://www.fecshop.com/license/
*/
namespace fecshop\services\category;
use fecshop\models\mongodb\Category;
use Yii;
/**
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class CategoryMysqldb implements CategoryInterface
{
public function getByPrimaryKey($primaryKey){
}
public function coll($filter){
}
public function save($one, $originUrlKey){
}
public function remove($ids){
}
}
\ No newline at end of file
......@@ -13,6 +13,7 @@ use fecshop\services\Service;
use Yii;
/**
* 分类图片的一些处理。
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
......
......@@ -20,7 +20,6 @@ use Yii;
class Menu extends Service
{
public $rootCategoryId = '0';
/**
* @property $parentId|int
* 得到分类的目录信息
......@@ -36,14 +35,13 @@ class Menu extends Service
])->where([
'parent_id' => $parentId,
])->all();
if (is_array($data) && !empty($data)) {
foreach ($data as $category) {
$categoryOne = [
'_id' => (string) $category['_id'],
'name' => Yii::$service->store->getStoreAttrVal($category['name'], 'name'),
'menu_custom'=> Yii::$service->store->getStoreAttrVal($category['menu_custom'], 'menu_custom'),
'url' => Yii::$service->url->getUrl($category['url_key']),
'_id' => (string) $category['_id'],
'name' => Yii::$service->store->getStoreAttrVal($category['name'], 'name'),
'menu_custom' => Yii::$service->store->getStoreAttrVal($category['menu_custom'], 'menu_custom'),
'url' => Yii::$service->url->getUrl($category['url_key']),
];
$childMenu = $this->getCategoryMenuArr((string) $category['_id']);
if ($childMenu) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册