本文整理汇总了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();
}
示例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());
}
示例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;
}
示例4: isItemInCart
function isItemInCart($accID)
{
$items = Cart::getItems();
return isset($items[$accID]);
}
示例5: update
public function update(Cart $cart)
{
echo var_export($cart->getItems(), true) . PHP_EOL;
}
示例6: fetchItems
/**
* @return List<Product>
*/
public function fetchItems()
{
return $this->cart->getItems();
}
示例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;
}
示例8: update
public function update(Cart $cart)
{
echo '<pre>';
var_dump($cart->getItems());
echo '</pre>';
}