本文整理汇总了PHP中Cart::save方法的典型用法代码示例。如果您正苦于以下问题:PHP Cart::save方法的具体用法?PHP Cart::save怎么用?PHP Cart::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cart
的用法示例。
在下文中一共展示了Cart::save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addToCart
/**
* 添加商品到购物车
* @param $request
*/
public function addToCart($userId, $request)
{
if (empty($request) || empty($request)) {
throw new exception('传输数据错误,请重试');
}
if ($request['type'] == 'product') {
$pInfo = Product::model()->findByPk($request['id']);
//商品详情
} elseif ($request['type'] == 'tab') {
$pInfo = Tab::model()->findByPk($request['id']);
} elseif ($request['type'] == 'zine') {
$pInfo = Zine::model()->findByPk($request['id']);
}
//校验数量和所选尺寸等信息
//查找购物车里面的商品
$map = array();
$map['user_id'] = $userId;
$map['product_id'] = $request['id'];
$map['size_id'] = $request['size'];
$map['type'] = $this->product_type[$request['type']];
$cartInfo = Cart::model()->findByAttributes($map);
$this->addToCartBeforeCheck($request, $pInfo, $cartInfo);
$time = time();
if (empty($cartInfo)) {
$cartInfo = new Cart();
$cartInfo->user_id = $userId;
$cartInfo->product_id = $request['id'];
$cartInfo->type = $this->product_type[$request['type']];
$cartInfo->size_id = $request['size'];
$cartInfo->shop_price = $pInfo['sell_price'];
$cartInfo->sell_price = $pInfo['sell_price'];
$cartInfo->quantity = $request['num'];
$cartInfo->add_time = $time;
$cartInfo->update_time = $time;
$cartInfo->is_pay = isset($request['buynow']) && !empty($request['buynow']) ? 1 : 0;
$flag = $cartInfo->save();
} else {
//若立即购买的P在购物车中已经存在
$cartInfo->shop_price = $pInfo['sell_price'];
$cartInfo->sell_price = $pInfo['sell_price'];
$cartInfo->quantity += $request['num'];
$cartInfo->is_pay = isset($request['buynow']) && !empty($request['buynow']) ? 1 : 0;
$cartInfo->update_time = $time;
$flag = $cartInfo->save();
}
if (empty($flag)) {
throw new exception('添加购物车失败,请重试!');
}
return true;
}
示例2: updateCustomer
/**
* Update context after customer login
* @param Customer $customer Created customer
*/
public function updateCustomer(Customer $customer)
{
$this->customer = $customer;
$this->cookie->id_customer = (int) $customer->id;
$this->cookie->customer_lastname = $customer->lastname;
$this->cookie->customer_firstname = $customer->firstname;
$this->cookie->passwd = $customer->passwd;
$this->cookie->logged = 1;
$customer->logged = 1;
$this->cookie->email = $customer->email;
$this->cookie->is_guest = $customer->isGuest();
$this->cart->secure_key = $customer->secure_key;
if (Configuration::get('PS_CART_FOLLOWING') && (empty($this->cookie->id_cart) || Cart::getNbProducts($this->cookie->id_cart) == 0) && ($id_cart = (int) Cart::lastNoneOrderedCart($this->customer->id))) {
$this->cart = new Cart($id_cart);
} else {
$id_carrier = (int) $this->cart->id_carrier;
$this->cart->id_carrier = 0;
$this->cart->setDeliveryOption(null);
$this->cart->id_address_delivery = (int) Address::getFirstCustomerAddressId((int) $customer->id);
$this->cart->id_address_invoice = (int) Address::getFirstCustomerAddressId((int) $customer->id);
}
$this->cart->id_customer = (int) $customer->id;
if (isset($id_carrier) && $id_carrier) {
$delivery_option = [$this->cart->id_address_delivery => $id_carrier . ','];
$this->cart->setDeliveryOption($delivery_option);
}
$this->cart->save();
$this->cookie->id_cart = (int) $this->cart->id;
$this->cookie->write();
$this->cart->autosetProductAddress();
}
示例3: triggerLoginAfter
/**
* trigger login after
* @param $logged_info
*/
function triggerLoginAfter($logged_info)
{
$cartRepo = new CartRepository();
if ($this->cartBeforeLogin instanceof Cart) {
if ($memberCart = $cartRepo->getCart($this->module_info->module_srl, NULL, $logged_info->member_srl, session_id()))
{
if ($memberCart->cart_srl != $this->cartBeforeLogin->cart_srl) {
$memberCart->merge($this->cartBeforeLogin);
}
Context::set('cart', $memberCart);
} else {
$this->cartBeforeLogin->member_srl = $logged_info->member_srl;
$this->cartBeforeLogin->save();
}
}
}
示例4: setPhpCookieData
public function setPhpCookieData()
{
if (!isset($_COOKIE['id_guest'])) {
if (!isset($this->context->cookie->id_guest)) {
Guest::setNewGuest($this->context->cookie);
}
setcookie('id_guest', $this->context->cookie->id_guest, time() + 86400, "/");
} else {
$this->context->cookie->id_guest = $_COOKIE['id_guest'];
setcookie('id_guest', $this->context->cookie->id_guest, time() + 86400, "/");
}
$guest = new Guest($this->context->cookie->id_guest);
if (!isset($_COOKIE['id_cart']) && !isset($this->context->cart->id)) {
$cart = new Cart();
$cart->recyclable = 0;
$cart->gift = 0;
$cart->id_shop = (int) $this->context->shop->id;
$cart->id_lang = ($id_lang = (int) Tools::getValue('id_lang')) ? $id_lang : Configuration::get('PS_LANG_DEFAULT');
$cart->id_currency = ($id_currency = (int) Tools::getValue('id_currency')) ? $id_currency : Configuration::get('PS_CURRENCY_DEFAULT');
$cart->id_address_delivery = 0;
$cart->id_address_invoice = 0;
$cart->id_currency = Configuration::get('PS_CURRENCY_DEFAULT');
$cart->id_guest = (int) $this->context->cookie->id_guest;
$cart->setNoMultishipping();
$cart->save();
$this->context->cart = $cart;
$this->context->cookie->id_cart = $cart->id;
setcookie('id_cart', $cart->id, time() + 86400, "/");
} else {
$cart = new Cart((int) $_COOKIE['id_cart']);
$this->context->cart = $cart;
$this->context->cookie->id_cart = $cart->id;
setcookie('id_cart', $cart->id, time() + 86400, "/");
}
$customer = new Customer();
$customer->id_gender = 0;
$customer->id_default_group = 1;
$customer->outstanding_allow_amount = 0;
$customer->show_public_prices = 0;
$customer->max_payment_days = 0;
$customer->active = 1;
$customer->is_guest = 0;
$customer->deleted = 0;
$customer->logged = 0;
$customer->id_guest = $this->context->cookie->id_guest;
$this->context->customer = $customer;
}
示例5: add
public function add()
{
$validator = Validator::make(Input::all(), Cart::$rules);
if ($validator->passes() == true) {
$key = 'kiobostha?kiobos';
$price = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, base64_decode(Input::get('price')), MCRYPT_MODE_ECB));
$cart = new Cart();
$cart->invoice = uniqid(rand());
$cart->user_id = Auth::user()->id;
$cart->product_id = Input::get('id');
$cart->quantity = Input::get('quantity');
$cart->price = Input::get('quantity') * $price;
$cart->catagory_id = Input::get('catagory');
if ($cart->save()) {
return Redirect::back()->with('event', '<p class="alert alert-success"><span class="glyphicon glyphicon-ok"></span> Successfully added to cart</p>');
}
return Redirect::back()->with('event', '<p class="alert alert-danger"><span class="glyphicon glyphicon-remove"></span> Error occured. Please try after again.</p>');
}
return Redirect::back()->withErrors($validator)->withInput();
}
示例6: testEmptyCart
/**
* Test that an empty cart has 0 products
*/
public function testEmptyCart()
{
$cart = new Cart();
$cart->module_srl = 123;
$cart->save();
$this->assertEquals(0, count($cart->getProducts()));
}
示例7: serialize
if ($oldcart->id) {
$oldcart->id_customer = $customer->id;
if ($oldcart->id_address_delivery <= 0 or !in_array($txn_type, $recurring_txn_types)) {
$oldcart->id_address_delivery = $address->id;
$delivery_option[(int) $oldcart->id_address_delivery] = $oldcart->id_carrier . ",";
$oldcart->delivery_option = serialize($delivery_option);
}
if ($oldcart->id_address_invoice <= 0 or !in_array($txn_type, $recurring_txn_types)) {
$oldcart->id_address_invoice = $address->id;
}
$paid_currency_id = intval(Currency::getIdByIsoCode($_POST['mc_currency']));
if (isset($paid_currency_id) and $paid_currency_id > 0) {
$oldcart->id_currency = $paid_currency_id;
}
$oldcart->secure_key = $customer->secure_key;
$oldcart->save();
Db::getInstance()->Execute('UPDATE ' . _DB_PREFIX_ . 'cart_product SET id_address_delivery = ' . (int) $oldcart->id_address_delivery . ' WHERE id_cart=' . (int) $oldcart->id);
}
$cookie->id_customer = intval($customer->id);
$cookie->customer_lastname = $customer->lastname;
$cookie->customer_firstname = $customer->firstname;
$cookie->passwd = $customer->passwd;
$cookie->logged = 1;
$cookie->email = $customer->email;
$cookie->id_lang = $oldcart->id_lang;
$cookie->id_cart = $oldcart->id;
if ($result == 'VERIFIED') {
if (!isset($_POST['mc_gross'])) {
$errors .= $paypal->getL('mc_gross') . '<br />';
}
if (!isset($_POST['payment_status'])) {
示例8: parseListOrders
/**
* This function will run parse an order that we get from Amazon MWS.
* It saves orders of the customers to the DB.
* @param $response ListOrderItemsResponse Contains the orders from Amazon
* Marketplace WebService
* @return void
*/
public function parseListOrders($response)
{
$checkDate = date("Y-m-d", strtotime($this->amazon_check_time));
$listOrdersResult = $response->getListOrdersResult();
if ($listOrdersResult->isSetOrders()) {
$orders = $listOrdersResult->getOrders();
$orderList = $orders->getOrder();
foreach ($orderList as $order) {
if ($order->isSetAmazonOrderId()) {
$strOrderId = $order->getAmazonOrderId();
Yii::log("Found Amazon Order " . $strOrderId, 'info', 'application.' . __CLASS__ . "." . __FUNCTION__);
$objCart = Cart::LoadByIdStr($strOrderId);
if (!$objCart instanceof Cart) {
//We ignore orders we've already downloaded
$objCart = new Cart();
$objCart->id_str = $strOrderId;
$objCart->origin = 'amazon';
//We mark this as just a cart, not an order, because we download the items next
$objCart->cart_type = CartType::cart;
$objOrderTotal = $order->getOrderTotal();
Yii::log("Order total information " . print_r($objOrderTotal, true), 'info', 'application.' . __CLASS__ . "." . __FUNCTION__);
$objCart->total = $objOrderTotal->getAmount();
$objCart->currency = $objOrderTotal->getCurrencyCode();
$objCart->status = OrderStatus::Requested;
$objCart->datetime_cre = $order->getPurchaseDate();
$objCart->modified = $order->getLastUpdateDate();
if (!$objCart->save()) {
Yii::log("Error saving cart " . print_r($objCart->getErrors(), true), 'error', 'application.' . __CLASS__ . "." . __FUNCTION__);
}
//Since email from is Anonymous, we probably will have to create a shell record
$objCustomer = Customer::LoadByEmail($order->getBuyerEmail());
if (!$objCustomer) {
$customerName = $this->_getCustomerName($order->getBuyerName());
$objCustomer = new Customer();
$objCustomer->email = $order->getBuyerEmail();
$objCustomer->first_name = $customerName['first_name'];
$objCustomer->last_name = $customerName['last_name'];
$objCustomer->record_type = Customer::EXTERNAL_SHELL_ACCOUNT;
$objCustomer->allow_login = Customer::UNAPPROVED_USER;
$objCustomer->save();
}
$objCart->customer_id = $objCustomer->id;
if (!$objCart->save()) {
Yii::log("Error saving cart " . print_r($objCart->getErrors(), true), 'error', 'application.' . __CLASS__ . "." . __FUNCTION__);
}
if ($order->isSetShippingAddress()) {
$shippingAddress = $order->getShippingAddress();
$countrycode = Country::IdByCode($shippingAddress->getCountryCode());
if ($shippingAddress->isSetStateOrRegion()) {
$objState = State::LoadByCode($shippingAddress->getStateOrRegion(), $countrycode);
}
$customerName = $this->_getCustomerName($shippingAddress->getName());
$config = array('address_label' => 'amazon', 'customer_id' => $objCustomer->id, 'first_name' => $customerName['first_name'], 'last_name' => $customerName['last_name'], 'address1' => $shippingAddress->getAddressLine1(), 'address2' => trim($shippingAddress->getAddressLine2() . " " . $shippingAddress->getAddressLine3()), 'city' => $shippingAddress->getCity(), 'state_id' => $objState->id, 'postal' => $shippingAddress->getPostalCode(), 'country_id' => $countrycode, 'phone' => $shippingAddress->getPhone());
$objCustAddress = CustomerAddress::findOrCreate($config);
$objCustomer->default_billing_id = $objCustAddress->id;
$objCustomer->default_shipping_id = $objCustAddress->id;
$objCustomer->save();
$objCart->shipaddress_id = $objCustAddress->id;
$objCart->billaddress_id = $objCustAddress->id;
//Amazon doesn't provide billing data, just dupe
if (!$objCart->save()) {
Yii::log("Error saving cart " . print_r($objCart->getErrors(), true), 'error', 'application.' . __CLASS__ . "." . __FUNCTION__);
}
Yii::log("Looking for destination " . $objState->country_code . " " . $objState->code . " " . $shippingAddress->getPostalCode(), 'info', 'application.' . __CLASS__ . "." . __FUNCTION__);
$objDestination = Destination::LoadMatching($objState->country_code, $objState->code, $shippingAddress->getPostalCode());
if ($objDestination === null) {
Yii::log("Did not find destination, using default in Web Store ", 'info', 'application.' . __CLASS__ . "." . __FUNCTION__);
$objDestination = Destination::getAnyAny();
}
$objCart->tax_code_id = $objDestination->taxcode;
$objCart->recalculateAndSave();
}
if ($order->isSetShipServiceLevel()) {
$strShip = $order->getShipServiceLevel();
//If we have a shipping object already, update it, otherwise create it
if (isset($objCart->shipping)) {
$objShipping = $objCart->shipping;
} else {
//create
$objShipping = new CartShipping();
if (!$objShipping->save()) {
Yii::log("Error saving shipping info for cart " . print_r($objShipping->getErrors(), true), 'error', 'application.' . __CLASS__ . "." . __FUNCTION__);
}
}
if ($order->isSetShipmentServiceLevelCategory()) {
$strShip = $order->getShipmentServiceLevelCategory();
}
$objShipping->shipping_module = get_class($this);
$objShipping->shipping_data = $strShip;
$objShipping->shipping_method = $this->objModule->getConfig('product');
$objShipping->shipping_cost = 0;
$objShipping->shipping_sell = 0;
$objShipping->save();
//.........这里部分代码省略.........
示例9: fakeCrowdFundingPurches
public function fakeCrowdFundingPurches($id)
{
set_time_limit(0);
$this->login();
$bottom = Input::get('bottom', '');
$top = Input::get('top', '');
$p_id = Input::get('p_id', '');
try {
if (!$p_id || !$top || !$bottom) {
throw new Exception("需要关键数据", 1);
}
$funding = CrowdFunding::find($id);
$funding->load(['eventItem']);
$product = CrowdFundingProduct::find($p_id);
$quantity = 1;
$users = User::where('u_mobile', '>=', $bottom)->where('u_mobile', '<=', $top)->get();
foreach ($users as $key => $user) {
$u_id = $user->u_id;
// sku need to be calulated before cart generated
$product->loadProduct($quantity);
// add cart
$cart = new Cart();
$cart->p_id = $p_id;
$cart->p_name = $product->p_title;
$cart->u_id = $u_id;
$cart->b_id = $product->b_id;
$cart->created_at = Tools::getNow();
$cart->c_quantity = $quantity;
$cart->c_price = $product->p_price;
$cart->c_amount = $product->p_price * $quantity;
$cart->c_discount = 100;
$cart->c_price_origin = $product->p_price;
$cart->c_amount_origin = $product->p_price * $quantity;
$cart->c_status = 2;
$cart->c_type = 2;
$re = $cart->save();
if (!$re) {
throw new Exception("提交库存失败", 7006);
}
$shipping_address = 'Fake Purches';
$shipping_name = $user->u_name;
$shipping_phone = $user->u_mobile;
$date_obj = new DateTime($funding->eventItem->e_start_at);
$delivery_time_obj = $date_obj->modify('+' . ($funding->c_time + $funding->c_yield_time) . 'days');
// add order
$order_group_no = Order::generateOrderGroupNo($u_id);
$rnd_str = rand(10, 99);
$order_no = $order_group_no . $cart->b_id . $rnd_str;
$order = new Order();
$order->u_id = $u_id;
$order->b_id = $cart->b_id;
$order->o_amount_origin = $cart->c_amount_origin;
$order->o_amount = $cart->c_amount;
$order->o_shipping_fee = $funding->c_shipping_fee;
$order->o_shipping_name = $shipping_name;
$order->o_shipping_phone = $shipping_phone;
$order->o_shipping_address = $shipping_address;
$order->o_delivery_time = $delivery_time_obj->format('Y-m-d H:i:s');
$order->o_shipping = $funding->c_shipping;
$order->o_comment = 'Fake Order';
$order->o_number = $order_no;
$order->o_group_number = $order_group_no;
$o_id = $order->addOrder();
Cart::bindOrder([$order->o_id => [$cart->c_id]]);
$cart->checkout();
$order->o_status = 2;
$order->o_shipping_status = 10;
$order->paied_at = Tools::getNow();
$order->save();
}
} catch (Exception $e) {
echo $e->getMessage();
}
echo "done";
}
示例10: getResponse
public function getResponse()
{
$this->doorGets->checkAjaxMode();
$response = array('code' => 404, 'data' => array());
$arrayAction = array('index' => 'Home', 'add' => 'add', 'plus' => 'plus', 'minus' => 'minus', 'remove' => 'remove', 'shippingMethod' => 'shippingMethod');
$out = '';
$params = $this->doorGets->Params();
$modules = $this->doorGets->getAllActiveModules();
$lgActuel = $this->doorGets->getLangueTradution();
$lg = 'en';
if (array_key_exists('lg', $params['GET']) && array_key_exists($params['GET']['lg'], $this->doorGets->allLanguages)) {
$lg = $this->doorGets->myLanguage = $params['GET']['lg'];
}
if (array_key_exists($this->Action, $arrayAction)) {
switch ($this->Action) {
case 'index':
break;
case 'add':
if (true) {
$uri = array_key_exists('uri', $params['GET']) && !empty($params['GET']['uri']) ? $params['GET']['uri'] : '';
$quantity = array_key_exists('qty', $params['GET']) && !empty($params['GET']['qty']) ? (int) $params['GET']['qty'] : 1;
$id = array_key_exists('id', $params['GET']) && !empty($params['GET']['id']) ? $params['GET']['id'] : '';
if (empty($quantity)) {
$quantity = 1;
}
if (!empty($uri) && !empty($id) && array_key_exists($uri, $modules)) {
$sqlUri = $this->doorGets->getRealUri($uri);
$table = '_m_' . $sqlUri;
$tableTraduction = $table . '_traduction';
$isContent = $this->doorGets->dbQS($id, $table);
if (!empty($isContent)) {
$idTraduction = $this->doorGets->getIdContentTraduction($isContent);
if (!is_null($idTraduction)) {
$isContentTraduction = $this->doorGets->dbQS($idTraduction, $tableTraduction);
if (!empty($isContentTraduction)) {
$product = array('uri' => $uri, 'id' => $id, 'quantity' => $quantity);
$Cart = new Cart($this->doorGets);
$Cart->addProduct($product);
$Cart->save();
$products = $Cart->getProducts();
$productName = $products[$uri . '-' . $id]['title'];
$response = array('code' => 200, 'data' => array('message' => $productName . ' ' . $this->doorGets->__("est dans votre panier") . '.', 'products' => $Cart->getProducts(), 'count' => $Cart->getCount(), 'totalAmount' => number_format($Cart->getTotalAmount(), 2, ',', ' '), 'totalAmountVat' => number_format($this->vat * $Cart->getTotalAmount() + $Cart->shippingAmount, 2, ',', ' '), 'subtotalAmountVat' => $Cart->getSubTotalAmountPromoVAT(true), 'totalAmountPromo' => number_format($Cart->getTotalAmountPromo(), 2, ',', ' '), 'totalAmountPromoVat' => number_format($this->vat * $Cart->getTotalAmountPromo() + $Cart->shippingAmount, 2, ',', ' '), 'shippingAmount' => $Cart->getShippingAmount(), 'langue' => $lg, 'uri' => $uri));
}
}
}
}
}
break;
case 'minus':
if (array_key_exists('uri', $params['GET'])) {
$uri = $params['GET']['uri'];
$Cart = new Cart($this->doorGets);
$newAmount = $Cart->minusProduct($uri);
$Cart->save();
$response = array('code' => 200, 'data' => array('message' => $this->doorGets->__("Le quantité du produit a été mise à jour") . '.', 'products' => $Cart->getProducts(true), 'count' => $Cart->getCount(), 'totalAmount' => $Cart->getTotalAmount(true), 'totalAmountVat' => $Cart->getTotalAmountVAT(true), 'subtotalAmountVat' => $Cart->getSubTotalAmountPromoVAT(true), 'totalAmountPromo' => $Cart->getTotalAmountPromo(true), 'totalAmountPromoVat' => $Cart->getTotalAmountPromoShippingVAT(true), 'shippingAmount' => $Cart->getShippingAmount(), 'langue' => $lg, 'newAmount' => $newAmount, 'uri' => $uri));
}
break;
case 'plus':
if (array_key_exists('uri', $params['GET'])) {
$uri = $params['GET']['uri'];
$Cart = new Cart($this->doorGets);
$newAmount = $Cart->plusProduct($uri);
$Cart->save();
$response = array('code' => 200, 'data' => array('message' => $this->doorGets->__("Le quantité du produit a été mise à jour") . '.', 'products' => $Cart->getProducts(true), 'count' => $Cart->getCount(), 'totalAmount' => $Cart->getTotalAmount(true), 'totalAmountVat' => $Cart->getTotalAmountVAT(true), 'subtotalAmountVat' => $Cart->getSubTotalAmountPromoVAT(true), 'totalAmountPromo' => $Cart->getTotalAmountPromo(true), 'totalAmountPromoVat' => $Cart->getTotalAmountPromoShippingVAT(true), 'shippingAmount' => $Cart->getShippingAmount(), 'langue' => $lg, 'newAmount' => $newAmount, 'uri' => $uri));
}
break;
case 'remove':
if (array_key_exists('uri', $params['GET'])) {
$uri = $params['GET']['uri'];
$Cart = new Cart($this->doorGets);
$Cart->removeProduct($uri);
$Cart->save();
$response = array('code' => 200, 'data' => array('message' => $this->doorGets->__("Le produit a été supprimé de votre panier") . '.', 'products' => $Cart->getProducts(true), 'count' => $Cart->getCount(), 'totalAmount' => $Cart->getTotalAmount(true), 'totalAmountVat' => $Cart->getTotalAmountVAT(true), 'subtotalAmountVat' => $Cart->getSubTotalAmountPromoVAT(true), 'totalAmountPromo' => $Cart->getTotalAmountPromo(true), 'totalAmountPromoVat' => $Cart->getTotalAmountPromoShippingVAT(true), 'shippingAmount' => $Cart->getShippingAmount(), 'langue' => $lg, 'uri' => $uri));
}
break;
case 'shippingMethod':
if (array_key_exists('key', $params['GET'])) {
$key = $params['GET']['key'];
$Cart = new Cart($this->doorGets);
$Cart->setShippingMethod($key);
$Cart->save();
$response = array('code' => 200, 'data' => array('message' => $this->doorGets->__("Le prix de la livraison est à jour") . '.', 'products' => $Cart->getProducts(true), 'count' => $Cart->getCount(), 'totalAmount' => $Cart->getTotalAmount(true), 'totalAmountVat' => $Cart->getTotalAmountVAT(true), 'subtotalAmountVat' => $Cart->getSubTotalAmountPromoVAT(true), 'totalAmountPromo' => $Cart->getTotalAmountPromo(true), 'totalAmountPromoVat' => $Cart->getTotalAmountPromoShippingVAT(true), 'shippingAmount' => $Cart->getShippingAmount(), 'langue' => $lg));
}
break;
}
}
return json_encode($response, JSON_FORCE_OBJECT);
}
示例11: social
public function social()
{
$social_id = Input::get('id');
if (Auth::check()) {
$user_id = Auth::user()->id;
$user = User::find($user_id);
$user->social_id = $social_id;
$user->save();
$store = StoreLocation::where('zipcode', Auth::user()->zipcode)->first();
if ($store) {
$store_id = $store->id;
} else {
$store_id = 0;
}
$cart = Cart::where('user_id')->orderBy('updated_at', 'desc')->first();
if ($cart) {
$cart_id = $cart->id;
} else {
$cart = new Cart();
$cart->cart_url = "";
$cart->user_id = Auth::user()->id;
$cart->save();
$cart_id = $cart->id;
$cart_user = new CartUser();
$cart_user->cart_id = $cart_id;
$cart_user->user_id = Auth::user()->id;
$cart_user->save();
}
Session::put('zipcode', Auth::user()->zipcode);
Session::put('store_id', $store_id);
Session::put('cart_id', $cart_id);
return Redirect::to('/user');
} else {
$user = User::where('social_id', $social_id)->first();
if ($user) {
$already = 'there';
Auth::login($user);
} else {
$already = '';
$zipcode = Session::get('zipcode');
if ($zipcode == null) {
return Redirect::to("/")->with('message', 'Please Select the Zipcode and proceed');
} else {
$social_id = Input::get('id');
$first_name = Input::get('first_name');
$last_name = Input::get('last_name');
$email = Input::get('email');
$user = User::add($first_name, $last_name, '', $email, '', $zipcode, $social_id, '');
}
}
Auth::login($user);
$store = StoreLocation::where('zipcode', Auth::user()->zipcode)->first();
if ($store) {
$store_id = $store->id;
} else {
$store_id = 0;
}
$cart = Cart::where('user_id')->orderBy('updated_at', 'desc')->first();
if ($cart) {
$cart_id = $cart->id;
} else {
$cart = new Cart();
$cart->cart_url = "";
$cart->user_id = Auth::user()->id;
$cart->save();
$cart_id = $cart->id;
$cart_user = new CartUser();
$cart_user->cart_id = $cart_id;
$cart_user->user_id = Auth::user()->id;
$cart_user->save();
}
// dd(Session::get('zipcode'));
Session::put('zipcode', Auth::user()->zipcode);
Session::put('store_id', $store_id);
Session::put('cart_id', $cart_id);
if ($already == 'there') {
return Redirect::to("/store/{$store_id}");
} else {
return Redirect::to("/login");
}
}
$response = Response::json($response_array, $response_code);
return $response;
}
示例12: postOrder
/**
* The function posts Order.
*
* @access private
* @param object $Order The Order to save.
* @param object $Cart The Cart object to clear items.
* @return string The JSON response.
*/
private function postOrder(Order $Order, Cart $Cart = null)
{
$error = array();
$Order->setPost($_POST);
$Custom = $Order->getCustom();
$Address = $Order->getAddress();
if ($Order->Type == Order::STANDARD && (!$Address->Name || !$Address->Phone) || $Order->Type == Order::CUSTOM && (!$Custom->Name || !$Custom->Email) || $Order->Type == Order::PRODUCT && (!$Address->Name || !$Address->Phone)) {
$error[] = 'Заполните все обязательные поля';
} else {
if ($Order->Type != Order::CUSTOM && !Error::check($Address->Email, 'email')) {
$error[] = 'Введите корректный E-mail';
} else {
if ($Order->save()) {
if (!empty($_FILES['file']['tmp_name'])) {
if (File::upload($Order, $_FILES['file'])) {
$Order->save();
}
}
if ($Cart) {
$Cart->clear();
$Cart->save();
}
$Email = new Email_Order($Order);
if (!$Email->send()) {
$error[] = 'Ошибка отправки сообщения';
}
} else {
$error[] = 'Ошибка записи данных';
}
}
}
$response = array('result' => count($error) ? 0 : 1);
$response['posted'] = 1;
$response['msg'] = implode("\n", $error);
return $this->outputJSON($response);
}
示例13: hooknewOrder
public function hooknewOrder($params)
{
if (!$this->active) {
return;
}
$cart = new Cart($params['cart']->id);
$order = $params['order'];
$option = Db::getInstance()->getValue('SELECT `option`
FROM `' . _DB_PREFIX_ . 'tnt_carrier_option`
WHERE `id_carrier` = "' . (int) $params['cart']->id_carrier . '"');
if (isset($option) && strpos($option, 'D') !== false) {
$dropOff = Db::getInstance()->getRow('SELECT `code`, `name`, `address`, `zipcode`, `city`
FROM `' . _DB_PREFIX_ . 'tnt_carrier_drop_off`
WHERE `id_cart` = "' . (int) $params['cart']->id . '"');
$alias = "tntRelaisColis" . $order->id;
$id_address = Db::getInstance()->getValue('SELECT id_address FROM `' . _DB_PREFIX_ . 'address` WHERE `id_customer` = "' . (int) $params['cart']->id_customer . '" AND `alias` = "' . $alias . '"');
if ($id_address > 0) {
$address_new = new Address($id_address);
} else {
$address_old = new Address($cart->id_address_delivery);
$address_new = new Address();
$address_new->id_customer = $address_old->id_customer;
$address_new->id_country = $address_old->id_country;
$address_new->id_state = $address_old->id_state;
$address_new->id_manufacturer = $address_old->id_manufacturer;
$address_new->id_supplier = $address_old->id_supplier;
$address_new->lastname = $address_old->lastname;
$address_new->firstname = $address_old->firstname;
$address_new->phone = $address_old->phone;
$address_new->phone_mobile = $address_old->phone_mobile;
$address_new->alias = $alias;
}
if (strlen($dropOff['name']) >= 32) {
$address_new->company = substr($dropOff['name'], 0, 31);
} else {
$address_new->company = $dropOff['name'];
}
$address_new->address1 = $dropOff['address'];
$address_new->postcode = $dropOff['zipcode'];
$address_new->city = $dropOff['city'];
$address_new->deleted = 1;
$address_new->save();
$cart->id_address_delivery = $address_new->id;
$cart->save();
$order->id_address_delivery = $address_new->id;
$order->save();
}
}
示例14: actionCreateCart
/**
* 点单
*
*/
public function actionCreateCart()
{
$seatNum = $this->seatNum ? $this->seatNum : 0;
// $siteNo = SiteNo::model()->find('company_id=:companyId and code=:code and delete_flag=0',array(':companyId'=>$this->companyId,':code'=>$seatNum));
$productId = Yii::app()->request->getParam('id');
$now = time();
$cart = new Cart();
$cartDate = array('product_id' => $productId, 'company_id' => $this->companyId, 'code' => $seatNum, 'product_num' => 1, 'create_time' => $now);
$cart->attributes = $cartDate;
if ($cart->save()) {
echo 1;
} else {
echo 0;
}
Yii::app()->end();
}
示例15: postAddItem
/**
* postAddItem
*/
public function postAddItem()
{
$item_id = Input::get('item_id');
$customer_id = Input::get('customer_id');
$cart = new Cart();
$cart->customer_id = $customer_id;
$cart->item_id = $item_id;
$cart->quantity = 1;
$cart->type = 0;
$cart->craft_description = '';
$cart->confirm_price = 0.0;
$cart->save();
return Response::json(array('msg' => 1));
}