本文整理汇总了PHP中Cart类的典型用法代码示例。如果您正苦于以下问题:PHP Cart类的具体用法?PHP Cart怎么用?PHP Cart使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Cart类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: initContent
/**
* @see FrontController::initContent()
*/
public function initContent()
{
parent::initContent();
$id_cart = Tools::GetValue('id_cart');
$cart = new Cart((int) $id_cart);
$liqpay = new Liqpay();
$total = $cart->getOrderTotal(true, 3);
$liqpay->validateOrder(intval($cart->id), Configuration::get('PS_OS_PREPARATION'), $total, $liqpay->displayName);
$currency = new Currency((int) $cart->id_currency);
$private_key = Configuration::get('LIQPAY_PRIVATE_KEY');
$public_key = Configuration::get('LIQPAY_PUBLIC_KEY');
$amount = number_format($cart->getOrderTotal(true, Cart::BOTH), 1, '.', '');
$currency = $currency->iso_code == 'RUR' ? 'RUB' : $currency->iso_code;
$order_id = '000' . $id_cart;
$description = 'Order #' . $order_id;
$result_url = 'http://' . htmlspecialchars($_SERVER['HTTP_HOST'], ENT_COMPAT, 'UTF-8') . __PS_BASE_URI__ . 'index.php?controller=history';
$server_url = 'http://' . htmlspecialchars($_SERVER['HTTP_HOST'], ENT_COMPAT, 'UTF-8') . $liqpay->getPath() . 'validation.php';
$type = 'buy';
$version = '3';
$language = Configuration::get('PS_LOCALE_LANGUAGE') == 'en' ? 'en' : 'ru';
$data = base64_encode(json_encode(array('version' => $version, 'public_key' => $public_key, 'amount' => $amount, 'currency' => $currency, 'description' => $description, 'order_id' => $order_id, 'type' => $type, 'language' => $language)));
$signature = base64_encode(sha1($private_key . $data . $private_key, 1));
$this->context->smarty->assign(compact('data', 'signature'));
$this->setTemplate('redirect.tpl');
}
开发者ID:litalex,项目名称:plugin-prestashop,代码行数:28,代码来源:redirect.php
示例2: showCartAction
/**
* @param Request $request
* @return string
* @throws Exception
*/
public function showCartAction(Request $request)
{
$cart = new Cart();
$productsId = $cart->getProducts();
$args = array('productsId' => $productsId);
return $this->render('cart', $args);
}
开发者ID:Ro911,项目名称:MVC,代码行数:12,代码来源:BookController.php
示例3: initContent
public function initContent()
{
parent::initContent();
$params = KwixoURLCallFrontController::ManageUrlCall();
$payment_ok = $params['payment_status'];
$errors = $params['errors'];
$id_order = $params['id_order'];
if ($id_order != false) {
$order = new Order($id_order);
$cart = new Cart($order->id_cart);
$products = $cart->getProducts();
$amount = $order->total_paid_tax_incl;
$total_shipping = $order->total_shipping;
} else {
$products = false;
$amount = false;
$total_shipping = false;
}
$link = new Link();
$this->context->smarty->assign('payment_ok', $payment_ok);
$this->context->smarty->assign('errors', $errors);
$this->context->smarty->assign('amount', $amount);
$this->context->smarty->assign('total_shipping', $total_shipping);
$this->context->smarty->assign('products', $products);
$this->context->smarty->assign('path_order', $link->getPageLink('order', true));
$this->context->smarty->assign('path_history', $link->getPageLink('history', true));
$this->context->smarty->assign('path_contact', $link->getPageLink('contact', true));
$this->setTemplate('urlcall.tpl');
}
开发者ID:ventsiwad,项目名称:presta_addons,代码行数:29,代码来源:MyUrlCallFrontController15.php
示例4: login
public function login()
{
$conn = Db::connect();
$sql = 'SELECT user_id FROM users ' . ' WHERE email = ? AND password = ?';
$email = $conn->real_escape_string($_POST['email']);
$password = md5($_POST['password']);
$statement = $conn->prepare($sql);
$statement->bind_param('ss', $email, $password);
$statement->execute();
$statement->bind_result($userId);
$statement->fetch();
if ($userId == NULL) {
return false;
} else {
session_start();
$_SESSION['user_id'] = $userId;
if (isset($_SESSION['cart']) && $_SESSION['cart'] != []) {
require_once '../app/models/Cart.php';
$cart = new Cart();
foreach ($_SESSION['cart'] as $product_id => $value) {
$cart->addProductToCart($product_id, $_SESSION['cart'][$product_id]['cart_quantity']);
}
}
return true;
}
}
开发者ID:matthewleighton,项目名称:online_shop,代码行数:26,代码来源:sessions_helper.php
示例5: updateProductsTax
public static function updateProductsTax(AvalaraTax $avalaraModule, Cart $cart, $id_address, $region, $taxable = true)
{
$p = array();
foreach ($cart->getProducts() as $product) {
$avalaraProducts = array('id_product' => (int) $product['id_product'], 'name' => $product['name'], 'description_short' => $product['description_short'], 'quantity' => 1, 'total' => (double) 1000000, 'tax_code' => $taxable ? $avalaraModule->getProductTaxCode((int) $product['id_product']) : 'NT');
$p[] = $avalaraProducts;
// Call Avalara
$getTaxResult = $avalaraModule->getTax(array($avalaraProducts), array('type' => 'SalesOrder', 'DocCode' => 1, 'taxable' => $taxable));
// Store the taxrate in cache
// If taxrate exists (but it's outdated), then update, else insert (REPLACE INTO)
if (isset($getTaxResult['TotalTax']) && isset($getTaxResult['TotalAmount'])) {
$total_tax = $getTaxResult['TotalTax'];
$total_amount = $getTaxResult['TotalAmount'];
if ($total_amount == 0) {
$db_rate = 0;
} else {
$db_rate = (double) ($total_tax * 100 / $total_amount);
}
Db::getInstance()->Execute('REPLACE INTO `' . _DB_PREFIX_ . 'avalara_product_cache` (`id_product`, `tax_rate`, `region`, `update_date`, `id_address`)
VALUES (' . (int) $product['id_product'] . ', ' . $db_rate . ',
\'' . ($region ? pSQL($region) : '') . '\', \'' . date('Y-m-d H:i:s') . '\', ' . (int) $cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')} . ')');
}
}
return $p;
}
开发者ID:alex974,项目名称:prestashop-avalaratax,代码行数:25,代码来源:CacheTools.php
示例6: postProcess
public function postProcess()
{
$sid = Configuration::get('TWOCHECKOUTPP_SID');
$secret_word = Configuration::get('TWOCHECKOUTPP_SECRET');
$credit_card_processed = $_REQUEST['credit_card_processed'];
$order_number = $_REQUEST['order_number'];
$cart_id = $_REQUEST['merchant_order_id'];
$cart = new Cart($cart_id);
$checkout = new twocheckoutpp();
if (Configuration::get('TWOCHECKOUTPP_CURRENCY') > 0) {
$amount = number_format($cart->getOrderTotal(true, 3), 2, '.', '');
$currency_from = Currency::getCurrency($cart->id_currency);
$currency_to = Currency::getCurrency(Configuration::get('TWOCHECKOUTPP_CURRENCY'));
$amount = Tools::ps_round($amount / $currency_from['conversion_rate'], 2);
$total = number_format(Tools::ps_round($amount *= $currency_to['conversion_rate'], 2), 2, '.', '');
} else {
$total = number_format($cart->getOrderTotal(true, 3), 2, '.', '');
}
//Check the hash
$compare_string = $secret_word . $sid . $order_number . $total;
$compare_hash1 = strtoupper(md5($compare_string));
$compare_hash2 = $_REQUEST['key'];
if ($compare_hash1 == $compare_hash2) {
$customer = new Customer($cart->id_customer);
$total = (double) $cart->getOrderTotal(true, Cart::BOTH);
$checkout->validateOrder($cart_id, _PS_OS_PAYMENT_, $total, $checkout->displayName, '', array(), NULL, false, $customer->secure_key);
$order = new Order($checkout->currentOrder);
Tools::redirect('index.php?controller=order-confirmation&id_cart=' . (int) $cart->id . '&id_module=' . (int) $this->module->id . '&id_order=' . $checkout->currentOrder);
} else {
echo 'Hash Mismatch! Please contact the seller directly for assistance.</br>';
echo 'Total: ' . $total . '</br>';
echo '2CO Total: ' . $_REQUEST['total'];
}
}
开发者ID:stefanikolov,项目名称:prestashop-2checkout-api,代码行数:34,代码来源:validation.php
示例7: postProcess
/**
* @see FrontController::postProcess()
*/
public function postProcess()
{
parse_str($_POST['optData'], $optData);
$id_cart = (int) $optData['cartId'];
$cart = new Cart($id_cart);
if ($cart->id_customer == 0 || $cart->id_address_delivery == 0 || $cart->id_address_invoice == 0 || !$this->module->active) {
die('Cannot create order for this cart.');
}
$customer = new Customer($cart->id_customer);
if (!Validate::isLoadedObject($customer)) {
die('No customer for this order.');
}
$currency = new Currency((int) $cart->id_currency);
$paid_amount = $_POST['amount'];
$order_amount = $cart->getOrderTotal(true, Cart::BOTH);
$apiHash = $_SERVER['HTTP_API_HASH'];
$query = http_build_query($_POST);
$hash = hash_hmac("sha512", $query, $this->module->secret_key);
if ($apiHash == $hash && $paid_amount == $order_amount) {
//success
$this->module->validateOrder($cart->id, Configuration::get('PS_OS_PAYMENT'), $paid_amount, $this->module->displayName, 'Invoice Code: ' . $_POST['invoiceCode'], array(), (int) $currency->id, false, $customer->secure_key);
} else {
//failed transaction
}
}
开发者ID:inpay,项目名称:InPay-prestashop-plugin,代码行数:28,代码来源:validation.php
示例8: testGetDefaultCardHandler
function testGetDefaultCardHandler()
{
$cart = new Cart(1, $h = null);
$h = $cart->getCartHandler();
$this->assertIsA($h, CART_DEFAULT_HANDLER_TYPE . 'CartHandler');
$this->assertEqual($h->getCartId(), 1);
}
开发者ID:BackupTheBerlios,项目名称:limb-svn,代码行数:7,代码来源:CartTest.class.php
示例9: create
public function create(User $user)
{
$cart = new Cart();
if (isset($_SESSION['id'])) {
$set = $cart->setUser($user);
if ($set === true) {
$set = $cart->setStatus(1);
if ($set === true) {
$idUser = intval($cart->getUser()->getId());
$status = intval($cart->getStatus());
$query = "INSERT INTO cart (id_user, status) VALUES (" . $idUser . ", " . $status . ")";
$result = $this->database->exec($query);
if ($result) {
$id = $this->database->lastInsertId();
if ($id) {
return $this->findById($id);
} else {
throw new Exception("Catastrophe serveur.");
}
} else {
throw new Exception("Catastrophe base de données.");
}
} else {
throw new Exception($set);
}
} else {
throw new Exception($set);
}
} else {
$_SESSION['cartStatus'] = 1;
}
}
开发者ID:CreepingPanda,项目名称:FennecPlusUltra,代码行数:32,代码来源:CartManager.class.php
示例10: postProcess
/**
* Do whatever you have to before redirecting the customer on the website of your payment processor.
*/
public function postProcess()
{
/**
* Oops, an error occured.
*/
if (Tools::getValue('action') == 'error') {
return $this->displayError('An error occurred while trying to redirect the customer');
} else {
//First solution to know if refreshed page: http://stackoverflow.com/a/6127748
$refreshButtonPressed = isset($_SERVER['HTTP_CACHE_CONTROL']) && $_SERVER['HTTP_CACHE_CONTROL'] === 'max-age=0';
$result = $this->module->callToRest('GET', '/orders?mid=' . Context::getContext()->cart->id, null, false);
$result['response'] = json_decode($result['response'], true);
if ($result['code'] == '200' && isset($result['response']['results'][0]['id']) && !$refreshButtonPressed) {
//The cart exists on Aplazame, we try to send with another ID
$oldCart = new Cart(Context::getContext()->cart->id);
$data = $oldCart->duplicate();
if ($data['success']) {
$cart = $data['cart'];
Context::getContext()->cart = $cart;
CartRule::autoAddToCart(Context::getContext());
Context::getContext()->cookie->id_cart = $cart->id;
} else {
$this->module->logError('Error: Cannot duplicate cart ' . Context::getContext()->cart->id);
}
}
$this->context->smarty->assign(array('cart_id' => Context::getContext()->cart->id, 'secure_key' => Context::getContext()->customer->secure_key, 'aplazame_order_json' => json_encode($this->module->getCheckoutSerializer(0, Context::getContext()->cart->id), 128), 'aplazame_version' => ConfigurationCore::get('APLAZAME_API_VERSION', null), 'aplazame_url' => Configuration::get('APLAZAME_API_URL', null), 'aplazame_mode' => Configuration::get('APLAZAME_LIVE_MODE', null) ? 'false' : 'true'));
return $this->setTemplate('redirect.tpl');
}
}
开发者ID:jgermade,项目名称:prestashop,代码行数:32,代码来源:redirect.php
示例11: getItemsFromCart
/**
* Returns cart items in a format useful for the
* API request
*
* Also adds discount as a cart item, since this is
* how Paypal expects to receive discounts
*
* @param Cart $cart
* @return array
*/
private function getItemsFromCart(Cart $cart)
{
$items = array();
foreach($cart->getProducts() as $product)
{
$item = new stdClass();
$item->name = $product->title;
$item->number = $product->sku;
$item->description = substr($product->short_description, 0, 127);
$item->amount = ShopDisplay::numberFormat($product->price);
$item->quantity = $product->quantity;
$items[] = $item;
}
if($cart->getDiscountAmount() > 0)
{
$item = new stdClass();
$item->name = 'Discount';
$item->description = $cart->getDiscountName();
$item->amount = -1 * $cart->getDiscountAmount();
$item->quantity = 1;
$items[] = $item;
}
return $items;
}
开发者ID:haegyung,项目名称:xe-module-shop,代码行数:35,代码来源:PaypalExpressCheckout.php
示例12: textRecord
function textRecord(Product $product, Cart $cart)
{
global $errors;
if (!($fieldIds = $product->getCustomizationFieldIds())) {
return false;
}
$authorizedTextFields = array();
foreach ($fieldIds as $fieldId) {
if ($fieldId['type'] == _CUSTOMIZE_TEXTFIELD_) {
$authorizedTextFields[intval($fieldId['id_customization_field'])] = 'textField' . intval($fieldId['id_customization_field']);
}
}
$indexes = array_flip($authorizedTextFields);
foreach ($_POST as $fieldName => $value) {
if (in_array($fieldName, $authorizedTextFields) and !empty($value)) {
if (!Validate::isMessage($value)) {
$errors[] = Tools::displayError('Invalid message');
} else {
$cart->addTextFieldToProduct(intval($product->id), $indexes[$fieldName], $value);
}
} elseif (in_array($fieldName, $authorizedTextFields) and empty($value)) {
$cart->deleteTextFieldFromProduct(intval($product->id), $indexes[$fieldName]);
}
}
}
开发者ID:vincent,项目名称:theinvertebrates,代码行数:25,代码来源:product.php
示例13: initContent
public function initContent()
{
$payu = new PayU();
$id_cart = Tools::getValue('id_cart');
$id_payu_session = $this->context->cookie->__get('payu_order_id');
if (Tools::getValue('error')) {
Tools::redirect('order.php?error=' . Tools::getValue('error'), __PS_BASE_URI__, null, 'HTTP/1.1 301 Moved Permanently');
}
$payu->id_cart = $id_cart;
$payu->payu_order_id = $id_payu_session;
$order_payment = $payu->getOrderPaymentBySessionId($payu->payu_order_id);
$id_order = (int) $order_payment['id_order'];
$payu->id_cart = (int) $order_payment['id_cart'];
// if order not validated yet
$cart_id = $payu->id_cart;
if ($id_order == 0 && $order_payment['status'] == PayU::PAYMENT_STATUS_NEW) {
$cart = new Cart($payu->id_cart);
$cart_id = $cart->id;
$payu->validateOrder($cart->id, (int) Configuration::get('PAYU_PAYMENT_STATUS_PENDING'), $cart->getOrderTotal(true, Cart::BOTH), $payu->displayName, 'PayU cart ID: ' . $cart_id . ', sessionId: ' . $payu->payu_order_id, null, (int) $cart->id_currency, false, $cart->secure_key, Context::getContext()->shop->id ? new Shop((int) Context::getContext()->shop->id) : null);
$payu->id_order = $payu->current_order = $payu->{'currentOrder'};
$payu->updateOrderPaymentStatusBySessionId(PayU::PAYMENT_STATUS_INIT);
}
$id_order = $payu->getOrderIdBySessionId($id_payu_session);
if (!empty($id_order)) {
$payu->id_order = $id_order;
$payu->updateOrderData();
}
Tools::redirect('index.php?controller=order-confirmation&id_cart=' . $cart_id, __PS_BASE_URI__, null, 'HTTP/1.1 301 Moved Permanently');
}
开发者ID:bonekost,项目名称:plugin_prestashop,代码行数:29,代码来源:success.php
示例14: onGetSimple
protected function onGetSimple(array $options)
{
$cart = new Cart($this->ctx);
$result = $cart->getXML();
$result .= $cart->getConfigXML();
return html::wrap('cart', $result, array('mode' => 'simple'));
}
开发者ID:umonkey,项目名称:molinos-cms,代码行数:7,代码来源:widget.cart.php
示例15: testCreateInitPayment
public function testCreateInitPayment()
{
$cart = new Cart(new Currency(Currency::CZK));
$cart->addItem('Nákup na vasobchodcz', 1, 1789600, 'Lenovo ThinkPad Edge E540');
$cart->addItem('Poštovné', 1, 0, 'Doprava PPL');
$request = $this->requestFactory->createInitPayment('5547', new PayOperation(PayOperation::PAYMENT), new PayMethod(PayMethod::CARD), true, 'https://vasobchod.cz/gateway-return', new HttpMethod(HttpMethod::POST), $cart, 'Nákup na vasobchod.cz (Lenovo ThinkPad Edge E540, Doprava PPL)', 'some-base64-encoded-merchant-data', '123', new Language(Language::CZ), 1800, 1, 1);
$this->assertInstanceOf(InitPaymentRequest::class, $request);
}
开发者ID:slevomat,项目名称:csob-gateway,代码行数:8,代码来源:RequestFactoryTest.php
示例16: get_cart
function get_cart()
{
$this->doNotRenderHeader = 1;
$m = new Cart();
$data = $m->getCartInfo();
$this->assign('message', $data);
$this->setReturnType('message');
}
开发者ID:koery,项目名称:Vcanbuy,代码行数:8,代码来源:SearchController.class.php
示例17: initContent
public function initContent()
{
parent::initContent();
$log_on = Configuration::get('YA_ORG_LOGGING_ON');
if (Tools::getValue('label')) {
$data = explode('_', Tools::getValue('label'));
} else {
$data = explode('_', Tools::getValue('customerNumber'));
}
if (!empty($data) && isset($data[1])) {
$ordernumber = $data['1'];
$this->context->smarty->assign('ordernumber', $ordernumber);
$this->context->smarty->assign('time', date('Y-m-d H:i:s '));
if (!$ordernumber) {
if ($log_on) {
$this->module->logSave('yakassa_success: Error ' . $this->module->l('Cart number is not specified'));
}
$this->setTemplate('error.tpl');
} else {
$cart = new Cart((int) $ordernumber);
$qty = $cart->nbProducts();
$this->context->smarty->assign('nbProducts', $qty);
if (!Validate::isLoadedObject($cart) || $qty < 1) {
if ($log_on) {
$this->module->logSave('yakassa_success: Error ' . $this->module->l('Shopping cart does not exist'));
}
$this->setTemplate('error.tpl');
} else {
$ordernumber = (int) $cart->id;
if (!$ordernumber) {
if ($log_on) {
$this->module->logSave('yakassa_success: Error ' . $this->module->l('Order number is not specified'));
}
$this->setTemplate('error.tpl');
} else {
$order = new Order((int) Order::getOrderByCartId($cart->id));
$customer = new Customer((int) $order->id_customer);
if ($order->hasBeenPaid()) {
if ($log_on) {
$this->module->logSave('yakassa_success: #' . $order->id . ' ' . $this->module->l('Order paid'));
}
Tools::redirectLink(__PS_BASE_URI__ . 'order-confirmation.php?key=' . $customer->secure_key . '&id_cart=' . (int) $order->id_cart . '&id_module=' . (int) $this->module->id . '&id_order=' . (int) $order->id);
} else {
if ($log_on) {
$this->module->logSave('yakassa_success: #' . $order->id . ' ' . $this->module->l('Order wait payment'));
}
$this->setTemplate('waitingPayment.tpl');
}
}
}
}
} else {
if ($log_on) {
$this->module->logSave('yakassa_success: Error ' . $this->module->l('Cart number is not specified'));
}
$this->setTemplate('error.tpl');
}
}
开发者ID:KPG1,项目名称:yandex-money-cms-prestashop,代码行数:58,代码来源:success.php
示例18: createOrder
/**
* @param $order_payment
* @param $payu
* @param $response
* @return mixed
*/
private function createOrder($order_payment, Payu $payu, $response)
{
$cart = new Cart($order_payment['id_cart']);
$payu->validateOrder($cart->id, (int) Configuration::get('PAYU_PAYMENT_STATUS_PENDING'), $cart->getOrderTotal(true, Cart::BOTH), $payu->displayName, 'PayU cart ID: ' . $cart->id . ', orderId: ' . $payu->payu_order_id, null, (int) $cart->id_currency, false, $cart->secure_key, Context::getContext()->shop->id ? new Shop((int) Context::getContext()->shop->id) : null);
$id_order = $payu->current_order = $payu->currentOrder;
SimplePayuLogger::addLog('notification', __FUNCTION__, 'Status zamówienia PayU: ' . PayU::PAYMENT_STATUS_NEW, $response->order->orderId);
$payu->updateOrderPaymentStatusBySessionId(PayU::PAYMENT_STATUS_INIT);
return $id_order;
}
开发者ID:bonekost,项目名称:plugin_prestashop,代码行数:15,代码来源:notification.php
示例19: delete
public function delete()
{
if (parent::delete()) {
$cart = new Cart($this->id_cart);
$cart->status = Cart::IS_CLOSE;
return $cart->update();
}
return false;
}
开发者ID:yiuked,项目名称:tmcart,代码行数:9,代码来源:Order.php
示例20: add_items_to_cart
function add_items_to_cart($id, $count)
{
if (empty($_SESSION['simple_cart']) || !isset($_SESSION['simple_cart'])) {
$c = new Cart();
$c->add_item($id, $count);
$_SESSION['simple_cart'] = $c;
} else {
$_SESSION['simple_cart']->add_item($id, $count);
}
}
开发者ID:nitzanb,项目名称:Simple-Cart,代码行数:10,代码来源:simple_cart.php
注:本文中的Cart类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论