Example #1
0
 public function renderEditRule($tpl = NULL)
 {
     if (!isset($this->context)) {
         $this->context = JeproshopContext::getContext();
     }
     $this->helper = new JeproshopHelper();
     $countryModel = new JeproshopCountryModelCountry();
     $countries = $countryModel->getCountries($this->context->language->lang_id);
     $taxModel = new JeproshopTaxModelTax();
     $taxes = $taxModel->getTaxes((int) $this->context->language->lang_id);
     $this->assignRef('taxes', $taxes);
     $taxRuleModel = new JeproshopTaxRuleModelTaxRule();
     $taxRules = $taxRuleModel->getTaxRuleList();
     $this->assignRef('tax_rules', $taxRules);
     $this->assignRef('countries', $countries);
     $this->addToolBar();
     $this->sideBar = JHtmlSidebar::render();
     parent::display($tpl);
 }
Example #2
0
 public function assignSummaryInformations()
 {
     $context = JeproshopContext::getContext();
     $summary = $context->cart->getSummaryDetails();
     $customizedDatas = JeproshopProductModelProduct::getAllCustomizedDatas($context->cart->cart_id);
     // override customization tax rate with real tax (tax rules)
     if ($customizedDatas) {
         foreach ($summary['products'] as &$productUpdate) {
             $productId = (int) (isset($productUpdate->product_id) ? $productUpdate->product_id : $productUpdate->product_id);
             $productAttributeId = (int) (isset($productUpdate->product_attribute_id) ? $productUpdate->product_attribute_id : $productUpdate->product_attribute_id);
             if (isset($customizedDatas[$productId][$productAttributeId])) {
                 $productUpdate->tax_rate = JeproshopTaxModelTax::getProductTaxRate($productId, $context->cart->{JeproshopSettingModelSetting::getValue('tax_address_type')});
             }
         }
         JeproshopProductModelProduct::addCustomizationPrice($summary->products, $customizedDatas);
     }
     $cart_product_context = JeproshopContext::getContext()->cloneContext();
     foreach ($summary['products'] as $key => $product) {
         $product->quantity = $product->cart_quantity;
         // for compatibility with 1.2 themes
         if ($cart_product_context->shop->shop_id != $product->shop_id) {
             $cart_product_context->shop = new JeproshopModelShop((int) $product->shop_id);
         }
         $null = null;
         $product->price_without_specific_price = JeproshopProductModelProduct::getStaticPrice($product->product_id, !JeproshopProductModelProduct::getTaxCalculationMethod(), $product->product_attribute_id, 2, null, false, false, 1, false, null, null, null, $null, true, true, $cart_product_context);
         if (JeproshopProductModelProduct::getTaxCalculationMethod()) {
             $product->is_discounted = $product->price_without_specific_price != $product->price;
         } else {
             $product->is_discounted = $product->price_without_specific_price != $product->price_wt;
         }
     }
     // Get available cart rules and unset the cart rules already in the cart
     $available_cart_rules = JeproshopCartRuleModelCartRule::getCustomerCartRules($this->context->language->lang_id, isset($this->context->customer->customer_id) ? $this->context->customer->customer_id : 0, true, true, true, $this->context->cart);
     $cart_cart_rules = $context->cart->getCartRules();
     foreach ($available_cart_rules as $key => $available_cart_rule) {
         if (!$available_cart_rule->high_light || strpos($available_cart_rule->code, 'BO_ORDER_') === 0) {
             unset($available_cart_rules[$key]);
             continue;
         }
         foreach ($cart_cart_rules as $cart_cart_rule) {
             if ($available_cart_rule->cart_rule_id == $cart_cart_rule->cart_rule_id) {
                 unset($available_cart_rules[$key]);
                 continue 2;
             }
         }
     }
     $show_option_allow_separate_package = !$this->context->cart->isAllProductsInStock(true) && JeproshopSettingModelSetting::getValue('ship_when_available');
     $this->assign($summary);
     //$this->assign('token_cart', Tools::getToken(false));
     $this->assign('is_logged', $this->context->controller->isLogged);
     $this->assign('is_virtual_cart', $this->context->cart->isVirtualCart());
     $this->assign('product_number', $this->context->cart->numberOfProducts());
     $this->assign('voucher_allowed', JeproshopCartRuleModelCartRule::isFeaturePublished());
     $this->assign('shipping_cost', $this->context->cart->getOrderTotal(true, JeproshopCartModelCart::ONLY_SHIPPING));
     $this->assign('shipping_cost_tax_excluded', $this->context->cart->getOrderTotal(false, JeproshopCartModelCart::ONLY_SHIPPING));
     $this->assign('customizedDatas', $customizedDatas);
     $this->assign('CUSTOMIZE_FILE', JeproshopProductModelProduct::CUSTOMIZE_FILE);
     $this->assign('CUSTOMIZE_TEXT_FIELD', JeproshopProductModelProduct::CUSTOMIZE_TEXT_FIELD);
     $this->assign('last_product_added', $this->context->cart->getLastProduct());
     $this->assign('display_vouchers', $available_cart_rules);
     $this->assign('currency_sign', $this->context->currency->sign);
     $this->assign('currency_rate', $this->context->currency->conversion_rate);
     $this->assign('currency_format', $this->context->currency->format);
     $this->assign('currency_blank', $this->context->currency->blank);
     $this->assign('show_option_allow_separate_package', $show_option_allow_separate_package);
     $this->assign('small_size', JeproshopImageModelImage::getSize(JeproshopImageTypeModelImageType::getFormatName('small')));
     /*
             $this->context->smarty->assign(array(
                 'HOOK_SHOPPING_CART' => Hook::exec('displayShoppingCartFooter', $summary),
                 'HOOK_SHOPPING_CART_EXTRA' => Hook::exec('displayShoppingCart', $summary)
             ));*/
 }
Example #3
0
    /**
     * Return cart products
     *
     * @result array Products
     * @param bool $refresh
     * @param bool $product_id
     * @param null $country_id
     * @return array|null
     */
    public function getProducts($refresh = false, $product_id = false, $country_id = null)
    {
        if (!$this->cart_id) {
            return array();
        }
        // Product cache must be strictly compared to NULL, or else an empty cart will add dozens of queries
        if ($this->_products !== null && !$refresh) {
            // Return product row with specified ID if it exists
            if (is_int($product_id)) {
                foreach ($this->_products as $product) {
                    if ($product->product_id == $product_id) {
                        return array($product);
                    }
                }
                return array();
            }
            return $this->_products;
        }
        $db = JFactory::getDBO();
        $select = $leftJoin = "";
        if (JeproshopCustomization::isFeaturePublished()) {
            $select .= 'cu.`id_customization`, cu.`quantity` AS customization_quantity';
            $leftJoin .= " LEFT JOIN " . $db->quoteName('#__jeproshop_customization') . " AS customization ";
            /*
                            'p.`id_product` = cu.`id_product` AND cart_product.`id_product_attribute` = cu.`id_product_attribute` AND cu.`id_cart` = '.(int)$this->id); */
        } else {
            $select .= 'NULL AS customization_quantity, NULL AS id_customization';
        }
        if (JeproshopCombinationModelCombination::isFeaturePublished()) {
            $select .= '
				product_attribute_shop.`price` AS price_attribute, product_attribute_shop.`ecotax` AS ecotax_attr,
				IF (IFNULL(pa.`reference`, \'\') = \'\', p.`reference`, pa.`reference`) AS reference,
				(p.`weight`+ pa.`weight`) weight_attribute,
				IF (IFNULL(pa.`ean13`, \'\') = \'\', p.`ean13`, pa.`ean13`) AS ean13,
				IF (IFNULL(pa.`upc`, \'\') = \'\', p.`upc`, pa.`upc`) AS upc,
				pai.`id_image` as pai_id_image, il.`legend` as pai_legend,
				IFNULL(product_attribute_shop.`minimal_quantity`, product_shop.`minimal_quantity`) as minimal_quantity
			';
            /*$sql->leftJoin('product_attribute', 'pa', 'pa.`id_product_attribute` = cart_product.`id_product_attribute`');
              $sql->leftJoin('product_attribute_shop', 'product_attribute_shop', '(product_attribute_shop.`id_shop` = cart_product.`id_shop` AND product_attribute_shop.`id_product_attribute` = pa.`id_product_attribute`)');
              $sql->leftJoin('product_attribute_image', 'pai', 'pai.`id_product_attribute` = pa.`id_product_attribute`');
              $sql->leftJoin('image_lang', 'il', 'il.`id_image` = pai.`id_image` AND il.`id_lang` = '.(int)$this->id_lang); */
        } else {
            $select .= 'p.`reference` AS reference, p.`ean13`,
				p.`upc` AS upc, product_shop.`minimal_quantity` AS minimal_quantity';
        }
        $query = "SELECT cart_product." . $db->quoteName('product_attribute_id') . ", cart_product." . $db->quoteName('product_id') . ", cart_product.";
        $query .= $db->quoteName('quantity') . " AS cart_quantity, cart_product." . $db->quoteName('shop_id') . ", product_lang." . $db->quoteName('name');
        $query .= ", product." . $db->quoteName('is_virtual') . ", product_lang." . $db->quoteName('short_description') . ", product_lang." . $db->quoteName('available_now');
        $query .= ", product_lang." . $db->quoteName('available_later') . ", product_shop." . $db->quoteName('default_category_id') . ", product.";
        $query .= $db->quoteName('supplier_id') . ", product." . $db->quoteName('manufacturer_id') . ", product_shop." . $db->quoteName('on_sale') . ", product_shop.";
        $query .= $db->quoteName('ecotax') . ", product_shop." . $db->quoteName('additional_shipping_cost') . ", product_shop." . $db->quoteName('available_for_order');
        $query .= ", product_shop." . $db->quoteName('price') . ", product_shop." . $db->quoteName('published') . ", product_shop." . $db->quoteName('unity');
        $query .= ", product_shop." . $db->quoteName('unit_price_ratio') . ", stock." . $db->quoteName('quantity') . " AS quantity_available, product." . $db->quoteName('width');
        $query .= ", product." . $db->quoteName('height') . ", product." . $db->quoteName('depth') . ", stock." . $db->quoteName('out_of_stock') . ", product.";
        $query .= $db->quoteName('weight') . ", product." . $db->quoteName('date_add') . ", product." . $db->quoteName('date_upd') . ", IFNULL(stock.quantity, 0) as quantity, ";
        $query .= "product_lang." . $db->quoteName('link_rewrite') . ", category_lang." . $db->quoteName('link_rewrite') . " AS category, CONCAT(LPAD(cart_product.";
        $query .= $db->quoteName('product_id') . ", 10, 0), LPAD(IFNULL(cart_product." . $db->quoteName('product_attribute_id') . ", 0), 10, 0), IFNULL(cart_product.";
        $query .= $db->quoteName('address_delivery_id') . ", 0)) AS unique_id, cart_product.address_delivery_id, product_shop." . $db->quoteName('wholesale_price');
        $query .= ", product_shop.advanced_stock_management, product_supplier.product_supplier_reference supplier_reference, IFNULL(specific_price." . $db->quoteName('reduction_type');
        $query .= ", 0) AS reduction_type FROM " . $db->quoteName('#__jeproshop_cart_product') . " AS cart_product LEFT JOIN " . $db->quoteName('#__jeproshop_product') . " AS product ";
        $query .= " ON (product." . $db->quoteName('product_id') . " = cart_product." . $db->quoteName('product_id') . ") INNER JOIN " . $db->quoteName('#__jeproshop_product_shop');
        $query .= " AS product_shop ON (product_shop." . $db->quoteName('shop_id') . " = cart_product." . $db->quoteName('shop_id') . " AND product_shop." . $db->quoteName('product_id');
        $query .= " = product." . $db->quoteName('product_id') . ") LEFT JOIN " . $db->quoteName('#__jeproshop_product_lang') . " AS product_lang ON (product." . $db->quoteName('product_id');
        $query .= " = product_lang." . $db->quoteName('product_id') . "\tAND product_lang." . $db->quoteName('lang_id') . " = " . (int) $this->lang_id;
        $query .= JeproshopShopModelShop::addSqlRestrictionOnLang('product_lang', 'cart_product.shop_id') . ") LEFT JOIN " . $db->quoteName('#__jeproshop_category_lang');
        $query .= " AS category_lang ON(product_shop." . $db->quoteName('default_category_id') . " = category_lang." . $db->quoteName('category_id') . " AND category_lang." . $db->quoteName('lang_id');
        $query .= " = " . (int) $this->lang_id . JeproshopShopModelShop::addSqlRestrictionOnLang('category_lang', 'cart_product.shop_id') . ") LEFT JOIN " . $db->quoteName('#__jeproshop_product_supplier');
        $query .= " AS product_supplier ON (product_supplier." . $db->quoteName('product_id') . " = cart_product." . $db->quoteName('product_id') . " AND product_supplier.";
        $query .= $db->quoteName('product_attribute_id') . " = cart_product." . $db->quoteName('product_attribute_id') . " AND product_supplier." . $db->quoteName('supplier_id');
        $query .= " = product." . $db->quoteName('supplier_id') . ") LEFT JOIN " . $db->quoteName('#__jeproshop_specific_price') . " AS specific_price ON (specific_price.";
        $query .= $db->quoteName('product_id') . " = cart_product." . $db->quoteName('product_id') . ") " . JeproshopProductModelProduct::sqlStock('cart_product');
        // AND 'sp.`id_shop` = cart_product.`id_shop`
        // @todo test if everything is ok, then refactorise call of this method
        //$sql->join(Product::sqlStock('cart_product', 'cart_product'));
        $query .= " WHERE cart_product." . $db->quoteName('cart_id') . " = " . (int) $this->cart_id;
        if ($product_id) {
            $query .= " AND cart_product." . $db->quoteName('product_id') . " = " . (int) $product_id;
        }
        $query .= " AND product." . $db->quoteName('product_id') . " IS NOT NULL GROUP BY unique_id ORDER BY cart_product." . $db->quoteName('date_add');
        $query .= ", product." . $db->quoteName('product_id') . ", cart_product." . $db->quoteName('product_attribute_id') . " ASC";
        $db->setQuery($query);
        $result = $db->loadObjectList();
        // Reset the cache before the following return, or else an empty cart will add dozens of queries
        $products_ids = array();
        $product_attribute_ids = array();
        if ($result) {
            foreach ($result as $row) {
                $products_ids[] = $row->product_id;
                $product_attribute_ids[] = $row->product_attribute_id;
            }
        }
        // Thus you can avoid one query per product, because there will be only one query for all the products of the cart
        JeproshopProductModelProduct::cacheProductsFeatures($products_ids);
        JeproshopCartModelCart::cacheSomeAttributesLists($product_attribute_ids, $this->lang_id);
        $this->_products = array();
        if (empty($result)) {
            return array();
        }
        $cart_shop_context = JeproshopContext::getContext()->cloneContext();
        foreach ($result as &$row) {
            if (isset($row->ecotax_attr) && $row->ecotax_attr > 0) {
                $row->ecotax = (double) $row->ecotax_attr;
            }
            $row->stock_quantity = (int) $row->quantity;
            // for compatibility with 1.2 themes
            $row->quantity = (int) $row->cart_quantity;
            if (isset($row->product_attribute_id) && (int) $row->product_attribute_id && isset($row->weight_attribute)) {
                $row->weight = (double) $row->weight_attribute;
            }
            if (JeproshopSettingModelSetting::getValue('tax_address_type') == 'address_invoice_id') {
                $address_id = (int) $this->address_invoice_id;
            } else {
                $address_id = (int) $row->address_delivery_id;
            }
            if (!JeproshopAddressModelAddress::addressExists($address_id)) {
                $address_id = null;
            }
            if ($cart_shop_context->shop->shop_id != $row->shop_id) {
                $cart_shop_context->shop = new JeproshopShopModelShop((int) $row->shop_id);
            }
            $specific_price_output = null;
            $null = null;
            if ($this->_taxCalculationMethod == COM_JEPROSHOP_TAX_EXCLUDED) {
                $row->price = JeproshopProductModelProduct::getStaticPrice((int) $row->product_id, false, isset($row->product_attribute_id) ? (int) $row->product_attribute_id : null, 2, null, false, true, (int) $row->cart_quantity, false, (int) $this->customer_id ? (int) $this->customer_id : null, (int) $this->cart_id, (int) $address_id ? (int) $address_id : null, $specific_price_output, true, true, $cart_shop_context);
                // Here taxes are computed only once the quantity has been applied to the product price
                $row->price_wt = JeproshopProductModelProduct::getStaticPrice((int) $row->product_id, true, isset($row->product_attribute_id) ? (int) $row->product_attribute_id : null, 2, null, false, true, (int) $row->cart_quantity, false, (int) $this->customer_id ? (int) $this->customer_id : null, (int) $this->cart_id, (int) $address_id ? (int) $address_id : null, $null, true, true, $cart_shop_context);
                $tax_rate = JeproshopTaxModelTax::getProductTaxRate((int) $row->product_id, (int) $address_id);
                $row->total_wt = JeproshopTools::roundPrice($row->price * (double) $row->cart_quantity * (1 + (double) $tax_rate / 100), 2);
                $row->total = $row->price * (int) $row->cart_quantity;
            } else {
                $row->price = JeproshopProductModelProduct::getStaticPrice((int) $row->product_id, false, (int) $row->product_attribute_id, 2, null, false, true, $row->cart_quantity, false, (int) $this->customer_id ? (int) $this->customer_id : null, (int) $this->cart_id, (int) $address_id ? (int) $address_id : null, $specific_price_output, true, true, $cart_shop_context);
                $row->price_wt = JeproshopProductModelProduct::getStaticPrice((int) $row->product_id, true, (int) $row->product_attribute_id, 2, null, false, true, $row->cart_quantity, false, (int) $this->customer_id ? (int) $this->customer_id : null, (int) $this->cart_id, (int) $address_id ? (int) $address_id : null, $null, true, true, $cart_shop_context);
                // In case when you use QuantityDiscount, getPriceStatic() can be return more of 2 decimals
                $row->price_wt = JeproshopTools::roundPrice($row->price_wt, 2);
                $row->total_wt = $row->price_wt * (int) $row->cart_quantity;
                $row->total = JeproshopTools::roundPrice($row->price * (int) $row->cart_quantity, 2);
                $row->description_short = JeproshopTools::nl2br($row->short_description);
            }
            if (!isset($row->product_attribute_id_image_id) || $row->product_attribute_id_image_id == 0) {
                $cache_id = 'jeproshop_cart_get_products_product_attribute_id_image_id_' . (int) $row->product_id . '_' . (int) $this->lang_id . '_' . (int) $row->shop_id;
                if (!JeproshopCache::isStored($cache_id)) {
                    $db = JFactory::getDBO();
                    $query = "SELECT image_shop." . $db->quoteName('image_id') . " AS image_id, image_lang." . $db->quoteName('legend') . " FROM ";
                    $query .= $db->quoteName('#__jeproshop_image') . " AS image JOIN " . $db->quoteName('#__jeproshop_image_shop') . " AS image_shop ON (";
                    $query .= " image.image_id = image_shop.image_id AND image_shop.cover=1 AND image_shop.shop_id = " . (int) $row->shop_id . ") LEFT JOIN ";
                    $query .= $db->quoteName('#__jeproshop_image_lang') . " AS image_lang ON (image_shop." . $db->quoteName('image_id') . " = image_lang.";
                    $query .= $db->quoteName('image_id') . " AND image_lang." . $db->quoteName('lang_id') . " = " . (int) $this->lang_id . ") WHERE image.";
                    $query .= $db->quoteName('product_id') . " = " . (int) $row->product_id . " AND image_shop." . $db->quoteName('cover') . " = 1";
                    $db->setQuery($query);
                    $row2 = $db->loadObject();
                    JeproshopCache::store($cache_id, $row2);
                }
                $row2 = JeproshopCache::retrieve($cache_id);
                if (!$row2) {
                    $row2 = new JObject();
                    $row2->image_id = false;
                    $row2->legend = false;
                } else {
                    $row = array_merge($row, $row2);
                }
            } else {
                $row->image_id = $row->product_attribute_id_image_id;
                $row->legend = $row->product_attribute_legend;
            }
            $row->reduction_applies = $specific_price_output && (double) $specific_price_output->reduction;
            $row->quantity_discount_applies = $specific_price_output && $row->cart_quantity >= (int) $specific_price_output->from_quantity;
            $row->image_id = JeproshopProductModelProduct::defineProductImage($row, $this->lang_id);
            $row->allow_out_of_sp = JeproshopProductModelProduct::isAvailableWhenOutOfStock($row->out_of_stock);
            $row->features = JeproshopProductModelProduct::getStaticFeatures((int) $row->product_id);
            if (array_key_exists($row->product_attribute_id . '_' . $this->lang_id, self::$_attributesLists)) {
                $row = array_merge($row, self::$_attributesLists[$row->product_attribute_id . '_' . $this->lang_id]);
            }
            $row = JeproshopProductModelProduct::getTaxesInformations($row, $cart_shop_context);
            $this->_products[] = $row;
        }
        return $this->_products;
    }
Example #4
0
 public function update()
 {
     if ($this->viewAccess() && JeproshopTools::checkTaxToken()) {
         $app = JFactory::getApplication();
         $tax_id = $app->input->get('tax_id');
         if (isset($tax_id) && $tax_id > 0) {
             $taxModel = new JeproshopTaxModelTax($tax_id);
             if ($taxModel->updateTax()) {
                 $link = 'index.php?option=com_jeproshop&view=tax';
             } else {
                 $link = 'index.php?option=com_jeproshop&view=tax&task=edit&tax_id=' . (int) $tax_id . '&' . JeproshopTools::getTaxToken() . '=1';
                 JError::raiseError(500, JText::_('COM_JEPROSHOP_WE_ENCOUNTER_AN_ERROR_WHILE_UPDATING_TAX_MESSAGE'));
             }
             $app->redirect($link);
         }
     }
 }
Example #5
0
 public static function getProductProperties($lang_id, $row, JeproshopContext $context = null)
 {
     if (!$row->product_id) {
         return false;
     }
     if ($context == null) {
         $context = JeproshopContext::getContext();
     }
     // Product::getDefaultAttribute is only called if id_product_attribute is missing from the SQL query at the origin of it:
     // consider adding it in order to avoid unnecessary queries
     $row->allow_out_of_stock_ordering = JeproshopProductModelProduct::isAvailableWhenOutOfStock($row->out_of_stock);
     if (JeproshopCombinationModelCombination::isFeaturePublished() && (!isset($row->product_attribute_id) || !$row->product_attribute_id) && (isset($row->cache_default_attribute) && ($default_product_attribute_id = $row->cache_default_attribute) !== null || ($default_product_attribute_id = JeproshopProductModelProduct::getDefaultAttribute($row->product_id, !$row->allow_out_of_stock_ordering)))) {
         $row->product_attribute_id = $default_product_attribute_id;
     }
     if (!JeproshopCombinationModelCombination::isFeaturePublished() || !isset($row->product_attribute_id)) {
         $row->product_attribute_id = 0;
     }
     // Tax
     $useTax = JeproshopTaxModelTax::taxExcludedOption();
     $cache_key = $row->product_id . '_' . $row->product_attribute_id . '_' . $lang_id . '_' . (int) $useTax;
     if (isset($row->product_pack_id)) {
         $cache_key .= '_pack_' . $row->product_pack_id;
     }
     if (isset(self::$_productPropertiesCache[$cache_key])) {
         return JeproshopTools::updateObjectData($row, self::$_productPropertiesCache[$cache_key]);
     }
     // Datas
     $row->category = JeproshopCategoryModelCategory::getLinkRewrite((int) $row->default_category_id, (int) $lang_id);
     $row->link = $context->controller->getProductLink((int) $row->product_id, $row->link_rewrite, $row->category, $row->ean13);
     $row->attribute_price = 0;
     if (isset($row->product_attribute_id) && $row->product_attribute_id) {
         $row->attribute_price = (double) JeproshopProductModelProduct::getProductAttributePrice($row->product_attribute_id);
     }
     $row->price_tax_exc = JeproshopProductModelProduct::getStaticPrice((int) $row->product_id, false, isset($row->product_attribute_id) && !empty($row->product_attribute_id) ? (int) $row->product_attribute_id : null, self::$_taxCalculationMethod == COM_JEPROSHOP_TAX_EXCLUDED ? 2 : 6);
     if (self::$_taxCalculationMethod == COM_JEPROSHOP_TAX_EXCLUDED) {
         $row->price_tax_exc = JeproshopTools::roundPrice($row->price_tax_exc, 2);
         $row->price = JeproshopProductModelProduct::getStaticPrice((int) $row->product_id, true, isset($row->product_attribute_id) && !empty($row->product_attribute_id) ? (int) $row->product_attribute_id : null, 6);
         $row->price_without_reduction = JeproshopProductModelProduct::getStaticPrice((int) $row->product_id, false, isset($row->product_attribute_id) && !empty($row->product_attribute_id) ? (int) $row->product_attribute_id : null, 2, null, false, false);
     } else {
         $row->price = JeproshopTools::roundPrice(JeproshopProductModelProduct::getStaticPrice((int) $row->product_id, true, isset($row->product_attribute_id) && !empty($row->product_attribute_id) ? (int) $row->product_attribute_id : null, 2), 2);
         $row->price_without_reduction = JeproshopProductModelProduct::getStaticPrice((int) $row->product_id, true, isset($row->product_attribute_id) && !empty($row->product_attribute_id) ? (int) $row->product_attribute_id : null, 6, null, false, false);
     }
     $specific_prices = null;
     $row->reduction = JeproshopProductModelProduct::getStaticPrice((int) $row->product_id, (bool) $useTax, (int) $row->product_attribute_id, 6, null, true, true, 1, true, null, null, null, $specific_prices);
     $row->specific_prices = $specific_prices;
     $row->quantity = JeproshopProductModelProduct::getQuantity((int) $row->product_id, 0, isset($row->cache_is_pack) ? $row->cache_is_pack : null);
     $row->quantity_all_versions = $row->quantity;
     if ($row->product_attribute_id) {
         $row->quantity = JeproshopProductModelProduct::getQuantity((int) $row->product_id, $row->product_attribute_id, isset($row->cache_is_pack) ? $row->cache_is_pack : null);
     }
     $row->image_id = JeproshopProductModelProduct::defineProductImage($row, $lang_id);
     $row->features = JeproshopProductModelProduct::getFrontStaticFeatures((int) $lang_id, $row->product_id);
     $row->attachments = array();
     if (!isset($row->cache_has_attachments) || $row->cache_has_attachments) {
         $row->attachments = JeproshopProductModelProduct::getStaticAttachments((int) $lang_id, $row->product_id);
     }
     $row->virtual = !isset($row->is_virtual) || $row->is_virtual ? 1 : 0;
     // Pack management
     $row->pack = !isset($row->cache_is_pack) ? JeproshopProductPack::isPack($row->product_id) : (int) $row->cache_is_pack;
     $row->packItems = $row->pack ? JeproshopProductPack::getItemTable($row->product_id, $lang_id) : array();
     $row->no_pack_price = $row->pack ? JeproshopProductPack::noPackPrice($row->product_id) : 0;
     if ($row->pack && !JeproshopProductPack::isInStock($row->product_id)) {
         $row->quantity = 0;
     }
     $row->customization_required = false;
     if (isset($row->customizable) && $row->customizable && JeproshopCustomization::isFeaturePublished()) {
         if (count(JeproshopProductModelProduct::getStaticRequiredCustomizableFields((int) $row->product_id))) {
             $row->customization_required = true;
         }
     }
     $row = JeproshopProductModelProduct::getTaxesInformations($row, $context);
     self::$_productPropertiesCache[$cache_key] = $row;
     return self::$_productPropertiesCache[$cache_key];
 }
Example #6
0
 /**
  * Assign price and tax to the template
  */
 protected function assignPriceAndTax()
 {
     $customer_id = isset($this->context->customer) ? (int) $this->context->customer->customer_id : 0;
     $group_id = (int) JeproshopGroupModelGroup::getCurrent()->group_id;
     $country_id = (int) $customer_id ? JeproshopCustomerModelCustomer::getCurrentCountry($customer_id) : JeproshopSettingModelSetting::getValue('default_country');
     $group_reduction = JeproshopGroupReductionModelGroupReduction::getValueForProduct($this->product->product_id, $group_id);
     if ($group_reduction === false) {
         $group_reduction = JeproshopGroupModelGroup::getReduction((int) $this->context->cookie->customer_id) / 100;
     }
     // Tax
     $tax = (double) $this->product->getTaxesRate(new JeproshopAddressModelAddress((int) $this->context->cart->{JeproshopSettingModelSetting::getValue('tax_address_type')}));
     $this->assignRef('tax_rate', $tax);
     $product_price_with_tax = JeproshopProductModelProduct::getStaticPrice($this->product->product_id, true, null, 6);
     if (JeproshopProductModelProduct::$_taxCalculationMethod == COM_JEPROSHOP_TAX_INCLUDED) {
         $product_price_with_tax = JeproshopTools::roundPrice($product_price_with_tax, 2);
     }
     $product_price_without_eco_tax = (double) $product_price_with_tax - $this->product->ecotax;
     $ecotax_rate = (double) JeproshopTaxModelTax::getProductEcotaxRate($this->context->cart->{JeproshopSettingModelSetting::getValue('tax_address_type')});
     $ecotax_tax_amount = JeproshopTools::roundPrice($this->product->ecotax, 2);
     if (JeproshopProductModelProduct::$_taxCalculationMethod == COM_JEPROSHOP_TAX_INCLUDED && (int) JeproshopSettingModelSetting::getValue('use_tax')) {
         $ecotax_tax_amount = JeproshopTools::roundPrice($ecotax_tax_amount * (1 + $ecotax_rate / 100), 2);
     }
     $currency_id = (int) $this->context->cookie->currency_id;
     $product_id = (int) $this->product->product_id;
     $shop_id = $this->context->shop->shop_id;
     $quantity_discounts = JeproshopSpecificPriceModelSpecificPrice::getQuantityDiscounts($product_id, $shop_id, $currency_id, $country_id, $group_id, null, true, (int) $this->context->customer->customer_id);
     foreach ($quantity_discounts as &$quantity_discount) {
         if ($quantity_discount->product_attribute_id) {
             $combination = new JeproshopCombinationModelCombination((int) $quantity_discount->product_attribute_id);
             $attributes = $combination->getAttributesName((int) $this->context->language->lang_id);
             foreach ($attributes as $attribute) {
                 $quantity_discount->attributes = $attribute->name . ' - ';
             }
             $quantity_discount->attributes = rtrim($quantity_discount->attributes, ' - ');
         }
         if ((int) $quantity_discount->currency_id == 0 && $quantity_discount->reduction_type == 'amount') {
             $quantity_discount->reduction = JeproshopTools::convertPriceFull($quantity_discount->reduction, null, JeproshopContext::getContext()->currency);
         }
     }
     $product_price = $this->product->getPrice(JeproshopProductModelProduct::$_taxCalculationMethod == COM_JEPROSHOP_TAX_INCLUDED, false);
     $address = new JeproshopAddressModelAddress($this->context->cart->{JeproshopSettingModelSetting::getValue('tax_address_type')});
     $quantity_discounts = $this->formatQuantityDiscounts($quantity_discounts, $product_price, (double) $tax, $ecotax_tax_amount);
     $this->assignRef('quantity_discounts', $quantity_discounts);
     $this->assignRef('ecotax_tax_included', $ecotax_tax_amount);
     $ecotax_tax_excluded = JeproshopTools::roundPrice($this->product->ecotax, 2);
     $this->assignRef('ecotax_tax_excluded', $ecotax_tax_excluded);
     $this->assignRef('ecotaxTax_rate', $ecotax_rate);
     $display_price = JeproshopSettingModelSetting::getValue('display_price');
     $this->assignRef('display_price', $display_price);
     $product_price_without_eco_tax = (double) $product_price_without_eco_tax;
     $this->assignRef('product_price_without_ecotax', $product_price_without_eco_tax);
     $this->assignRef('group_reduction', $group_reduction);
     $no_tax = JeproshopTaxModelTax::taxExcludedOption() || !$this->product->getTaxesRate($address);
     $this->assignRef('no_tax', $no_tax);
     $ecotax = !count($this->errors) && $this->product->ecotax > 0 ? JeproshopTools::convertPrice((double) $this->product->ecotax) : 0;
     $this->assignRef('ecotax', $ecotax);
     $tax_enabled = JeproshopSettingModelSetting::getValue('use_tax');
     $this->assignRef('tax_enabled', $tax_enabled);
     $customer_group_without_tax = JeproshopGroupModelGroup::getPriceDisplayMethod($this->context->customer->default_group_id);
     $this->assignRef('customer_group_without_tax', $customer_group_without_tax);
 }
Example #7
0
 /**
  * Return package shipping cost
  *
  * @param integer $carrier_id Carrier ID (default : current carrier)
  * @param boolean $use_tax
  * @param JeproshopCountryModelCountry $default_country
  * @param Array $product_list
  * @param array $product_list List of product concerned by the shipping. If null, all the product of the cart are used to calculate the shipping cost
  *
  * @return float Shipping total
  */
 public function getPackageShippingCost($carrier_id = null, $use_tax = true, JeproshopCountryModelCountry $default_country = null, $product_list = null, $zone_id = null)
 {
     if ($this->isVirtualCart()) {
         return 0;
     }
     if (!$default_country) {
         $default_country = JeproshopContext::getContext()->country;
     }
     $complete_product_list = $this->getProducts();
     if (is_null($product_list)) {
         $products = $complete_product_list;
     } else {
         $products = $product_list;
     }
     if (JeproshopSettingModelSetting::getValue('tax_address_type') == 'address_invoice_id') {
         $address_id = (int) $this->address_invoice_id;
     } elseif (count($product_list)) {
         $prod = current($product_list);
         $address_id = (int) $prod->address_delivery_id;
     } else {
         $address_id = null;
     }
     if (!JeproshopAddressModelAddress::addressExists($address_id)) {
         $address_id = null;
     }
     $cache_id = 'get_package_shipping_cost_' . (int) $this->cart_id . '_' . (int) $address_id . '_' . (int) $carrier_id . '_' . (int) $use_tax . '_' . (int) $default_country->country_id;
     if ($products) {
         foreach ($products as $product) {
             $cache_id .= '_' . (int) $product->product_id . '_' . (int) $product->product_attribute_id;
         }
     }
     if (JeproshopCache::isStored($cache_id)) {
         return JeproshopCache::retrieve($cache_id);
     }
     // Order total in default currency without fees
     $order_total = $this->getOrderTotal(true, JeproshopCartModelCart::ONLY_PHYSICAL_PRODUCTS_WITHOUT_SHIPPING, $product_list);
     // Start with shipping cost at 0
     $shipping_cost = 0;
     // If no product added, return 0
     if (!count($products)) {
         JeproshopCache::store($cache_id, $shipping_cost);
         return $shipping_cost;
     }
     if (!isset($zone_id)) {
         // Get id zone
         if (!$this->isMultiAddressDelivery() && isset($this->address_delivery_id) && $this->address_delivery_id && JeproshopCustomerModelCustomer::customerHasAddress($this->customer_id, $this->address_delivery_id)) {
             $zone_id = JeproshopAddressModelAddress::getZoneIdByAddressId((int) $this->address_delivery_id);
         } else {
             if (!JeproshopValidator::isLoadedObject($default_country, 'country_id')) {
                 $default_country = new Country(JeproshopSettingModelSeting::getValue('PS_COUNTRY_DEFAULT'), JeproshopSettingModelSeting::getValue('PS_LANG_DEFAULT'));
             }
             $zone_id = (int) $default_country->zone_id;
         }
     }
     if ($carrier_id && !$this->isCarrierInRange((int) $carrier_id, (int) $zone_id)) {
         $carrier_id = '';
     }
     if (empty($carrier_id) && $this->isCarrierInRange((int) JeproshopSettingModelSeting::getValue('default_carrier'), (int) $zone_id)) {
         $carrier_id = (int) JeproshopSettingModelSeting::getValue('default_carrier');
     }
     $total_package_without_shipping_tax_inc = $this->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING, $product_list);
     if (empty($carrier_id)) {
         if ((int) $this->customer_id) {
             $customer = new JeproshopCustomerModelCustomer((int) $this->customer_id);
             $result = JeproshopCarrierModelCarrier::getCarriers((int) JeproshopSettingModelSeting::getValue('default_lang'), true, false, (int) $zone_id, $customer->getGroups());
             unset($customer);
         } else {
             $result = JeproshopCarrierModelCarrier::getCarriers((int) JeproshopSettingModelSeting::getValue('default_lang'), true, false, (int) $zone_id);
         }
         foreach ($result as $k => $row) {
             if ($row->carrier_id == JeproshopSettingModelSeting::getValue('default_carrier')) {
                 continue;
             }
             if (!isset(self::$_carriers[$row->carrier_id])) {
                 self::$_carriers[$row->carrier_id] = new JeproshopCarrierModelCarrier((int) $row->carrier_id);
             }
             $carrier = self::$_carriers[$row->carrier_id];
             // Get only carriers that are compliant with shipping method
             if ($carrier->getShippingMethod() == JeproshopCarrierModelCarrier::WEIGHT_SHIPPING_METHOD && $carrier->getMaxDeliveryPriceByWeight((int) $zone_id) === false || $carrier->getShippingMethod() == JeproshopCarrierModelCarrier::PRICE_SHIPPING_METHOD && $carrier->getMaxDeliveryPriceByPrice((int) $zone_id) === false) {
                 unset($result[$k]);
                 continue;
             }
             // If out-of-range behavior carrier is set on "Deactivated carrier"
             if ($row->range_behavior) {
                 $check_delivery_price_by_weight = JeproshopCarrierModelCarrier::checkDeliveryPriceByWeight($row->carrier_id, $this->getTotalWeight(), (int) $zone_id);
                 $total_order = $total_package_without_shipping_tax_inc;
                 $check_delivery_price_by_price = JeproshopCarrierModelCarrier::checkDeliveryPriceByPrice($row->carrier_id, $total_order, (int) $zone_id, (int) $this->currency_id);
                 // Get only carriers that have a range compatible with cart
                 if ($carrier->getShippingMethod() == JeproshopCarrierModelCarrier::WEIGHT_SHIPPING_METHOD && !$check_delivery_price_by_weight || $carrier->getShippingMethod() == JeproshopCarrierModelCarrier::PRICE_SHIPPING_METHOD && !$check_delivery_price_by_price) {
                     unset($result[$k]);
                     continue;
                 }
             }
             if ($carrier->getShippingMethod() == JeproshopCarrierModelCarrier::WEIGHT_SHIPPING_METHOD) {
                 $shipping = $carrier->getDeliveryPriceByWeight($this->getTotalWeight($product_list), (int) $zone_id);
             } else {
                 $shipping = $carrier->getDeliveryPriceByPrice($order_total, (int) $zone_id, (int) $this->currency_id);
             }
             if (!isset($min_shipping_price)) {
                 $min_shipping_price = $shipping;
             }
             if ($shipping <= $min_shipping_price) {
                 $carrier_id = (int) $row->carrier_id;
                 $min_shipping_price = $shipping;
             }
         }
     }
     if (empty($carrier_id)) {
         $carrier_id = JeproshopSettingModelSeting::getValue('default_carrier');
     }
     if (!isset(self::$_carriers[$carrier_id])) {
         self::$_carriers[$carrier_id] = new JeproshopCarrierModelCarrier((int) $carrier_id, JeproshopSettingModelSeting::getValue('default_lang'));
     }
     $carrier = self::$_carriers[$carrier_id];
     // No valid Carrier or $carrier_id <= 0 ?
     if (!JeproshopValidator::isLoadedObject($carrier, 'carrier_id')) {
         JeproshopCache::store($cache_id, 0);
         return 0;
     }
     if (!$carrier->published) {
         JeproshopCache::store($cache_id, $shipping_cost);
         return $shipping_cost;
     }
     // Free fees if free carrier
     if ($carrier->is_free == 1) {
         JeproshopCache::store($cache_id, 0);
         return 0;
     }
     // Select carrier tax
     if ($use_tax && !JeproshopTaxModelTax::excludedTaxOption()) {
         $address = JeproshopAddressModelAddress::initialize((int) $address_id);
         $carrier_tax = $carrier->getTaxesRate($address);
     }
     $configuration = JeproshopSettingModelSeting::getValueMultiple(array('PS_SHIPPING_FREE_PRICE', 'PS_SHIPPING_HANDLING', 'PS_SHIPPING_METHOD', 'PS_SHIPPING_FREE_WEIGHT'));
     // Free fees
     $free_fees_price = 0;
     if (isset($configuration['PS_SHIPPING_FREE_PRICE'])) {
         $free_fees_price = JeproshopValidator::convertPrice((double) $configuration['PS_SHIPPING_FREE_PRICE'], JeproshopCurrencyModelCurrency::getCurrencyInstance((int) $this->currency_id));
     }
     $orderTotalWithDiscounts = $this->getOrderTotal(true, JeproshopCartModelCart::BOTH_WITHOUT_SHIPPING, null, null, false);
     if ($orderTotalWithDiscounts >= (double) $free_fees_price && (double) $free_fees_price > 0) {
         Cache::store($cache_id, $shipping_cost);
         return $shipping_cost;
     }
     if (isset($configuration['PS_SHIPPING_FREE_WEIGHT']) && $this->getTotalWeight() >= (double) $configuration['PS_SHIPPING_FREE_WEIGHT'] && (double) $configuration['PS_SHIPPING_FREE_WEIGHT'] > 0) {
         JeproshopCache::store($cache_id, $shipping_cost);
         return $shipping_cost;
     }
     // Get shipping cost using correct method
     if ($carrier->range_behavior) {
         if (!isset($zone_id)) {
             // Get id zone
             if (isset($this->address_delivery_id) && $this->address_delivery_id && JeproshopCustomerModelCustomer::customerHasAddress($this->customer_id, $this->address_delivery_id)) {
                 $zone_id = JeproshopAddressModelAddress::getZoneIdByAddressId((int) $this->address_delivery_id);
             } else {
                 $zone_id = (int) $default_country->zone_id;
             }
         }
         if ($carrier->getShippingMethod() == JeproshopCarrierModelCarrier::WEIGHT_SHIPPING_METHOD && !JeproshopCarrierModelCarrier::checkDeliveryPriceByWeight($carrier->id, $this->getTotalWeight(), (int) $zone_id) || $carrier->getShippingMethod() == JeproshopCarrierModelCarrier::PRICE_SHIPPING_METHOD && !JeproshopCarrierModelCarrier::checkDeliveryPriceByPrice($carrier->id, $total_package_without_shipping_tax_inc, $zone_id, (int) $this->currency_id)) {
             $shipping_cost += 0;
         } else {
             if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT) {
                 $shipping_cost += $carrier->getDeliveryPriceByWeight($this->getTotalWeight($product_list), $zone_id);
             } else {
                 // by price
                 $shipping_cost += $carrier->getDeliveryPriceByPrice($order_total, $zone_id, (int) $this->currency_id);
             }
         }
     } else {
         if ($carrier->getShippingMethod() == JeproshopCarrierModelCarrier::WEIGHT_SHIPPING_METHOD) {
             $shipping_cost += $carrier->getDeliveryPriceByWeight($this->getTotalWeight($product_list), $zone_id);
         } else {
             $shipping_cost += $carrier->getDeliveryPriceByPrice($order_total, $zone_id, (int) $this->currency_id);
         }
     }
     // Adding handling charges
     if (isset($configuration['PS_SHIPPING_HANDLING']) && $carrier->shipping_handling) {
         $shipping_cost += (double) $configuration['PS_SHIPPING_HANDLING'];
     }
     // Additional Shipping Cost per product
     foreach ($products as $product) {
         if (!$product->is_virtual) {
             $shipping_cost += $product->additional_shipping_cost * $product->cart_quantity;
         }
     }
     $shipping_cost = JeproshopValidator::convertPrice($shipping_cost, JeproshopCurrencyModelCurrency::getCurrencyInstance((int) $this->currency_id));
     /*/get external shipping cost from module
             if ($carrier->shipping_external)
             {
                 $module_name = $carrier->external_module_name;
                 $module = Module::getInstanceByName($module_name);
     
                 if (JeproshopValidator::isLoadedObject($module))
                 {
                     if (array_key_exists('carrier_id', $module))
                         $module->carrier_id = $carrier->id;
                     if ($carrier->need_range)
                         if (method_exists($module, 'getPackageShippingCost'))
                             $shipping_cost = $module->getPackageShippingCost($this, $shipping_cost, $products);
                         else
                             $shipping_cost = $module->getOrderShippingCost($this, $shipping_cost);
                     else
                         $shipping_cost = $module->getOrderShippingCostExternal($this);
     
                     // Check if carrier is available
                     if ($shipping_cost === false)
                     {
                         JeproshopCache::store($cache_id, false);
                         return false;
                     }
                 }
                 else
                 {
                     JeproshopCache::store($cache_id, false);
                     return false;
                 }
             } */
     // Apply tax
     if ($use_tax && isset($carrier_tax)) {
         $shipping_cost *= 1 + $carrier_tax / 100;
     }
     $shipping_cost = (double) JeproshopValidator::roundPrice((double) $shipping_cost, 2);
     JeproshopCache::store($cache_id, $shipping_cost);
     return $shipping_cost;
 }
Example #8
0
 private function initPriceForm()
 {
     if ($this->context == null) {
         $this->context = JeproshopContext::getContext();
     }
     if ($this->product->product_id) {
         $shops = JeproshopShopModelShop::getShops();
         $countries = JeproshopCountryModelCountry::getStaticCountries($this->context->language->lang_id);
         $groups = JeproshopGroupModelGroup::getStaticGroups($this->context->language->lang_id);
         $currencies = JeproshopCurrencyModelCurrency::getStaticCurrencies();
         $attributes = $this->product->getAttributesGroups((int) $this->context->language->lang_id);
         $combinations = array();
         if (count($attributes)) {
             foreach ($attributes as $attribute) {
                 $combinations[$attribute->product_attribute_id] = new JObject();
                 $combinations[$attribute->product_attribute_id]->product_attribute_id = $attribute->product_attribute_id;
                 if (!isset($combinations[$attribute->product_attribute_id]->attributes)) {
                     $combinations[$attribute->product_attribute_id]->attributes = '';
                 }
                 if (isset($combinations[$attribute->product_attribute_id])) {
                     $combinations[$attribute->product_attribute_id]->attributes .= $attribute->attribute_name . ' - ';
                     $combinations[$attribute->product_attribute_id]->price = JeproshopTools::displayPrice(JeproshopTools::convertPrice(JeproshopProductModelProduct::getStaticPrice((int) $this->product->product_id, false, $attribute->product_attribute_id), $this->context->currency), $this->context->currency);
                 }
             }
             foreach ($combinations as $combination) {
                 if (isset($combination->attributes)) {
                     $combination->attributes = rtrim($combination->attributes, ' - ');
                 }
             }
         }
         $specificPriceModificationForm = $this->displaySpecificPriceModificationForm($this->context->currency, $shops, $currencies, $countries, $groups);
         $this->assignRef('specific_price_modification_form', $specificPriceModificationForm);
         $this->assignRef('ecotax_tax_excluded', $this->product->ecotax);
         //$this->applyTaxToEcotax();
         $this->assignRef('shops', $shops);
         /*$admin_one_shop = count($this->context->employee->getAssociatedShops()) == 1;
           $this->assignRef('admin_one_shop', $admin_one_shop); */
         $this->assignRef('currencies', $currencies);
         $this->assignRef('currency', $this->context->currency);
         $this->assignRef('countries', $countries);
         $this->assignRef('groups', $groups);
         $this->assignRef('combinations', $combinations);
         $multiShop = JeproshopShopModelShop::isFeaturePublished();
         $this->assignRef('multi_shop', $multiShop);
     } else {
         JError::raiseWarnig(JText::_('COM_JEPROSHOP_YOU_MUST_SAVE_THIS_PRODUCT_BEFORE_ADDING_SPECIFIC_PRICING_MESSAGE'));
         $this->product->tax_rules_group_id = JeproshopProductModelProduct::getTaxRulesMostUsedGroupId();
         $this->assignRef('ecotax_tax_excluded', 0);
     }
     $use_tax = JeproshopSettingModelSetting::getValue('use_tax');
     $this->assignRef('use_tax', $use_tax);
     $use_ecotax = JeproshopSettingModelSetting::getValue('use_eco_tax');
     $this->assignRef('use_ecotax', $use_ecotax);
     $tax_rules_groups = JeproshopTaxRulesGroupModelTaxRulesGroup::getTaxRulesGroups(true);
     $this->assignRef('tax_rules_groups', $tax_rules_groups);
     $taxesRatesByGroup = JeproshopTaxRulesGroupModelTaxRulesGroup::getAssociatedTaxRatesByCountryId($this->context->country->country_id);
     $this->assignRef('taxesRatesByGroup', $taxesRatesByGroup);
     $ecotaxTaxRate = JeproshopTaxModelTax::getProductEcotaxRate();
     $this->assignRef('ecotaxTaxRate', $ecotaxTaxRate);
     $tax_exclude_tax_option = JeproshopTaxModelTax::taxExcludedOption();
     $this->assignRef('tax_exclude_tax_option', $tax_exclude_tax_option);
     $this->product->price = JeproshopTools::convertPrice($this->product->price, $this->context->currency, true, $this->context);
     if ($this->product->unit_price_ratio != 0) {
         $unit_price = JeproshopTools::roundPrice($this->product->price / $this->product->unit_price_ratio, 2);
     } else {
         $unit_price = 0;
     }
     $this->assignRef('unit_price', $unit_price);
 }
Example #9
0
 /**
  * Get product price
  *
  * @param integer $product_id Product id
  * @param boolean $use_tax With taxes or not (optional)
  * @param integer $product_attribute_id Product attribute id (optional).
  *    If set to false, do not apply the combination price impact. NULL does apply the default combination price impact.
  * @param integer $decimals Number of decimals (optional)
  * @param boolean $only_reduction Returns only the reduction amount
  * @param boolean $use_reduction Set if the returned amount will include reduction
  * @param integer $quantity Required for quantity discount application (default value: 1)
  * @param integer $customer_id Customer ID (for customer group reduction)
  * @param integer $cart_id Cart ID. Required when the cookie is not accessible (e.g., inside a payment module, a cron task...)
  * @param integer $address_id Customer address ID. Required for price (tax included) calculation regarding the guest localization
  * @param null $specific_price_output
  * @param boolean $with_ecotax insert ecotax in price output.
  * @param bool $use_group_reduction
  * @param JeproshopContext $context
  * @param bool $use_customer_price
  * @internal param int $divisor Useful when paying many time without fees (optional)
  * @internal param \variable_reference $specificPriceOutput .
  *    If a specific price applies regarding the previous parameters, this variable is filled with the corresponding SpecificPrice object
  * @return float Product price
  */
 public static function getStaticPrice($product_id, $use_tax = true, $product_attribute_id = null, $decimals = 6, $only_reduction = false, $use_reduction = true, $quantity = 1, $customer_id = null, $cart_id = null, $address_id = null, $specific_price_output = null, $with_ecotax = true, $use_group_reduction = true, JeproshopContext $context = null, $use_customer_price = true)
 {
     if (!$context) {
         $context = JeproshopContext::getContext();
     }
     $cur_cart = $context->cart;
     if (!JeproshopTools::isBool($use_tax) || !JeproshopTools::isUnsignedInt($product_id)) {
         //die(Tools::displayError());
     }
     // Initializations
     $group_id = (int) JeproshopGroupModelGroup::getCurrent()->group_id;
     // If there is cart in context or if the specified id_cart is different from the context cart id
     if (!is_object($cur_cart) || JeproshopTools::isUnsignedInt($cart_id) && $cart_id && $cur_cart->cart_id != $cart_id) {
         /*
          * When a user (e.g., guest, customer, Google...) is on Jeproshop, he has already its cart as the global (see /init.php)
          * When a non-user calls directly this method (e.g., payment module...) is on JeproShop, he does not have already it BUT knows the cart ID
          * When called from the back office, cart ID can be in-existent
          */
         if (!$cart_id && !isset($context->employee)) {
             JError::raiseError(500, __FILE__ . ' ' . __LINE__);
         }
         $cur_cart = new JeproshopCartModelCart($cart_id);
         // Store cart in context to avoid multiple instantiations in BO
         if (!JeproshopTools::isLoadedObject($context->cart, 'cart_id')) {
             $context->cart = $cur_cart;
         }
     }
     $db = JFactory::getDBO();
     $cart_quantity = 0;
     if ((int) $cart_id) {
         $cache_id = 'jeproshop_product_model_get_price_static_' . (int) $product_id . '_' . (int) $cart_id;
         $cart_qty = JeproshopCache::retrieve($cache_id);
         if (!JeproshopCache::isStored($cache_id) || $cart_qty != (int) $quantity) {
             $query = "SELECT SUM(" . $db->quoteName('quantity') . ") FROM " . $db->quoteName('#__jeproshop_cart_product');
             $query .= " WHERE " . $db->quoteName('product_id') . " = " . (int) $product_id . " AND " . $db->quoteName('cart_id');
             $query .= " = " . (int) $cart_id;
             $db->setQuery($query);
             $cart_quantity = (int) $db->loadResult();
             JeproshopCache::store($cache_id, $cart_quantity);
         }
         $cart_quantity = JeproshopCache::retrieve($cache_id);
     }
     $currency_id = (int) JeproshopTools::isLoadedObject($context->currency, 'currency_id') ? $context->currency->currency_id : JeproshopSettingModelSetting::getValue('default_currency');
     // retrieve address information
     $country_id = (int) $context->country->country_id;
     $state_id = 0;
     $zipcode = 0;
     if (!$address_id && JeproshopTools::isLoadedObject($cur_cart, 'cart_id')) {
         $address_id = $cur_cart->{JeproshopSettingModelSetting::getValue('tax_address_type')};
     }
     if ($address_id) {
         $address_info = JeproshopAddressModelAddress::getCountryAndState($address_id);
         if ($address_info->country_id) {
             $country_id = (int) $address_info->country_id;
             $state_id = (int) $address_info->state_id;
             $zipcode = $address_info->postcode;
         }
     } else {
         if (isset($context->customer->geolocation_country_id)) {
             $country_id = (int) $context->customer->geolocation_country_id;
             $state_id = (int) $context->customer->state_id;
             $zipcode = (int) $context->customer->postcode;
         }
     }
     if (JeproshopTaxModelTax::taxExcludedOption()) {
         $use_tax = false;
     }
     if ($use_tax != false && !empty($address_info->vat_number) && $address_info->country_id != JeproshopSettingModelSetting::getValue('vat_number_country') && JeproshopSettingModelSetting::getValue('vat_number_management')) {
         $use_tax = false;
     }
     if (is_null($customer_id) && JeproshopTools::isLoadedObject($context->customer, 'customer_id')) {
         $customer_id = $context->customer->customer_id;
     }
     return JeproshopProductModelProduct::priceCalculation($context->shop->shop_id, $product_id, $product_attribute_id, $country_id, $state_id, $zipcode, $currency_id, $group_id, $quantity, $use_tax, $decimals, $only_reduction, $use_reduction, $with_ecotax, $specific_price_output, $use_group_reduction, $customer_id, $use_customer_price, $cart_id, $cart_quantity);
 }
Example #10
0
 public function update($nullValues = false)
 {
     if (!$this->deleted && $this->isUsed()) {
         $historized_tax = new JeproshopTaxModelTax($this->tax_id);
         $historized_tax->historize();
         // remove the id in order to create a new object
         $this->tax_id = 0;
         $res = $this->add();
         // change tax id in the tax rule table
         $res &= JeproshopTaxRuleModelTaxRule::swapTaxId($historized_tax->tax_id, $this->tax_id);
         return $res;
     } elseif ($this->updateTax()) {
         return $this->onStatusChange();
     }
     return false;
 }