function hookRightColumn($params) { global $smarty, $category_path; $category_path_ids = array(); foreach ($category_path as $cat) { $category_path_ids[] = $cat['id_category']; } $currency = new Currency(intval($params['cookie']->id_currency)); $bestsellers = ProductSale::getBestSalesLight(intval($params['cookie']->id_lang), 0, 25); $best_sellers = array(); $nr = 0; foreach ($bestsellers as $bestseller) { if ($nr >= 5) { break; } $display = false; foreach (Product::getIndexedCategories($bestseller['id_product']) as $row) { if (in_array($row['id_category'], $category_path_ids)) { $display = true; break; } } if ($display) { $bestseller['price'] = Tools::displayPrice(Product::getPriceStaticLC(intval($bestseller['id_product'])), $currency, false, false); $best_sellers[] = $bestseller; $nr += 1; } } $smarty->assign(array('best_sellers' => $best_sellers, 'mediumSize' => Image::getSize('medium'), 'static_token' => Tools::getToken(false))); return $this->display(__FILE__, 'blockbestsellers.tpl'); }
public function getList($id_lang, $orderBy = NULL, $orderWay = NULL, $start = 0, $limit = NULL) { $orderByPriceFinal = empty($orderBy) ? Tools::getValue($this->table . 'Orderby', 'id_' . $this->table) : $orderBy; $orderWayPriceFinal = empty($orderWay) ? Tools::getValue($this->table . 'Orderway', 'ASC') : $orderWay; if ($orderByPriceFinal == 'price_final') { $orderBy = 'id_' . $this->table; $orderWay = 'ASC'; } parent::getList($id_lang, $orderBy, $orderWay, $start, $limit); /* update product quantity with attributes ...*/ if ($this->_list) { $nb = count($this->_list); for ($i = 0; $i < $nb; $i++) { Attribute::updateQtyProduct($this->_list[$i]); } /* update product final price */ for ($i = 0; $i < $nb; $i++) { //Product::getBasePriceStaticLC does not allways return an array. Added cast to array. $this->_list[$i] = array_merge($this->_list[$i], (array) Product::getBasePriceStaticLC($this->_list[$i]['id_product'], $id_product_attribute = NULL)); $this->_list[$i]['price_tmp'] = Product::getPriceStaticLC($this->_list[$i]['id_product'], $usetax = true, $id_product_attribute = NULL, $decimals = 6, $divisor = NULL, $only_reduc = false, $usereduc = true, $quantity = 1, $forceAssociatedTax = true); } } if ($orderByPriceFinal == 'price_final') { if (strtolower($orderWayPriceFinal) == 'desc') { uasort($this->_list, 'cmpPriceDesc'); } else { uasort($this->_list, 'cmpPriceAsc'); } } for ($i = 0; $this->_list and $i < $nb; $i++) { $this->_list[$i]['price_final'] = $this->_list[$i]['price_tmp']; unset($this->_list[$i]['price_tmp']); } }
function smartyAssigns(&$smarty, &$params) { global $errors; // Set currency if (!intval($params['cart']->id_currency)) { $currency = new Currency(intval($params['cookie']->id_currency)); } else { $currency = new Currency(intval($params['cart']->id_currency)); } if (!Validate::isLoadedObject($currency)) { $currency = new Currency(intval(Configuration::get('PS_DEFAULT_CURRENCY'))); } $products = $params['cart']->getProducts(true); foreach ($products as $k => $product) { $products[$k]['real_price'] = Product::getPriceStaticLC($product['id_product'], intval(Configuration::get('PS_PRICE_DISPLAY')) == 1 ? false : true, $product['id_product_attribute'], 6, NULL, false, true, $product['cart_quantity']) * $product['cart_quantity']; } $smarty->assign(array('products' => $products, 'customizedDatas' => Product::getAllCustomizedDatas(intval($params['cart']->id)), 'CUSTOMIZE_FILE' => _CUSTOMIZE_FILE_, 'CUSTOMIZE_TEXTFIELD' => _CUSTOMIZE_TEXTFIELD_, 'discounts' => $params['cart']->getDiscounts(false, true), 'nb_total_products' => $params['cart']->nbProducts(), 'shipping_cost' => Tools::displayPrice($params['cart']->getOrderTotalLC(intval(Configuration::get('PS_PRICE_DISPLAY')) == 1 ? false : true, 5), $currency, false, false), 'show_wrapping' => floatval($params['cart']->getOrderTotalLC(true, 6)) > 0 ? true : false, 'wrapping_cost' => Tools::displayPrice($params['cart']->getOrderTotalLC(intval(Configuration::get('PS_PRICE_DISPLAY')) == 1 ? false : true, 6), $currency, false, false), 'product_total' => Tools::displayPrice($params['cart']->getOrderTotalLC(intval(Configuration::get('PS_PRICE_DISPLAY')) == 1 ? false : true, 4), $currency, false, false), 'total' => Tools::displayPrice($params['cart']->getOrderTotalLC(intval(Configuration::get('PS_PRICE_DISPLAY')) == 1 ? false : true), $currency, false, false), 'id_carrier' => $params['cart']->id_carrier, 'ajax_allowed' => intval(Configuration::get('PS_BLOCK_CART_AJAX')) == 1 ? true : false)); if (sizeof($errors)) { $smarty->assign('errors', $errors); } if (isset($params['cookie']->ajax_blockcart_display)) { $smarty->assign('colapseExpandStatus', $params['cookie']->ajax_blockcart_display); } }
function getOrderTotalLC($withTaxes = true, $type = 3) { if (!$this->id) { return 0; } $type = intval($type); if (!in_array($type, array(1, 2, 3, 4, 5, 6, 7))) { die(Tools::displayError()); } // no shipping cost if is a cart with only virtuals products $virtual = $this->isVirtualCart(); if ($virtual and $type == 5) { return 0; } if ($virtual and $type == 3) { $type = 4; } $shipping_fees = ($type != 4 and $type != 7) ? $this->getOrderShippingCostLC(NULL, intval($withTaxes)) : 0; if ($type == 7) { $type = 1; } $products = $this->getProducts(); $order_total = 0; foreach ($products as $product) { $price = floatval(Product::getPriceStaticLC(intval($product['id_product']), $withTaxes, intval($product['id_product_attribute']), 6, NULL, false, true, $product['quantity'])); $total_price = $price * intval($product['quantity']); $order_total += $total_price; } $order_total_products = $order_total; if ($type == 2) { $order_total = 0; } // Wrapping Fees $wrapping_fees = 0; if ($this->gift) { $wrapping_fees = floatval(Configuration::get('PS_GIFT_WRAPPING_PRICE')); if (!$withTaxes) { $wrapping_fees_tax = new Tax(intval(Configuration::get('PS_GIFT_WRAPPING_TAX'))); $wrapping_fees /= 1 + floatval($wrapping_fees_tax->rate) / 100; } } if ($type != 1) { $discounts = array(); /* Firstly get all discounts, looking for a free shipping one (in order to substract shipping fees to the total amount) */ if ($discountIds = $this->getDiscounts(true)) { foreach ($discountIds as $id_discount) { $discount = new Discount(intval($id_discount['id_discount'])); if (Validate::isLoadedObject($discount)) { $discounts[] = $discount; if ($discount->id_discount_type == 3) { foreach ($products as $product) { $categories = Discount::getCategories($discount->id); if (count($categories)) { if (Product::idIsOnCategoryId($product['id_product'], $categories)) { if ($type == 2) { $order_total -= $shipping_fees; } $shipping_fees = 0; break; } } } } } } /* Secondly applying all vouchers to the correct amount */ foreach ($discounts as $discount) { if ($discount->id_discount_type != 3) { $order_total -= floatval($discount->getValue(sizeof($discounts), $order_total_products, $shipping_fees, $this->id, intval($withTaxes))); } } } } if ($type == 5) { return $shipping_fees; } if ($type == 6) { return $wrapping_fees; } if ($type == 3) { $order_total += $shipping_fees + $wrapping_fees; } if ($order_total < 0 and $type != 2) { return 0; } return floatval($order_total); }
public function hookNewOrder($params) { if (!$this->_merchant_order or empty($this->_merchant_mails)) { return; } // Getting differents vars $id_lang = intval(Configuration::get('PS_LANG_DEFAULT')); $currency = $params['currency']; $configuration = Configuration::getMultiple(array('PS_SHOP_EMAIL', 'PS_MAIL_METHOD', 'PS_MAIL_SERVER', 'PS_MAIL_USER', 'PS_MAIL_PASSWD', 'PS_SHOP_NAME')); $order = $params['order']; $customer = $params['customer']; $delivery = new Address(intval($order->id_address_delivery)); $invoice = new Address(intval($order->id_address_invoice)); $order_date_text = Tools::displayDate($order->date_add, intval($id_lang)); $carrier = new Carrier(intval($order->id_carrier)); $message = $order->getFirstMessage(); if (!$message or empty($message)) { $message = $this->l('No message'); } $itemsTable = ''; foreach ($params['cart']->getProducts() as $key => $product) { $unit_price = Product::getPriceStaticLC($product['id_product'], true, $product['id_product_attribute']); $price = Product::getPriceStaticLC($product['id_product'], true, $product['id_product_attribute'], 6, NULL, false, true, $product['quantity']); $itemsTable .= '<tr style="background-color:' . ($key % 2 ? '#DDE2E6' : '#EBECEE') . ';"> <td style="padding:0.6em 0.4em;">' . $product['reference'] . '</td> <td style="padding:0.6em 0.4em;"><strong>' . $product['name'] . (isset($product['attributes_small']) ? ' ' . $product['attributes_small'] : '') . '</strong></td> <td style="padding:0.6em 0.4em; text-align:right;">' . Tools::displayPrice($unit_price, $currency, false, false) . '</td> <td style="padding:0.6em 0.4em; text-align:center;">' . intval($product['quantity']) . '</td> <td style="padding:0.6em 0.4em; text-align:right;">' . Tools::displayPrice($price * $product['quantity'], $currency, false, false) . '</td> </tr>'; } foreach ($params['cart']->getDiscounts() as $discount) { $itemsTable .= '<tr style="background-color:#EBECEE;"> <td colspan="4" style="padding:0.6em 0.4em; text-align:right;">' . $this->l('Voucher code:') . ' ' . $discount['name'] . '</td> <td style="padding:0.6em 0.4em; text-align:right;">-' . Tools::displayPrice($discount['value_real'], $currency, false, false) . '</td> </tr>'; } if ($delivery->id_state) { $delivery_state = new State(intval($delivery->id_state)); } if ($invoice->id_state) { $invoice_state = new State(intval($invoice->id_state)); } // Filling-in vars for email $template = 'new_order'; $subject = $this->l('New order'); $templateVars = array('{firstname}' => $customer->firstname, '{lastname}' => $customer->lastname, '{email}' => $customer->email, '{delivery_company}' => $delivery->company, '{delivery_firstname}' => $delivery->firstname, '{delivery_lastname}' => $delivery->lastname, '{delivery_address1}' => $delivery->address1, '{delivery_address2}' => $delivery->address2, '{delivery_city}' => $delivery->city, '{delivery_postal_code}' => $delivery->postcode, '{delivery_country}' => $delivery->country, '{delivery_state}' => $delivery->id_state ? $delivery_state->name : '', '{delivery_phone}' => $delivery->phone, '{delivery_other}' => $delivery->other, '{invoice_company}' => $invoice->company, '{invoice_firstname}' => $invoice->firstname, '{invoice_lastname}' => $invoice->lastname, '{invoice_address2}' => $invoice->address2, '{invoice_address1}' => $invoice->address1, '{invoice_city}' => $invoice->city, '{invoice_postal_code}' => $invoice->postcode, '{invoice_country}' => $invoice->country, '{invoice_state}' => $invoice->id_state ? $invoice_state->name : '', '{invoice_phone}' => $invoice->phone, '{invoice_other}' => $invoice->other, '{order_name}' => sprintf("%06d", $order->id), '{shop_name}' => Configuration::get('PS_SHOP_NAME'), '{date}' => $order_date_text, '{carrier}' => $carrier->name == '0' ? Configuration::get('PS_SHOP_NAME') : $carrier->name, '{payment}' => $order->payment, '{items}' => $itemsTable, '{total_paid}' => Tools::displayPrice($order->total_paid, $currency), '{total_products}' => Tools::displayPrice($order->getTotalProductsWithTaxes(), $currency), '{total_discounts}' => Tools::displayPrice($order->total_discounts, $currency), '{total_shipping}' => Tools::displayPrice($order->total_shipping, $currency), '{total_wrapping}' => Tools::displayPrice($order->total_wrapping, $currency), '{currency}' => $currency->sign, '{message}' => $message); $iso = Language::getIsoById(intval($id_lang)); if (file_exists(dirname(__FILE__) . '/mails/' . $iso . '/' . $template . '.txt') and file_exists(dirname(__FILE__) . '/mails/' . $iso . '/' . $template . '.html')) { Mail::Send($id_lang, $template, $subject, $templateVars, explode(self::__MA_MAIL_DELIMITOR__, $this->_merchant_mails), NULL, $configuration['PS_SHOP_EMAIL'], $configuration['PS_SHOP_NAME'], NULL, NULL, dirname(__FILE__) . '/mails/'); } }
public static function orderbyPrice(&$array, $orderWay) { foreach ($array as &$row) { $row['price_tmp'] = Product::getPriceStaticLC($row['id_product'], true, (isset($row['id_product_attribute']) and !empty($row['id_product_attribute'])) ? intval($row['id_product_attribute']) : NULL, 2); } if (strtolower($orderWay) == 'desc') { uasort($array, 'cmpPriceDesc'); } else { uasort($array, 'cmpPriceAsc'); } foreach ($array as &$row) { unset($row['price_tmp']); } }
/** * Validate an order in database * Function called from a payment module * * @param integer $id_cart Value * @param integer $id_order_state Value * @param float $amountPaid Amount really paid by customer (in the default currency) * @param string $paymentMethod Payment method (eg. 'Credit cart') * @param string $message Message to attach to order */ function validateOrder($id_cart, $id_order_state, $amountPaid, $paymentMethod = 'Unknown', $message = NULL, $extraVars = array(), $currency_special = NULL, $dont_touch_amount = false, $payment_reference = null) { global $currency; $cart = new Cart(intval($id_cart)); // Does order already exists ? if (Validate::isLoadedObject($cart) and $cart->OrderExists() === 0) { // Copying data from cart $order = new Order(); $order->id_carrier = intval($cart->id_carrier); $order->id_customer = intval($cart->id_customer); $order->id_address_invoice = intval($cart->id_address_invoice); $order->id_address_delivery = intval($cart->id_address_delivery); $vat_address = new Address(intval($order->id_address_delivery)); $id_zone = Address::getZoneById(intval($vat_address->id)); $order->id_currency = $currency_special ? intval($currency_special) : intval($cart->id_currency); $order->id_lang = intval($cart->id_lang); $order->id_cart = intval($cart->id); $customer = new Customer(intval($order->id_customer)); $order->secure_key = pSQL($customer->secure_key); $order->payment = Tools::substr($paymentMethod, 0, 32); if (isset($this->name)) { $order->module = $this->name; } $order->recyclable = $cart->recyclable; $order->gift = intval($cart->gift); $order->gift_message = $cart->gift_message; $currency = new Currency($order->id_currency); // Hm, if !dont_touch_amount, maybe we should // do something here, just can't see what? The // old code converted currency and chopped // decimals... $amountPaid = $amountPaid; $order->total_paid_real = $amountPaid; $order->total_products = $cart->getOrderTotalLC(false, 1); $order->total_discounts = abs($cart->getOrderTotalLC(true, 2)); $order->total_shipping = $cart->getOrderShippingCostLC(); $order->total_wrapping = abs($cart->getOrderTotalLC(true, 6)); $order->total_paid = $cart->getOrderTotalLC(true, 3); $logfile = "/srv/www/shp-debug-logging/" . date('Y-m-d_H:i:s') . '_' . md5(microtime(true)) . '.payment_module.php'; $fp = @fopen($logfile, 'w'); $LOGSTRING = print_r($cart, true); $LOGSTRING .= "----------------\n\n"; $LOGSTRING .= print_r($order, true); $LOGSTRING .= "----------------\n\n"; $LOGSTRING .= print_r($currency, true); fwrite($fp, $LOGSTRING); @fclose($fp); // Amount paid by customer is not the right one -> Status = payment error /* Some payment modules round to two decimals. We do so here aswell, to prevent payment error */ if (round($order->total_paid, 2) != round($order->total_paid_real, 2)) { $id_order_state = _PS_OS_ERROR_; } $order->payment_reference = $payment_reference; // Creating order if ($cart->OrderExists() === 0) { $result = $order->add(); } else { die(Tools::displayError('An order has already been placed using this cart')); } // Next ! if ($result and isset($order->id)) { // Optional message to attach to this order if (isset($message) and !empty($message)) { $msg = new Message(); $message = strip_tags($message, '<br>'); if (!Validate::isCleanHtml($message)) { $message = $this->l('Payment message is not valid, please check your module!'); } $msg->message = $message; $msg->id_order = intval($order->id); $msg->private = 1; $msg->add(); } // Insert products from cart into order_detail table $products = $cart->getProducts(); $productsList = ''; $db = Db::getInstance(); $query = 'INSERT INTO `' . _DB_PREFIX_ . 'order_detail` (`id_order`, `product_id`, `product_attribute_id`, `product_name`, `product_quantity`, `product_quantity_in_stock`, `product_price`, `product_quantity_discount`, `product_ean13`, `product_reference`, `product_supplier_reference`, `product_weight`, `tax_name`, `tax_rate`, `ecotax`, `download_deadline`, `download_hash`) VALUES '; $customizedDatas = Product::getAllCustomizedDatas(intval($order->id_cart)); Product::addCustomizationPrice($products, $customizedDatas); foreach ($products as $key => $product) { $productQuantity = intval(Product::getQuantity(intval($product['id_product']), isset($product['id_product_attribute']) ? intval($product['id_product_attribute']) : NULL)); $quantityInStock = $productQuantity - intval($product['quantity']) < 0 ? $productQuantity : intval($product['quantity']); if ($id_order_state != _PS_OS_CANCELED_ and $id_order_state != _PS_OS_ERROR_) { if ($id_order_state != _PS_OS_OUTOFSTOCK_ and (($updateResult = Product::updateQuantity($product)) === false or $updateResult === -1)) { $id_order_state = _PS_OS_OUTOFSTOCK_; $history = new OrderHistory(); $history->id_order = intval($order->id); $history->changeIdOrderState(_PS_OS_OUTOFSTOCK_, intval($order->id)); $history->addWithemail(); } Hook::updateQuantity($product, $order); } $price = Product::getPriceStaticLC(intval($product['id_product']), false, $product['id_product_attribute'] ? intval($product['id_product_attribute']) : NULL, 6, NULL, false, true, $product['quantity']); $price_wt = Product::getPriceStaticLC(intval($product['id_product']), true, $product['id_product_attribute'] ? intval($product['id_product_attribute']) : NULL, 6, NULL, false, true, $product['quantity']); // Add some informations for virtual products $deadline = '0000-00-00 00:00:00'; $download_hash = NULL; $productDownload = new ProductDownload(); if ($id_product_download = $productDownload->getIdFromIdProduct(intval($product['id_product']))) { $productDownload = new ProductDownload(intval($id_product_download)); $deadline = $productDownload->getDeadLine(); $download_hash = $productDownload->getHash(); } // Exclude VAT if (Tax::excludeTaxeOption()) { $product['tax'] = 0; $product['rate'] = 0; } else { $tax = Tax::getApplicableTax(intval($product['id_tax']), floatval($product['rate'])); } // Quantity discount $reduc = 0.0; if ($product['quantity'] > 1 and $qtyD = QuantityDiscount::getDiscountFromQuantity($product['id_product'], $product['quantity'])) { $reduc = QuantityDiscount::getValue($price_wt, $qtyD->id_discount_type, $qtyD->value); } // Query $query .= '(' . intval($order->id) . ', ' . intval($product['id_product']) . ', ' . (isset($product['id_product_attribute']) ? intval($product['id_product_attribute']) : 'NULL') . ', \'' . pSQL($product['name'] . ((isset($product['attributes']) and $product['attributes'] != NULL) ? ' - ' . $product['attributes'] : '')) . '\', ' . intval($product['quantity']) . ', ' . $quantityInStock . ', ' . floatval($price) . ', ' . floatval($reduc) . ', ' . (empty($product['ean13']) ? 'NULL' : '\'' . pSQL($product['ean13']) . '\'') . ', ' . (empty($product['reference']) ? 'NULL' : '\'' . pSQL($product['reference']) . '\'') . ', ' . (empty($product['supplier_reference']) ? 'NULL' : '\'' . pSQL($product['supplier_reference']) . '\'') . ', ' . floatval(array_key_exists('id_product_attribute', $product) ? $product['weight_attribute'] : $product['weight']) . ', \'' . (!$tax ? '' : pSQL($product['tax'])) . '\', ' . floatval($tax) . ', ' . floatval($product['ecotax']) . ', \'' . pSQL($deadline) . '\', \'' . pSQL($download_hash) . '\'),'; $priceWithTax = number_format($price * (($tax + 100) / 100), 2, '.', ''); $customizationQuantity = 0; if (isset($customizedDatas[$product['id_product']][$product['id_product_attribute']])) { $customizationQuantity = intval($product['customizationQuantityTotal']); $productsList .= '<tr style="background-color:' . ($key % 2 ? '#DDE2E6' : '#EBECEE') . ';"> <td style="padding:0.6em 0.4em;">' . $product['reference'] . '</td> <td style="padding:0.6em 0.4em;"><strong>' . $product['name'] . (isset($product['attributes_small']) ? ' ' . $product['attributes_small'] : '') . ' - ' . $this->l('Customized') . '</strong></td> <td style="padding:0.6em 0.4em; text-align:right;">' . Tools::displayPrice($price * ($tax + 100) / 100, $currency, false, false) . '</td> <td style="padding:0.6em 0.4em; text-align:center;">' . $customizationQuantity . '</td> <td style="padding:0.6em 0.4em; text-align:right;">' . Tools::displayPrice($customizationQuantity * $priceWithTax, $currency, false, false) . '</td> </tr>'; } if (!$customizationQuantity or intval($product['quantity']) > $customizationQuantity) { $productsList .= '<tr style="background-color:' . ($key % 2 ? '#DDE2E6' : '#EBECEE') . ';"> <td style="padding:0.6em 0.4em;">' . $product['reference'] . '</td> <td style="padding:0.6em 0.4em;"><strong>' . $product['name'] . (isset($product['attributes_small']) ? ' ' . $product['attributes_small'] : '') . '</strong></td> <td style="padding:0.6em 0.4em; text-align:right;">' . Tools::displayPrice($price * ($tax + 100) / 100, $currency, false, false) . '</td> <td style="padding:0.6em 0.4em; text-align:center;">' . (intval($product['quantity']) - $customizationQuantity) . '</td> <td style="padding:0.6em 0.4em; text-align:right;">' . Tools::displayPrice((intval($product['quantity']) - $customizationQuantity) * $priceWithTax, $currency, false, false) . '</td> </tr>'; } } // end foreach ($products) $query = rtrim($query, ','); $result = $db->Execute($query); // Insert discounts from cart into order_discount table $discounts = $cart->getDiscounts(); $discountsList = ''; foreach ($discounts as $discount) { $objDiscount = new Discount(intval($discount['id_discount'])); $value = $objDiscount->getValue(sizeof($discounts), $cart->getOrderTotalLC(true, 1), $order->total_shipping, $cart->id); $order->addDiscount($objDiscount->id, $objDiscount->name, $value); if ($id_order_state != _PS_OS_ERROR_ and $id_order_state != _PS_OS_CANCELED_) { $objDiscount->quantity = $objDiscount->quantity - 1; } $objDiscount->update(); $discountsList .= '<tr style="background-color:#EBECEE;"> <td colspan="4" style="padding:0.6em 0.4em; text-align:right;">' . $this->l('Voucher code:') . ' ' . $objDiscount->name . '</td> <td style="padding:0.6em 0.4em; text-align:right;">-' . Tools::displayPrice($value, $currency, false, false) . '</td> </tr>'; } // Specify order id for message $oldMessage = Message::getMessageByCartId(intval($cart->id)); if ($oldMessage) { $message = new Message(intval($oldMessage['id_message'])); $message->id_order = intval($order->id); $message->update(); } // Hook new order $orderStatus = new OrderState(intval($id_order_state)); if (Validate::isLoadedObject($orderStatus)) { Hook::newOrder($cart, $order, $customer, $currency, $orderStatus); foreach ($cart->getProducts() as $product) { if ($orderStatus->logable) { ProductSale::addProductSale($product['id_product'], $product['quantity']); } } } // Set order state in order history ONLY if the "out of stock" status has not been yet reached // If it has, a status changing has already been applied at that time if ($id_order_state != _PS_OS_OUTOFSTOCK_) { $new_history = new OrderHistory(); $new_history->id_order = intval($order->id); $new_history->changeIdOrderState(intval($id_order_state), intval($order->id)); $new_history->addWithemail(true, $extraVars); } // Send an e-mail to customer if ($id_order_state != _PS_OS_ERROR_ and $id_order_state != _PS_OS_CANCELED_ and $customer->id) { $invoice = new Address(intval($order->id_address_invoice)); $delivery = new Address(intval($order->id_address_delivery)); $carrier = new Carrier(intval($order->id_carrier)); $delivery_state = $delivery->id_state ? new State(intval($delivery->id_state)) : false; $invoice_state = $invoice->id_state ? new State(intval($invoice->id_state)) : false; $data = array('{firstname}' => $customer->firstname, '{lastname}' => $customer->lastname, '{email}' => $customer->email, '{delivery_company}' => $delivery->company, '{delivery_firstname}' => $delivery->firstname, '{delivery_lastname}' => $delivery->lastname, '{delivery_address1}' => $delivery->address1, '{delivery_address2}' => $delivery->address2, '{delivery_city}' => $delivery->city, '{delivery_postal_code}' => $delivery->postcode, '{delivery_country}' => $delivery->country, '{delivery_state}' => $delivery->id_state ? $delivery_state->name : '', '{delivery_phone}' => $delivery->phone, '{delivery_other}' => $delivery->other, '{invoice_company}' => $invoice->company, '{invoice_firstname}' => $invoice->firstname, '{invoice_lastname}' => $invoice->lastname, '{invoice_address2}' => $invoice->address2, '{invoice_address1}' => $invoice->address1, '{invoice_city}' => $invoice->city, '{invoice_postal_code}' => $invoice->postcode, '{invoice_country}' => $invoice->country, '{invoice_state}' => $invoice->id_state ? $invoice_state->name : '', '{invoice_phone}' => $invoice->phone, '{invoice_other}' => $invoice->other, '{order_name}' => sprintf("#%06d", intval($order->id)), '{date}' => Tools::displayDate(date('Y-m-d H:i:s'), intval($order->id_lang), 1), '{carrier}' => strval($carrier->name) != '0' ? $carrier->name : Configuration::get('PS_SHOP_NAME'), '{payment}' => $order->payment, '{products}' => $productsList, '{discounts}' => $discountsList, '{total_paid}' => Tools::displayPrice($order->total_paid, $currency, false, false), '{total_products}' => Tools::displayPrice($order->total_paid - $order->total_shipping - $order->total_wrapping + $order->total_discounts, $currency, false, false), '{total_discounts}' => Tools::displayPrice($order->total_discounts, $currency, false, false), '{total_shipping}' => Tools::displayPrice($order->total_shipping, $currency, false, false), '{total_wrapping}' => Tools::displayPrice($order->total_wrapping, $currency, false, false)); if (is_array($extraVars)) { $data = array_merge($data, $extraVars); } // Join PDF invoice if (intval(Configuration::get('PS_INVOICE')) and Validate::isLoadedObject($orderStatus) and $orderStatus->invoice and $order->invoice_number) { $fileAttachment['content'] = PDF::invoice($order, 'S'); $fileAttachment['name'] = Configuration::get('PS_INVOICE_PREFIX', intval($order->id_lang)) . sprintf('%06d', $order->invoice_number) . '.pdf'; $fileAttachment['mime'] = 'application/pdf'; } else { $fileAttachment = NULL; } if ($orderStatus->send_email and Validate::isEmail($customer->email)) { Mail::Send(intval($order->id_lang), 'order_conf', 'Order confirmation', $data, $customer->email, $customer->firstname . ' ' . $customer->lastname, NULL, NULL, $fileAttachment); } $this->currentOrder = intval($order->id); return true; } return true; } else { die(Tools::displayError('Order creation failed')); } } else { die(Tools::displayError('An order has already been placed using this cart')); } }
function hookRightColumn($params) { global $link, $smarty, $category_path; $id_product = intval(Tools::getValue('id_product')); if ($id_product) { $product = new Product($id_product); } $productsViewed = (isset($params['cookie']->viewed) and !empty($params['cookie']->viewed)) ? array_slice(explode(',', $params['cookie']->viewed), 0, 2 * Configuration::get('PRODUCTS_VIEWED_NBR')) : array(); if (sizeof($productsViewed)) { $productsViewedObj = array(); $articlesViewedObj = array(); $nrProducts = 0; $nrArticles = 0; $category_path_ids = array(); foreach ($category_path as $cat) { $category_path_ids[] = $cat['id_category']; } foreach ($productsViewed as $productViewed) { $obj = new Product(intval($productViewed), false, intval($params['cookie']->id_lang)); $currency = new Currency(intval($params['cookie']->id_currency)); $obj->price = Tools::displayPrice(Product::getPriceStaticLC(intval($productViewed)), $currency, false, false); if (!Validate::isLoadedObject($obj) or !$obj->active) { continue; } else { $images = $obj->getImages(intval($params['cookie']->id_lang)); foreach ($images as $k => $image) { if ($image['cover']) { $obj->cover = $obj->id . '-' . $image['id_image']; $obj->legend = $image['legend']; break; } } if (!isset($obj->cover)) { $obj->cover = Language::getIsoById($params['cookie']->id_lang) . '-default'; $obj->legend = ''; } $display = false; foreach (Product::getIndexedCategories($obj->id) as $row) { if (in_array($row['id_category'], $category_path_ids)) { $display = true; break; } } if ($display) { if ($obj->type == 'product') { $productsViewedObj[] = $obj; $nrProducts += 1; } else { if ($obj->type == 'article') { $articlesViewedObj[] = $obj; $nrArticles += 1; } } } } } if (isset($product) and $product and !in_array($product->id, $productsViewed)) { array_unshift($productsViewed, $product->id); } $viewed = ''; foreach ($productsViewed as $id_product_viewed) { $viewed .= intval($id_product_viewed) . ','; } $params['cookie']->viewed = rtrim($viewed, ','); $smarty->assign(array('productsViewedObj' => $productsViewedObj, 'articlesViewedObj' => $articlesViewedObj, 'mediumSize' => Image::getSize('medium'))); return $this->display(__FILE__, 'blockviewed.tpl'); } elseif (isset($product) and Validate::isLoadedObject($product)) { $params['cookie']->viewed = intval($product->id); } return; }
public static function getProductProperties($id_lang, $row) { if (!$row['id_product']) { return false; } $row['allow_oosp'] = Product::isAvailableWhenOutOfStock($row['out_of_stock']); if ((!isset($row['id_product_attribute']) or !$row['id_product_attribute']) and $ipa_default = Product::getDefaultAttribute($row['id_product'], !$row['allow_oosp'])) { $row['id_product_attribute'] = $ipa_default; } if (!isset($row['id_product_attribute'])) { $row['id_product_attribute'] = 0; } // Tax $usetax = true; $tax = floatval(Tax::getApplicableTax(intval($row['id_tax']), floatval($row['rate']))); if (Tax::excludeTaxeOption() or !$tax) { $usetax = false; } $cacheKey = $row['id_product'] . '-' . $row['id_product_attribute'] . '-' . $id_lang . '-' . intval($usetax); if (array_key_exists($cacheKey, self::$producPropertiesCache)) { return self::$producPropertiesCache[$cacheKey]; } // Datas $link = new Link(); $row['category'] = Category::getLinkRewrite($row['id_category_default'], intval($id_lang)); $row['link'] = $link->getProductLink($row['id_product'], $row['link_rewrite'], $row['category'], $row['ean13']); $row['attribute_price'] = isset($row['id_product_attribute']) and $row['id_product_attribute'] ? floatval(Product::getProductAttributePrice($row['id_product_attribute'])) : 0; $row['price_tax_exc'] = Product::getPriceStaticLC($row['id_product'], false, (isset($row['id_product_attribute']) and !empty($row['id_product_attribute'])) ? intval($row['id_product_attribute']) : NULL, 2); $row['price'] = Product::getPriceStaticLC($row['id_product'], true, (isset($row['id_product_attribute']) and !empty($row['id_product_attribute'])) ? intval($row['id_product_attribute']) : NULL, 2); $row['reduction'] = self::getReductionValue($row['reduction_price'], $row['reduction_percent'], $row['reduction_from'], $row['reduction_to'], $row['price'], $usetax, floatval($row['rate'])); $row['price_without_reduction'] = Product::getPriceStaticLC($row['id_product'], true, (isset($row['id_product_attribute']) and !empty($row['id_product_attribute'])) ? intval($row['id_product_attribute']) : NULL, 2, NULL, false, false); $row['quantity'] = Product::getQuantity($row['id_product']); $row['id_image'] = Product::defineProductImage($row); $row['features'] = Product::getFrontFeaturesStatic(intval($id_lang), $row['id_product']); $row['attachments'] = Product::getAttachmentsStatic(intval($id_lang), $row['id_product']); $row['pack'] = Pack::isPack($row['id_product']); $row['packItems'] = $row['pack'] ? Pack::getItemTable($row['id_product'], $id_lang) : array(); $row['nopackprice'] = $row['pack'] ? Pack::noPackPrice($row['id_product']) : 0; self::$producPropertiesCache[$cacheKey] = $row; return self::$producPropertiesCache[$cacheKey]; }
<generator>PrestaShop</generator> <language><?php echo Language::getIsoById(intval($cookie->id_lang)); ?> </language> <image> <title><![CDATA[<?php echo Configuration::get('PS_SHOP_NAME'); ?> ]]></title> <url><?php echo _PS_BASE_URL_ . __PS_BASE_URI__ . 'img/logo.jpg'; ?> </url> <link><?php echo _PS_BASE_URL_ . __PS_BASE_URI__; ?> </link> </image> <?php foreach ($products as $product) { $image = Image::getImages(intval($cookie->id_lang), $product['id_product']); echo "\t\t<item>\n"; echo "\t\t\t<title><![CDATA[" . $product['name'] . " - " . html_entity_decode(Tools::displayPrice(Product::getPriceStaticLC($product['id_product']), $currency), ENT_COMPAT, 'UTF-8') . " ]]></title>\n"; echo "\t\t\t<description><img src="" . _PS_BASE_URL_ . __PS_BASE_URI__ . "img/p/" . $image[0]['id_product'] . "-" . $image[0]['id_image'] . "-small.jpg" title="" . $product['name'] . "" alt="thumb" />\n\t\t<![CDATA[" . $product['description_short'] . "]]></description>\n"; echo "\t\t\t<link><![CDATA[" . htmlspecialchars($link->getproductLink($product['id_product'], $product['link_rewrite'], Tools::getValue('id_category'))) . $affiliate . "]]></link>\n"; echo "\t\t</item>\n"; } ?> </channel> </rss>