当前位置: 首页>>代码示例>>PHP>>正文


PHP Cart::getItems方法代码示例

本文整理汇总了PHP中Cart::getItems方法的典型用法代码示例。如果您正苦于以下问题:PHP Cart::getItems方法的具体用法?PHP Cart::getItems怎么用?PHP Cart::getItems使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Cart的用法示例。


在下文中一共展示了Cart::getItems方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: rpc_change

 public static function rpc_change(Context $ctx)
 {
     if (null === ($id = $ctx->get('id'))) {
         throw new RuntimeException(t('Не указан id товара.'));
     }
     $cart = new Cart($ctx);
     $items = $cart->getItems();
     $items[$id] = $ctx->get('qty', 1);
     $cart->setItems($items);
     return $ctx->getRedirect();
 }
开发者ID:umonkey,项目名称:molinos-cms,代码行数:11,代码来源:class.cartrpc.php

示例2: testAddItem

 public function testAddItem()
 {
     $item = \App\Models\Commodity::find(1);
     $item2 = \App\Models\Commodity::find(2);
     Cart::addItem($item);
     $this->assertEquals(Cart::getItems()->count(), 1);
     $this->assertEquals(Cart::getTotalCost(), $item->getPrice());
     Cart::removeItemsById($item->getIdentifer());
     $this->assertEquals(Cart::getItems()->count(), 0);
     $this->assertEquals(Cart::getTotalCost(), 0);
     Cart::addItem($item);
     Cart::addItem($item2);
     Cart::addItem($item);
     $this->assertEquals(Cart::getItems()->count(), 2);
     $this->assertEquals(Cart::getTotalCost(), $item->getPrice() * 2 + $item2->getPrice());
     Cart::removeItems(['name' => $item->getName()]);
     $this->assertEquals(Cart::getItems()->count(), 1);
     $this->assertEquals(Cart::getTotalCost(), $item2->getPrice());
 }
开发者ID:KeepCalmAndPraiseTheSun,项目名称:werashop,代码行数:19,代码来源:CartTest.php

示例3: save

 public function save()
 {
     if ($isnew = !$this->id) {
         $cart = new Cart($ctx = Context::last());
         $this->orderdetails = $cart->getItems();
     } elseif (array_key_exists('orderdetails', (array) $this->olddata)) {
         $this->orderdetails = $this->olddata['orderdetails'];
     }
     if (empty($this->orderdetails)) {
         throw new ForbiddenException(t('Не удалось оформить заказ: ' . 'ваша корзина пуста. Возможно, вы его уже оформили?'));
     }
     $res = parent::save();
     if ($isnew) {
         $this->sendEmail($this->email, 'invoice');
         $this->sendEmail($ctx->config->get('modules/cart/email'), 'notification');
         $cart->setItems(array());
     }
     return $res;
 }
开发者ID:umonkey,项目名称:molinos-cms,代码行数:19,代码来源:node.order.php

示例4: isItemInCart

 function isItemInCart($accID)
 {
     $items = Cart::getItems();
     return isset($items[$accID]);
 }
开发者ID:pankajit,项目名称:carumba,代码行数:5,代码来源:mod.Cart_.php

示例5: update

 public function update(Cart $cart)
 {
     echo var_export($cart->getItems(), true) . PHP_EOL;
 }
开发者ID:JJmaz,项目名称:dp,代码行数:4,代码来源:LoggingListener.php

示例6: fetchItems

 /**
  * @return List<Product>
  */
 public function fetchItems()
 {
     return $this->cart->getItems();
 }
开发者ID:keniel123,项目名称:comp2140,代码行数:7,代码来源:Account.php

示例7: checkout


//.........这里部分代码省略.........
             $post->add_rules('cc_type', 'required');
             $post->add_rules('cc_number', 'required', array($valid, 'credit_card'));
             $post->add_rules('cc_cvv', 'required', 'length[3,4]', array($valid, 'digit'));
             $post->add_rules('cc_exp_month', 'required');
             $post->add_rules('cc_exp_year', 'required');
             if (isset($_POST['order']['cc_exp_month']) && isset($_POST['order']['cc_exp_year'])) {
                 $post->add_callbacks('cc_exp_year', array($this, '_validate_cc_exp_date'));
             }
             $post->pre_filter('trim');
             if ($post->validate()) {
                 $cart = new Cart('shopping_cart');
                 //order data array
                 $order_arr = array_merge($_SESSION['order'], $_POST['order']);
                 $full_cc_number = $order_arr['cc_number'];
                 $order_arr['cc_number'] = substr($order_arr['cc_number'], -4);
                 $order_arr['promo_discount'] = $cart->getDiscount($order_arr['promo_code']);
                 $order_arr['subtotal'] = $cart->getTotal();
                 $order_arr['tax'] = $cart->getTax();
                 //process payment
                 include 'merchants/firstdata.class.php';
                 $merchant = new FirstData();
                 //billing info
                 $merchant->name = $order_arr['first_name'] . ' ' . $order_arr['last_name'];
                 $merchant->company = $order_arr['company'];
                 $merchant->address = $order_arr['address'];
                 $merchant->address2 = $order_arr['address2'];
                 $merchant->city = $order_arr['city'];
                 $merchant->state = $order_arr['state'];
                 $merchant->country = $order_arr['country'];
                 $merchant->phone = $order_arr['phone'];
                 $merchant->fax = $order_arr['fax'];
                 $merchant->email = $order_arr['email'];
                 $merchant->zip = $order_arr['zip'];
                 //shipping info
                 $merchant->ship_name = $order_arr['ship_first_name'] . ' ' . $order_arr['ship_last_name'];
                 $merchant->ship_address = $order_arr['ship_address'];
                 $merchant->ship_saddress2 = $order_arr['ship_address2'];
                 $merchant->ship_city = $order_arr['ship_city'];
                 $merchant->ship_state = $order_arr['ship_state'];
                 $merchant->ship_country = $order_arr['ship_country'];
                 $merchant->ship_zip = $order_arr['ship_zip'];
                 //payment info
                 $merchant->cc_number = $full_cc_number;
                 $merchant->cc_exp_month = $order_arr['cc_exp_month'];
                 $merchant->cc_exp_year = substr($order_arr['cc_exp_year'], -2);
                 $merchant->cc_cvv = $order_arr['cc_cvv'];
                 $merchant->subtotal = $order_arr['subtotal'];
                 $merchant->shipping = 0;
                 $merchant->tax = $order_arr['tax'];
                 $merchant->total = $order_arr['subtotal'] + $order_arr['tax'] - $order_arr['promo_discount'];
                 // set to GOOD for test or LIVE
                 $merchant->result = 'LIVE';
                 $merchant_success = false;
                 $result = $merchant->sale();
                 if ($result['r_approved'] == "APPROVED") {
                     $merchant_success = true;
                 }
                 //merchant error
                 if (!$merchant_success) {
                     $errors = $post->errors();
                     $this->set_flash($result['r_error'], 'error');
                     $output = $this->_checkout_step_2($_POST, $errors);
                 } else {
                     //save order to database
                     $record = Record::insert('ecommerce_order', $order_arr);
                     $order_id = Record::lastInsertId();
                     //save order items to database
                     foreach ($cart->getItems() as $variant_id => $quantity) {
                         //get variant data
                         $variant = Record::findByIdFrom('ProductVariant', $variant_id);
                         $variant->order_id = $order_id;
                         $variant->quantity = $quantity;
                         $variant_arr = (array) $variant;
                         //remove unneeded fields
                         unset($variant_arr['id']);
                         unset($variant_arr['created_on']);
                         unset($variant_arr['updated_on']);
                         unset($variant_arr['position']);
                         //insert
                         $record = Record::insert('ecommerce_order_variant', $variant_arr);
                     }
                     //save log
                     $this->_insert_log('Order <a href="' . get_url('plugin/ecommerce/order_show/' . $order_id) . '">' . $order_id . '</a> was placed.');
                     //send emails to client and buyer
                     $this->_send_order_email('info@emedamerica.com', $order_id, $order_arr, $variant_arr);
                     $this->_send_order_email($order_arr['email'], $order_id, $order_arr, $variant_arr);
                     //success
                     $this->set_flash('Thank you for your order. You will receive a confirmation email shortly.', 'success');
                     //clear cart and order session
                     unset($_SESSION['order']);
                     unset($_SESSION['Cart']);
                 }
             } else {
                 $errors = $post->errors();
                 $output = $this->_checkout_step_2($_POST, $errors);
             }
         }
     }
     return $output;
 }
开发者ID:shuhrat,项目名称:frog_ecommerce,代码行数:101,代码来源:EcommerceController.php

示例8: update

 public function update(Cart $cart)
 {
     echo '<pre>';
     var_dump($cart->getItems());
     echo '</pre>';
 }
开发者ID:th1209,项目名称:php_design_pattern,代码行数:6,代码来源:observer.php


注:本文中的Cart::getItems方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。