本文整理汇总了PHP中Cart类的典型用法代码示例。如果您正苦于以下问题:PHP Cart类的具体用法?PHP Cart怎么用?PHP Cart使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Cart类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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');
}
示例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);
}
示例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');
}
示例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;
}
}
示例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;
}
示例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'];
}
}
示例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
}
}
示例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);
}
示例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;
}
}
示例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');
}
}
示例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;
}
示例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]);
}
}
}
示例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');
}
示例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'));
}
示例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);
}