Beispiel #1
0
 function productPriceRangeStrings($prices = array(), $productAssoc = array(), $nbRange = 6)
 {
     if (count($this->productIds) > 0) {
         $productIdMin = array_search(min(count($prices) < 1 ? $this->productFinalPrices : $prices), count($productAssoc) < 1 ? $this->idFinalPriceAssoc : $productAssoc);
         $productIdMax = array_search(max(count($prices) < 1 ? $this->productFinalPrices : $prices), count($productAssoc) < 1 ? $this->idFinalPriceAssoc : $productAssoc);
         $productMin = new Product($productIdMin, TRUE, $this->lang);
         $productMax = new Product($productIdMax, TRUE, $this->lang);
         $min = $productMin->getPrice($this->inclTax);
         $max = $productMax->getPrice($this->inclTax);
         $this->minTax = Tax::getApplicableTax($productMin->id_tax, $productMin->tax_rate);
         $this->maxTax = Tax::getApplicableTax($productMax->id_tax, $productMax->tax_rate);
         $explicit = FALSE;
         $range = $retRanges = array();
         $mxAvg = (double) ($max / $nbRange);
         $mxAvg = $nbRange > 6 ? $mxAvg + 1 : $mxAvg;
         $minTmp = $explicit ? $min : floor($min);
         for ($i = 1; $i <= $nbRange; $i++) {
             $temp = $min + $mxAvg;
             if ($temp > $max) {
                 $temp = $max;
             }
             if ($minTmp != $min) {
                 $minTmp = $explicit ? $minTmp : round($minTmp);
             }
             if ($temp != $max) {
                 $temp = $explicit ? $temp : round($temp);
             }
             $range[$minTmp] = $min = $temp;
             $minTmp = $temp + 1;
         }
         $i = 0;
         $nbr = count($range) - 1;
         foreach ($range as $min => $max) {
             if ($i == 0) {
                 $minPer = 0;
             } else {
                 $minPer = round($min, strlen(intval($min)) < 4 ? -1 : -floor(log10($min)));
             }
             if ($i == $nbr) {
                 $maxPer = round($max, strlen(intval($max)) < 4 ? -1 : -floor(log10($max)) - $i == $nbr ? 1 : 0);
             } else {
                 $maxPer = round($max, strlen(intval($max)) < 4 ? -1 : -floor(log10($max))) - 0.01;
             }
             if ($explicit == TRUE) {
                 if ($min < $max) {
                     $retRanges[] = $min . ':' . $max . ':' . $this->productRangeCount($min, $max);
                 }
             } else {
                 if ($minPer < $maxPer) {
                     $retRanges[] = $minPer . ':' . $maxPer . ':' . $this->productRangeCount($minPer, $maxPer);
                 }
             }
             $i++;
         }
         return $retRanges;
     } else {
         return FALSE;
     }
 }
Beispiel #2
0
                            }
                        }
                    }
                }
                foreach ($groups as &$group) {
                    natcasesort($group['attributes']);
                }
                foreach ($combinations as $id_product_attribute => $comb) {
                    $attributeList = '';
                    foreach ($comb['attributes'] as $id_attribute) {
                        $attributeList .= '\'' . intval($id_attribute) . '\',';
                    }
                    $attributeList = rtrim($attributeList, ',');
                    $combinations[$id_product_attribute]['list'] = $attributeList;
                }
                $smarty->assign(array('groups' => $groups, 'combinaisons' => $combinations, 'combinations' => $combinations, 'colors' => (sizeof($colors) and $product->id_color_default) ? $colors : false, 'combinationImages' => $combinationImages));
            }
        }
        $smarty->assign(array('no_tax' => Tax::excludeTaxeOption() or !Tax::getApplicableTax(intval($product->id_tax), 1), 'customizationFields' => $product->getCustomizationFields(intval($cookie->id_lang))));
        // Pack management
        $smarty->assign('packItems', Pack::getItemTable($product->id, intval($cookie->id_lang), true));
        $smarty->assign('packs', Pack::getPacksTable($product->id, intval($cookie->id_lang), true, 1));
    }
}
$smarty->assign(array('ENT_NOQUOTES' => ENT_NOQUOTES, 'outOfStockAllowed' => intval(Configuration::get('PS_ORDER_OUT_OF_STOCK')), 'errors' => $errors, 'categories' => Category::getHomeCategories(intval($cookie->id_lang)), 'have_image' => Product::getCover(intval(Tools::getValue('id_product'))), 'tax_enabled' => Configuration::get('PS_TAX'), 'display_qties' => intval(Configuration::get('PS_DISPLAY_QTIES')), 'display_ht' => !Tax::excludeTaxeOption()));
if (file_exists(_PS_THEME_DIR_ . 'thickbox.tpl')) {
    $smarty->display(_PS_THEME_DIR_ . 'thickbox.tpl');
}
$smarty->assign(array('currencySign' => $currency->sign, 'currencyRate' => $currency->conversion_rate, 'currencyFormat' => $currency->format, 'currencyBlank' => $currency->blank));
$smarty->display(_PS_THEME_DIR_ . 'product.tpl');
include dirname(__FILE__) . '/footer.php';
    /**
     * 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)
    {
        global $cart;
        $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);
            $amountPaid = !$dont_touch_amount ? Tools::ps_round(floatval($amountPaid), 2) : $amountPaid;
            $order->total_paid_real = $amountPaid;
            $order->total_products = floatval($cart->getOrderTotal(false, 1));
            $order->total_products_wt = floatval($cart->getOrderTotal(true, 1));
            $order->total_discounts = floatval(abs($cart->getOrderTotal(true, 2)));
            $order->total_shipping = floatval($cart->getOrderShippingCost());
            $order->total_wrapping = floatval(abs($cart->getOrderTotal(true, 6)));
            $order->total_paid = floatval(Tools::ps_round(floatval($cart->getOrderTotal(true, 3)), 2));
            $order->invoice_date = '0000-00-00 00:00:00';
            $order->delivery_date = '0000-00-00 00:00:00';
            // Amount paid by customer is not the right one -> Status = payment error
            if ($order->total_paid != $order->total_paid_real) {
                $id_order_state = _PS_OS_ERROR_;
            }
            // 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`, `reduction_percent`, `reduction_amount`, `product_quantity_discount`, `product_ean13`, `product_reference`, `product_supplier_reference`, `product_weight`, `tax_name`, `tax_rate`, `ecotax`, `discount_quantity_applied`, `download_deadline`, `download_hash`)
				VALUES ';
                $customizedDatas = Product::getAllCustomizedDatas(intval($order->id_cart));
                Product::addCustomizationPrice($products, $customizedDatas);
                foreach ($products as $key => $product) {
                    $outOfStock = false;
                    $productQuantity = intval(Product::getQuantity(intval($product['id_product']), $product['id_product_attribute'] ? intval($product['id_product_attribute']) : NULL));
                    $quantityInStock = $productQuantity - intval($product['cart_quantity']) < 0 ? $productQuantity : intval($product['cart_quantity']);
                    if ($id_order_state != _PS_OS_CANCELED_ and $id_order_state != _PS_OS_ERROR_) {
                        if (($updateResult = Product::updateQuantity($product)) === false or $updateResult === -1) {
                            $outOfStock = true;
                        }
                        if (!$outOfStock) {
                            $product['stock_quantity'] -= $product['cart_quantity'];
                        }
                        Hook::updateQuantity($product, $order);
                    }
                    $price = Product::getPriceStatic(intval($product['id_product']), false, $product['id_product_attribute'] ? intval($product['id_product_attribute']) : NULL, 6, NULL, false, true, $product['cart_quantity'], false, intval($order->id_customer), intval($order->id_cart), intval($order->id_address_delivery));
                    $price_wt = Product::getPriceStatic(intval($product['id_product']), true, $product['id_product_attribute'] ? intval($product['id_product_attribute']) : NULL, 2, NULL, false, true, $product['cart_quantity'], false, intval($order->id_customer), intval($order->id_cart), intval($order->id_address_delivery));
                    // Add some informations for virtual products
                    $deadline = '0000-00-00 00:00:00';
                    $download_hash = NULL;
                    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;
                        $tax = 0;
                    } else {
                        $tax = Tax::getApplicableTax(intval($product['id_tax']), floatval($product['rate']), intval($order->id_address_delivery));
                    }
                    $currentDate = date('Y-m-d H:m:i');
                    if ($product['reduction_from'] != $product['reduction_to'] and ($currentDate > $product['reduction_to'] or $currentDate < $product['reduction_from'])) {
                        $reduction_percent = 0.0;
                        $reduction_amount = 0.0;
                    } else {
                        $reduction_percent = floatval($product['reduction_percent']);
                        $reduction_amount = Tools::ps_round(floatval($product['reduction_price']) / (1 + floatval($tax) / 100), 6);
                    }
                    // Quantity discount
                    $reduc = 0.0;
                    if ($product['cart_quantity'] > 1 and $qtyD = QuantityDiscount::getDiscountFromQuantity($product['id_product'], $product['cart_quantity'])) {
                        $reduc = QuantityDiscount::getValue($price_wt, $qtyD->id_discount_type, $qtyD->value, new Currency(intval($order->id_currency)));
                    }
                    $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['cart_quantity']) . ',
						' . $quantityInStock . ',
						' . floatval(Product::getPriceStatic(intval($product['id_product']), false, $product['id_product_attribute'] ? intval($product['id_product_attribute']) : NULL, Product::getTaxCalculationMethod(intval($order->id_customer)) == PS_TAX_EXC ? 2 : 6, NULL, false, false, $product['cart_quantity'], false, intval($order->id_customer), intval($order->id_cart), intval($order->id_address_delivery))) . ',
						' . floatval($reduction_percent) . ',
						' . floatval($reduction_amount) . ',
						' . 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($product['id_product_attribute'] ? $product['weight_attribute'] : $product['weight']) . ',
						\'' . (!$tax ? '' : pSQL($product['tax'])) . '\',
						' . floatval($tax) . ',
						' . floatval($product['ecotax']) . ',
						' . (int) QuantityDiscount::getDiscountFromQuantity(intval($product['id_product']), intval($product['cart_quantity'])) . ',
						\'' . 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']])) {
                        $customizationText = '';
                        foreach ($customizedDatas[$product['id_product']][$product['id_product_attribute']] as $customization) {
                            if (isset($customization['datas'][_CUSTOMIZE_TEXTFIELD_])) {
                                foreach ($customization['datas'][_CUSTOMIZE_TEXTFIELD_] as $text) {
                                    $customizationText .= $text['name'] . $this->l(':') . ' ' . $text['value'] . ', ';
                                }
                            }
                        }
                        $customizationText = rtrim($customizationText, ', ');
                        $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') . (!empty($customizationText) ? ' - ' . $customizationText : '') . '</strong></td>
							<td style="padding: 0.6em 0.4em; text-align: right;">' . Tools::displayPrice(Product::getTaxCalculationMethod() == PS_TAX_EXC ? $price : $price_wt, $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 * (Product::getTaxCalculationMethod() == PS_TAX_EXC ? $price : $price_wt), $currency, false, false) . '</td>
						</tr>';
                    }
                    if (!$customizationQuantity or intval($product['cart_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(Product::getTaxCalculationMethod() == PS_TAX_EXC ? $price : $price_wt, $currency, false, false) . '</td>
							<td style="padding: 0.6em 0.4em; text-align: center;">' . (intval($product['cart_quantity']) - $customizationQuantity) . '</td>
							<td style="padding: 0.6em 0.4em; text-align: right;">' . Tools::displayPrice((intval($product['cart_quantity']) - $customizationQuantity) * (Product::getTaxCalculationMethod() == PS_TAX_EXC ? $price : $price_wt), $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->getOrderTotal(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(intval($product['id_product']), intval($product['cart_quantity']));
                        }
                    }
                }
                if (isset($outOfStock) and $outOfStock) {
                    $history = new OrderHistory();
                    $history->id_order = intval($order->id);
                    $history->changeIdOrderState(_PS_OS_OUTOFSTOCK_, intval($order->id));
                    $history->addWithemail();
                }
                // Set order state in order history ONLY even if the "out of stock" status has not been yet reached
                // So you migth have two order states
                $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;
                }
                $this->currentOrder = intval($order->id);
                return true;
            } else {
                die(Tools::displayError('Order creation failed'));
            }
        } else {
            die(Tools::displayError('An order has already been placed using this cart'));
        }
    }
Beispiel #4
0
 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::getPriceStatic($row['id_product'], false, (isset($row['id_product_attribute']) and !empty($row['id_product_attribute'])) ? intval($row['id_product_attribute']) : NULL, 6);
     if (self::$_taxCalculationMethod == PS_TAX_EXC) {
         $row['price_tax_exc'] = Tools::ps_round($row['price_tax_exc'], 2);
         $row['price'] = Product::getPriceStatic($row['id_product'], true, (isset($row['id_product_attribute']) and !empty($row['id_product_attribute'])) ? intval($row['id_product_attribute']) : NULL, 6);
     } else {
         $row['price'] = Tools::ps_round(Product::getPriceStatic($row['id_product'], true, (isset($row['id_product_attribute']) and !empty($row['id_product_attribute'])) ? intval($row['id_product_attribute']) : NULL, 6), 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::getPriceStatic($row['id_product'], true, (isset($row['id_product_attribute']) and !empty($row['id_product_attribute'])) ? intval($row['id_product_attribute']) : NULL, 6, 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];
 }
Beispiel #5
0
    function hookProductFooter($params)
    {
        global $smarty, $cookie;
        $priceFormat = Configuration::get('PRODUCT_ATTRIB_NC_PRICE_FORMAT');
        $fullPrice = Configuration::get('PRODUCT_ATTRIB_NC_FULL_PRICE');
        $product = new Product(intval($_GET['id_product']), true, intval($cookie->id_lang));
        if ($priceFormat > 1) {
            // Tax
            $tax_datas = Db::getInstance()->getRow('
			SELECT p.`id_tax`, t.`rate`
			FROM `' . _DB_PREFIX_ . 'product` p
			LEFT JOIN `' . _DB_PREFIX_ . 'tax` AS t ON t.`id_tax` = p.`id_tax`
			WHERE p.`id_product` = ' . intval($product->id));
            $tax = floatval(Tax::getApplicableTax(intval($tax_datas['id_tax']), floatval($tax_datas['rate'])));
        }
        /* Attributes / Groups & colors */
        $colors = array();
        $attributesGroups = Db::getInstance()->ExecuteS('
			SELECT ag.`id_attribute_group`, agl.`name` AS group_name, agl.`public_name` AS public_group_name, a.`id_attribute`, al.`name` AS attribute_name,
			a.`color` AS attribute_color, pa.`id_product_attribute`, pa.`quantity`, pa.`price`, pa.`ecotax`, pa.`weight`, pa.`default_on`, pa.`reference`
			FROM `' . _DB_PREFIX_ . 'product_attribute` pa
			LEFT JOIN `' . _DB_PREFIX_ . 'product_attribute_combination` pac ON pac.`id_product_attribute` = pa.`id_product_attribute`
			LEFT JOIN `' . _DB_PREFIX_ . 'attribute` a ON a.`id_attribute` = pac.`id_attribute`
			LEFT JOIN `' . _DB_PREFIX_ . 'attribute_group` ag ON ag.`id_attribute_group` = a.`id_attribute_group`
			LEFT JOIN `' . _DB_PREFIX_ . 'attribute_lang` al ON a.`id_attribute` = al.`id_attribute`
			LEFT JOIN `' . _DB_PREFIX_ . 'attribute_group_lang` agl ON ag.`id_attribute_group` = agl.`id_attribute_group`
			WHERE pa.`id_product` = ' . intval($product->id) . '
			AND al.`id_lang` = ' . intval($cookie->id_lang) . '
			AND agl.`id_lang` = ' . intval($cookie->id_lang) . '
			ORDER BY agl.`public_name`');
        if (Db::getInstance()->numRows()) {
            foreach ($attributesGroups as $k => $row) {
                /* Color management */
                if (isset($row['attribute_color']) and $row['attribute_color'] and $row['id_attribute_group'] == $product->id_color_default) {
                    $colors[$row['id_attribute']]['value'] = $row['attribute_color'];
                    $colors[$row['id_attribute']]['name'] = $row['attribute_name'];
                }
                $groups[$row['id_attribute_group']]['attributes'][$row['id_attribute']] = $row['attribute_name'];
                if (strpos($row['public_group_name'], '|') !== FALSE) {
                    $label = explode('|', $row['public_group_name'], 2);
                    $groups[$row['id_attribute_group']]['label'] = $label[0];
                    $groups[$row['id_attribute_group']]['name'] = $label[1];
                } else {
                    $groups[$row['id_attribute_group']]['name'] = $row['public_group_name'];
                }
                if ($row['default_on']) {
                    $groups[$row['id_attribute_group']]['default'] = intval($row['id_attribute']);
                }
                if (!isset($groups[$row['id_attribute_group']]['attributes_quantity'][$row['id_attribute']])) {
                    $groups[$row['id_attribute_group']]['attributes_quantity'][$row['id_attribute']] = 0;
                }
                $groups[$row['id_attribute_group']]['attributes_quantity'][$row['id_attribute']] += intval($row['quantity']);
            }
            $smarty->assign(array('col_img_dir' => _PS_COL_IMG_DIR_, 'reductionPrice' => $product->reduction_price, 'reductionPercent' => $product->reduction_percent, 'reductionFrom' => $product->reduction_from, 'reductionTo' => $product->reduction_to, 'groupReduction' => (100 - Group::getReduction(intval($cookie->id_customer))) / 100, 'groups' => $groups, 'attributeImpacts' => Db::getInstance()->ExecuteS('SELECT * FROM `' . _DB_PREFIX_ . 'attribute_impact` WHERE `id_product` = ' . intval($_GET['id_product'])), 'fullPrice' => $fullPrice, 'price' => $fullPrice ? number_format($product->price * (1 + $tax * 0.01), 2, '.', '') : 0, 'priceFormat' => $priceFormat, 'hideZeros' => Configuration::get('PRODUCT_ATTRIB_NC_HIDE_ZEROS'), 'weight' => $product->weight, 'weightUnit' => Configuration::get('PS_WEIGHT_UNIT'), 'displayWeight' => Configuration::get('PRODUCT_ATTRIB_NC_DISPLAY_WEIGHT'), 'displayImage' => Configuration::get('PRODUCT_ATTRIB_NC_DISPLAY_IMAGE'), 'displayDescription' => Configuration::get('PRODUCT_ATTRIB_NC_DISPLAY_DESC')));
            if ($priceFormat > 1) {
                $smarty->assign(array('tax' => 1 - $tax / 100));
            }
        }
        return $this->display(__FILE__, 'productattributesnc.tpl');
    }
Beispiel #6
0
 /**
  * This function returns the total cart amount
  *
  * type = 1 : only products
  * type = 2 : only discounts
  * type = 3 : both
  * type = 4 : both but without shipping
  * type = 5 : only shipping
  * type = 6 : only wrapping
  * type = 7 : only products without shipping
  *
  * @param boolean $withTaxes With or without taxes
  * @param integer $type Total type
  * @return float Order total
  */
 public function getOrderTotal($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->getOrderShippingCost(NULL, intval($withTaxes)) : 0;
     if ($type == 7) {
         $type = 1;
     }
     $products = $this->getProducts();
     $order_total = 0;
     if (Tax::excludeTaxeOption()) {
         $withTaxes = false;
     }
     foreach ($products as $product) {
         if ($this->_taxCalculationMethod == PS_TAX_EXC) {
             // Here taxes are computed only once the quantity has been applied to the product price
             $price = Product::getPriceStatic(intval($product['id_product']), false, intval($product['id_product_attribute']), 2, NULL, false, true, $product['cart_quantity'], false, intval($this->id_customer) ? intval($this->id_customer) : NULL, intval($this->id), intval($this->id_address_delivery) ? intval($this->id_address_delivery) : NULL);
             $total_price = $price * intval($product['cart_quantity']);
             if ($withTaxes) {
                 $total_price = Tools::ps_round($total_price * (1 + floatval(Tax::getApplicableTax(intval($product['id_tax']), floatval($product['rate']))) / 100), 2);
             }
         } else {
             $price = Product::getPriceStatic(intval($product['id_product']), $withTaxes, intval($product['id_product_attribute']), 6, NULL, false, true, $product['cart_quantity'], false, intval($this->id_customer) ? intval($this->id_customer) : NULL, intval($this->id), intval($this->id_address_delivery) ? intval($this->id_address_delivery) : NULL);
             if (!$withTaxes) {
                 $total_price = Tools::ps_round($price * intval($product['cart_quantity']), 2);
             } else {
                 $total_price = Tools::ps_round($price, 2) * intval($product['cart_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;
         }
         $wrapping_fees = Tools::convertPrice(Tools::ps_round($wrapping_fees, 2), new Currency(intval($this->id_currency)));
     }
     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) and 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 -= Tools::ps_round(floatval($discount->getValue(sizeof($discounts), $order_total_products, $shipping_fees, $this->id, intval($withTaxes))), 2);
                 }
             }
         }
     }
     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 Tools::ps_round(floatval($order_total), 2);
 }
Beispiel #7
0
 public static function getProductProperties($id_lang, $row)
 {
     if (!$row['id_product']) {
         return false;
     }
     $link = new Link();
     // Tax
     $usetax = true;
     $tax = floatval(Tax::getApplicableTax(intval($row['id_tax']), floatval($row['rate'])));
     if (Tax::excludeTaxeOption() or !$tax) {
         $usetax = false;
     }
     // Datas
     $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['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;
     }
     $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::getPriceStatic($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::getPriceStatic($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::getPriceStatic($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;
     return $row;
 }