Skip to content

Commit

Permalink
初始化项目
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaokaishan committed Nov 24, 2018
1 parent a7c5027 commit 6cebe6a
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 6 deletions.
37 changes: 37 additions & 0 deletions models/Cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,41 @@ public function attributes()
'app_name',
];
}

/**
* @see ActiveRecord::insert()
*/
protected function insertInternal($attributes = null)
{
if (!$this->beforeSave(true)) {
return false;
}

$values = $this->getDirtyAttributes($attributes);

if (empty($values)) {
$currentAttributes = $this->getAttributes();

if (isset($currentAttributes['_id'])) {
$values['_id'] = $currentAttributes['_id'];
}
}

$bucket = static::getBucket();
$sql = $bucket->db->getQueryBuilder()->insert($bucket->name, $values);
$sql = str_replace('":cart_id"', 'UUID()', $sql);
$newId = $bucket->db->createCommand($sql)->queryScalar();

if ($newId !== null) {
$this->setAttribute('_id', $newId);
$values['_id'] = $newId;
}

$changedAttributes = array_fill_keys(array_keys($values), null);

$this->setOldAttributes($values);
$this->afterSave(true, $changedAttributes);

return true;
}
}
37 changes: 37 additions & 0 deletions models/cart/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,41 @@ public function attributes()
'custom_option_sku',
];
}

/**
* @see ActiveRecord::insert()
*/
protected function insertInternal($attributes = null)
{
if (!$this->beforeSave(true)) {
return false;
}

$values = $this->getDirtyAttributes($attributes);

if (empty($values)) {
$currentAttributes = $this->getAttributes();

if (isset($currentAttributes['_id'])) {
$values['_id'] = $currentAttributes['_id'];
}
}

$bucket = static::getBucket();
$sql = $bucket->db->getQueryBuilder()->insert($bucket->name, $values);
$sql = str_replace('":item_id"', 'UUID()', $sql);
$newId = $bucket->db->createCommand($sql)->queryScalar();

if ($newId !== null) {
$this->setAttribute('_id', $newId);
$values['_id'] = $newId;
}

$changedAttributes = array_fill_keys(array_keys($values), null);

$this->setOldAttributes($values);
$this->afterSave(true, $changedAttributes);

return true;
}
}
6 changes: 1 addition & 5 deletions services/cart/Quote.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function updateLoginCart($address_id, $shipping_method, $payment_method)
protected function actionCreateCart()
{
$myCart = new $this->_cartModelName;
$myCart->cart_id = 'UUID()';
$myCart->cart_id = ':cart_id';
$myCart->store = Yii::$service->store->currentStore;
$myCart->created_at = time();
$myCart->updated_at = time();
Expand All @@ -62,12 +62,8 @@ protected function actionCreateCart()
}
$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();
$newCart = $this->_cartModel->findOne($myCart['_id']);

$cart_id = $newCart['cart_id'];
$this->setCartId($cart_id);
$this->setCart($newCart);
Expand Down
2 changes: 1 addition & 1 deletion services/cart/QuoteItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function addItem($item)
Yii::$service->cart->quote->computeCartInfo();
} else {
$item_one = new $this->_itemModelName;
$item_one->item_id = 'UUID()';
$item_one->item_id = ':item_id';
$item_one->active = $this->itemDefaultActiveStatus;
$item_one->store = Yii::$service->store->currentStore;
$item_one->cart_id = $cart_id;
Expand Down

0 comments on commit 6cebe6a

Please sign in to comment.