public function add() { $db = JFactory::getDBO(); $query = "INSERT INTO " . $db->quoteName('#__jeproshop_specific_price') . "(" . $db->quoteName('specific_price_rule_id'); $query .= ", " . $db->quoteName('product_id') . ", " . $db->quoteName('shop_id') . ", " . $db->quoteName('shop_group_id'); $query .= ", " . $db->quoteName('currency_id') . ", " . $db->quoteName('country_id') . ", " . $db->quoteName('group_id'); $query .= ", " . $db->quoteName('customer_id') . ", " . $db->quoteName('product_attribute_id') . ", " . $db->quoteName('price'); $query .= ", " . $db->quoteName('from_quantity') . ", " . $db->quoteName('reduction') . ", " . $db->quoteName('reduction_type'); $query .= ", " . $db->quoteName('from') . ", " . $db->quoteName('to') . ") VALUES (" . (int) $this->specific_price_rule_id . ", "; $query .= (int) $this->product_id . ", " . (int) $this->shop_id . ", " . (int) $this->shop_group_id . ", " . (int) $this->currency_id . ", "; $query .= (int) $this->country_id . ", " . (int) $this->group_id . ", " . (int) $this->customer_id . ", " . (int) $this->product_attribute_id; $query .= ", " . (double) $this->price . ", " . (int) $this->from_quantity . ", " . (double) $this->reduction . ", " . $db->quote($this->reduction_type); $query .= ", " . $db->quote($this->from) . ", " . $db->quote($this->to) . ")"; $db->setQuery($query); if ($db->query()) { // Flush cache when we adding a new specific price JeproshopSpecificPriceModelSpecificPrice::$_specific_price_cache = array(); JeproshopProductModelProduct::flushPriceCache(); // Set cache of feature detachable to true JeproshopSettingModelSetting::updateValue('specific_price_feature_active', '1'); return true; } return false; }
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) ));*/ }
public function product() { // Update the cart ONLY if $this->cookies are available, in order to avoid ghost carts created by bots if (!$this->context) { $this->context = JeproshopContext::getContext(); } if ($this->context->cookie->exists() && !$this->has_errors && !($this->context->customer->isLogged() && !$this->isTokenValid())) { // Send noindex to avoid ghost carts by bots header("X-Robots-Tag: noindex, nofollow", true); if (!$this->isInitialized()) { $this->initialize(); } $app = JFactory::getApplication(); $product_id = $app->input->get('product_id', null); $customization_id = (int) $app->input->get('customization_id', null); $address_delivery_id = (int) $app->input->get('address_delivery_id', null); $product_attribute_id = $app->input->get('product_attribute_id', null); $mode = $app->input->get('task') == 'update' && $product_id ? 'update' : 'add'; if ($app->input->get('quantity') == 0) { $this->has_errors = true; echo JText::_('COM_JEPROSHOP_NULL_QUANTITY_MESSAGE') . ' ' . !$app->input->get('use_ajax'); } elseif (!$product_id) { $this->has_errors = true; echo JText::_('COM_JEPROSHOP_PRODUCT_ID_NOT_FOUND_MESSAGE') . ' ' . !$app->input->get('use_ajax'); } $product = new JeproshopProductModelProduct($product_id, true, $this->context->language->lang_id); if (!$product->product_id || !$product->published) { $this->has_errors = true; echo JText::_('COM_JEPROSHOP_THIS_PRODUCT_IS_NO_LONGER_AVAILABLE_MESSAGE.') . ' ' . !$app->input->get('use_ajax'); exit; } $quantity = abs($app->input->get('quantity', 1)); $qty_to_check = $quantity; $cart_products = $this->context->cart->getProducts(); if (is_array($cart_products)) { foreach ($cart_products as $cart_product) { if ((!isset($this->product_attribute_id) || $cart_product->product_attribute_id == $product_attribute_id) && (isset($product_id) && $cart_product->product_id == $product_id)) { $qty_to_check = $cart_product->cart_quantity; if ($app->input->get('op', 'up') == 'down') { $qty_to_check -= $quantity; } else { $qty_to_check += $quantity; } break; } } } // Check product quantity availability if ($product_attribute_id) { if (!JeproshopProductModelProduct::isAvailableWhenOutOfStock($product->out_of_stock) && !JeproshopAttributeModelAttribute::checkAttributeQty($product_attribute_id, $qty_to_check)) { $this->has_errors = true; echo JText::_('COM_JEPROSHOP_THERE_IS_NOT_ENOUGH_PRODUCT_IN_STOCK_MESSAGE') . ' ' . __LINE__ . !$app->input->get('use_ajax'); } } elseif ($product->hasAttributes()) { $minimumQuantity = $product->out_of_stock == 2 ? !JeproshopSettingModelSetting::getValue('order_out_of_stock') : !$product->out_of_stock; $product_attribute_id = JeproshopProductModelProduct::getDefaultAttribute($product->product_id, $minimumQuantity); // @todo do something better than a redirect admin !! if (!$product_attribute_id) { $app->redirect($this->getProductLink($product)); } elseif (!JeproshopProductModelProduct::isAvailableWhenOutOfStock($product->out_of_stock) && !JeproshopAttributeModelAttribute::checkAttributeQty($product_attribute_id, $qty_to_check)) { $this->has_errors = true; echo JText::_('COM_JEPROSHOP_THERE_IS_NOT_ENOUGH_PRODUCT_IN_STOCK_MESSAGE') . ' ' . __LINE__ . !$app->input->get('use_ajax'); } } elseif (!$product->checkQuantity($qty_to_check)) { $this->has_errors = true; echo JText::_('COM_JEPROSHOP_THERE_IS_NOT_ENOUGH_PRODUCT_IN_STOCK_MESSAGE') . ' ' . __LINE__ . !$app->input->get('use_ajax'); } // If no errors, process product addition if ($mode == 'add') { // Add cart if no cart found if (!$this->context->cart->cart_id) { if (JeproshopContext::getContext()->cookie->guest_id) { $guest = new JeproshopGuestModelGuest(JeproshopContext::getContext()->cookie->guest_id); $this->context->cart->mobile_theme = $guest->mobile_theme; } $this->context->cart->add(); if ($this->context->cart->cart_id) { $this->context->cookie->cart_id = (int) $this->context->cart->cart_id; } } // Check customizable fields if (!$product->hasAllRequiredCustomizableFields() && !$customization_id) { // $this->errors[] = Tools::displayError('Please fill in all of the required fields, and then save your customizations.', !Tools::getValue('ajax')); } if (!$this->has_errors) { $cart_rules = $this->context->cart->getCartRules(); $update_quantity = $this->context->cart->updateQuantity($quantity, $product_id, $product_attribute_id, $customization_id, $app->input->get('op', 'up'), $address_delivery_id); if ($update_quantity < 0) { // If product has attribute, minimal quantity is set with minimal quantity of attribute $minimal_quantity = $product_attribute_id ? JeproshopAttributeModelAttribute::getAttributeMinimalQty($product_attribute_id) : $product->minimal_quantity; $this->has_errors = true; sprintf(Tools::displayError('You must add %d minimum quantity', !$app->input->get('use_ajax')), $minimal_quantity); } elseif (!$update_quantity) { $this->has_errors = true; echo JText::_('COM_JEPROSHOP_YOU_ALREADY_HAVE_THE_MAXIMUM_AVAILABLE_FOR_THIS_PRODUCT_MESSAGE') . ' ' . !$app->input->get('use_ajax'); } elseif ((int) $app->input->get('allow_refresh')) { // If the cart rules has changed, we need to refresh the whole cart $cart_rules2 = $this->context->cart->getCartRules(); if (count($cart_rules2) != count($cart_rules)) { $this->ajax_refresh = true; } else { $rule_list = array(); foreach ($cart_rules2 as $rule) { $rule_list[] = $rule->cart_rule_id; } foreach ($cart_rules as $rule) { if (!in_array($rule->cart_rule_id, $rule_list)) { $this->ajax_refresh = true; break; } } } } } } $removed = JeproshopCartRuleModelCartRule::autoRemoveFromCart(); JeproshopCartRuleModelCartRule::autoAddToCart(); if (count($removed) && (int) $app->input->get('allow_refresh')) { $this->ajax_refresh = true; } echo 'bonjour'; exit; } elseif (!$this->context->cookie->exists()) { echo 'bonjour cookkie'; exit; } elseif ($this->has_errors) { } elseif ($this->context->customer->isLogged() && !$this->isTokenValid()) { } }
/** * For a given id_product, synchronizes StockAvailable::quantity with Stock::usable_quantity * * @param int $product_id * @param int $order_shop_id * @return bool */ public static function synchronize($product_id, $order_shop_id = null) { if (!JeproshopTools::isUnsignedInt($product_id)) { return false; } $db = JFactory::getDBO(); // gets warehouse ids grouped by shops $warehouse_ids = JeproshopWarehouseModelWarehouse::getWarehousesGroupedByShops(); if ($order_shop_id !== null) { $order_warehouses = array(); $warehouses = JeproshopWarehouseModelWarehouse::getWarehouses(false, (int) $order_shop_id); foreach ($warehouses as $warehouse) { $order_warehouses[] = $warehouse->warehouse_id; } } // gets all product attributes ids $product_attribute_ids = array(); foreach (JeproshopProductModelProduct::getProductAttributesIds($product_id) as $product_attribute_id) { $product_attribute_ids[] = $product_attribute_id->product_attribute_id; } // Allow to order the product when out of stock? $out_of_stock = JeproshopStockAvailableModelStockAvailable::outOfStock($product_id); $manager = JeproshopStockManagerFactory::getManager(); // loops on $ids_warehouse to synchronize quantities foreach ($warehouse_ids as $shop_id => $warehouses) { // first, checks if the product depends on stock for the given shop $id_shop if (JeproshopStockAvailableModelStockAvailable::dependsOnStock($product_id, $shop_id)) { // init quantity $product_quantity = 0; // if it's a simple product if (empty($product_attribute_ids)) { $allowed_warehouse_for_product = JeproshopWarehouseModelWarehouse::getProductWarehouseList((int) $product_id, 0, (int) $shop_id); $allowed_warehouse_for_product_clean = array(); foreach ($allowed_warehouse_for_product as $warehouse) { $allowed_warehouse_for_product_clean[] = (int) $warehouse->warehouse_id; } $allowed_warehouse_for_product_clean = array_intersect($allowed_warehouse_for_product_clean, $warehouses); if ($order_shop_id != null && !count(array_intersect($allowed_warehouse_for_product_clean, $order_warehouses))) { continue; } $product_quantity = $manager->getProductRealQuantities($product_id, null, $allowed_warehouse_for_product_clean, true); /*Hook::exec('actionUpdateQuantity', array( 'id_product' => $id_product, 'id_product_attribute' => 0, 'quantity' => $product_quantity ) );*/ } else { // else this product has attributes, hence loops on $ids_product_attribute foreach ($product_attribute_ids as $product_attribute_id) { $allowed_warehouse_for_combination = JeproshopWarehouseModelWarehouse::getProductWarehouseList((int) $product_id, (int) $product_attribute_id, (int) $shop_id); $allowed_warehouse_for_combination_clean = array(); foreach ($allowed_warehouse_for_combination as $warehouse) { $allowed_warehouse_for_combination_clean[] = (int) $warehouse->warehouse_id; } $allowed_warehouse_for_combination_clean = array_intersect($allowed_warehouse_for_combination_clean, $warehouses); if ($order_shop_id != null && !count(array_intersect($allowed_warehouse_for_combination_clean, $order_warehouses))) { continue; } $quantity = $manager->getProductRealQuantities($product_id, $product_attribute_id, $allowed_warehouse_for_combination_clean, true); $query = new DbQuery(); $query->select('COUNT(*)'); $query->from('stock_available'); $query->where('id_product = ' . (int) $product_id . ' AND id_product_attribute = ' . (int) $product_attribute_id . StockAvailable::addSqlShopRestriction(null, $shop_id)); if ((int) Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query)) { $query = array('table' => 'stock_available', 'data' => array('quantity' => $quantity), 'where' => 'id_product = ' . (int) $product_id . ' AND id_product_attribute = ' . (int) $product_attribute_id . StockAvailable::addSqlShopRestriction(null, $shop_id)); Db::getInstance()->update($query['table'], $query['data'], $query['where']); } else { $query = array('table' => 'stock_available', 'data' => array('quantity' => $quantity, 'depends_on_stock' => 1, 'out_of_stock' => $out_of_stock, 'id_product' => (int) $id_product, 'id_product_attribute' => (int) $id_product_attribute)); StockAvailable::addSqlShopParams($query['data']); Db::getInstance()->insert($query['table'], $query['data']); } $product_quantity += $quantity; Hook::exec('actionUpdateQuantity', array('id_product' => $id_product, 'id_product_attribute' => $id_product_attribute, 'quantity' => $quantity)); } } // updates // if $id_product has attributes, it also updates the sum for all attributes $query = array('table' => 'stock_available', 'data' => array('quantity' => $product_quantity), 'where' => 'id_product = ' . (int) $id_product . ' AND id_product_attribute = 0' . StockAvailable::addSqlShopRestriction(null, $shop_id)); Db::getInstance()->update($query['table'], $query['data'], $query['where']); } } // In case there are no warehouses, removes product from StockAvailable if (count($warehouse_ids) == 0 && JeproshopStockAvailableModelStockAvailable::dependsOnStock((int) $product_id)) { $query = "UPDATE " . $db->quoteName('#__jeproshop_stock_available') . " SET " . $db->quoteName('quantity') . " = 0 "; $query .= " WHERE " . $db->quoteName('product_id') . " = " . (int) $product_id; $db->setQuery($query); $db->query(); } JeproshopCache::clean('jeproshop_stock_available_get_quantity_available_by_product_' . (int) $product_id . '_*'); }
public static function searchTag($id_lang, $tag, $count = false, $pageNumber = 0, $pageSize = 10, $orderBy = false, $orderWay = false, $useCookie = true, JeproshopContext $context = null) { if (!$context) { $context = JeproshopContext::getContext(); } // Only use cookie if id_customer is not present if ($useCookie) { $customer_id = (int) $context->customer->customer_id; } else { $customer_id = 0; } if (!is_numeric($pageNumber) || !is_numeric($pageSize) || !Validate::isBool($count) || !Validate::isValidSearch($tag) || $orderBy && !$orderWay || $orderBy && !Validate::isOrderBy($orderBy) || $orderWay && !Validate::isOrderBy($orderWay)) { return false; } if ($pageNumber < 1) { $pageNumber = 1; } if ($pageSize < 1) { $pageSize = 10; } $shop_id = JeproshopContext::getContext()->shop->shop_id; $shop_id = $shop_id ? $shop_id : JeproshopSettingModelSetting::getValue('default_shop'); $sql_groups = ''; if (JeproshopGroupModelGroup::isFeaturePublished()) { $groups = JeproshopController::getCurrentCustomerGroups(); $sql_groups = " AND customer_group." . $db->quoteName('group_id') . (count($groups) ? " IN (" . implode(',', $groups) . ")" : "= 1"); } if ($count) { $query = "SELECT COUNT(DISTINCT product_tag." . $db->quoteName('product_id') . ") nb FROM " . $db->quoteName('#__jeproshop_product'); $query .= " AS product " . JeproshopShopModelShop::addSqlAssociation('product') . "\tLEFT JOIN " . $db->quoteName('#__jeproshop_product_tag'); $query .= " AS product_tag ON (product." . $db->quoteName('product_id') . " = product_tag." . $db->quoteName('product_id') . ") LEFT JOIN "; $query .= $db->quoteName('#__jeproshop_tag') . " AS tag ON (product_tag." . $db->quoteName('tag_id') . " = tag." . $db->quoteName('tag_id'); $query .= " AND tag." . $db->quoteName('lang_id') . " = " . (int) $lang_id . ") LEFT JOIN " . $db->quoteName('#__jeproshop_product_category'); $query .= " AS product_category ON (product_category." . $db->quoteName('product_id') . " = product." . $db->quoteName('product_id') . ") LEFT JOIN "; $query .= $db->quoteName('#__jeproshop_category_shop') . " AS category_shop ON (product_category." . $db->quoteName('category_id') . " = category_shop."; $query .= $db->quoteName('category_id') . " AND category_shop." . $db->quoteName('shop_id') . " = " . (int) $shop_id . ") "; $query .= JeproshopGroupModelGroup::isFeaturePublished() ? " LEFT JOIN " . $db->quoteName('#__jeproshop_category_group') . " AS category_group ON (category_group." . $db->quoteName('category_id') . " = product_category." . $db->quoteName('category_id') . ")" : ""; $query .= "\tWHERE product_shop." . $db->quoteName('publishd') . " = 1 AND product.visibility IN ('both', 'search') AND category_shop." . $db->quoteName('shop_id'); $query .= " = " . (int) JeproshopContext::getContext()->shop->shop_id . $sql_groups . " AND tag." . $db->quoteName('name') . " LIKE '%'" . $db->quote($tag) . "'%')"; /*$query .= " } $sql = 'SELECT DISTINCT p.*, product_shop.*, stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity, pl.`description_short`, pl.`link_rewrite`, pl.`name`, MAX(image_shop.`id_image`) id_image, il.`legend`, m.`name` manufacturer_name, 1 position, DATEDIFF( p.`date_add`, DATE_SUB( NOW(), INTERVAL '.(Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20).' DAY ) ) > 0 new FROM `' $db->quoteName('#__jeproshop_product` p INNER JOIN `'.$db->quoteName('#__jeproshop_product_lang` pl ON ( p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('pl').' )'.Shop::addSqlAssociation('product', 'p', false).' LEFT JOIN `'.$db->quoteName('#__jeproshop_image` i ON (i.`id_product` = p.`id_product`)'. Shop::addSqlAssociation('image', 'i', false, 'image_shop.cover=1').' LEFT JOIN `' . $db->quoteName('#__jeproshop_image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$id_lang.') LEFT JOIN `'. $db->quoteName('#__jeproshop_manufacturer` m ON (m.`id_manufacturer` = p.`id_manufacturer`) LEFT JOIN `'. $db->quoteName('#__jeproshop_product_tag` pt ON (p.`id_product` = pt.`id_product`) LEFT JOIN `'. $db->quoteName('#__jeproshop_tag` t ON (pt.`id_tag` = t.`id_tag` AND t.`id_lang` = '.(int)$id_lang.') LEFT JOIN `'. $db->quoteName('#__jeproshop_category_product` cp ON (cp.`id_product` = p.`id_product`) '.(Group::isFeatureActive() ? 'LEFT JOIN `'._DB_PREFIX_.'category_group` cg ON (cg.`id_category` = cp.`id_category`)' : '').' LEFT JOIN `'. $db->quoteName('#__jeproshop_category_shop` cs ON (cp.`id_category` = cs.`id_category` AND cs.`id_shop` = '.(int)$id_shop.') '.Product::sqlStock('p', 0).' WHERE product_shop.`active` = 1 AND cs.`id_shop` = '.(int)Context::getContext()->shop->id.' '.$sql_groups.' AND t.`name` LIKE \'%'.pSQL($tag).'%\' return (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue( GROUP BY product_shop.id_product ORDER BY position DESC'.($orderBy ? ', '.$orderBy : '').($orderWay ? ' '.$orderWay : '').' LIMIT '.(int)(($pageNumber - 1) * $pageSize).','.(int)$pageSize; $db->setQuery($query); $result = $db->loadObjectList(); if (!$result) return false; */ } return JeproshopProductModelProduct::getProductsProperties((int) $lang_id, $result); }
/** * Returns the product tax * * @param integer $product_id * @param integer $address_id * @param JeproshopContext $context * @return JeproshopTaxModelTax */ public static function getProductTaxRate($product_id, $address_id = null, JeproshopContext $context = null) { if ($context == null) { $context = JeproshopContext::getContext(); } $address = JeproshopAddressModelAddress::initialize($address_id); $tax_rules_id = (int) JeproshopProductModelProduct::getTaxRulesGroupIdByProductId($product_id, $context); $tax_manager = JeproshopTaxManagerFactory::getManager($address, $tax_rules_id); $tax_calculator = $tax_manager->getTaxCalculator(); return $tax_calculator->getTotalRate(); }
public static function getProducts($lang_id, $limit_start, $limit, $order_by = null, $order_way = null, $get_total = false, $published = true, $random = false, $random_number_products = 1, $check_access = true, JeproshopContext $context = null) { if (!$context) { $context = JeproshopContext::getContext(); } $db = JFactory::getDBO(); $app = JFactory::getApplication(); jimport('joomla.html.pagination'); //if ($check_access && !$context->controller->checkAccess($context->customer->customer_id, $category_id)){ return false; } if ($limit_start < 1) { $limit_start = 0; } if (empty($order_by)) { $order_by = 'position'; } else { /* Fix for all modules which are now using lowercase values for 'orderBy' parameter */ $order_by = strtolower($order_by); } if (empty($order_way)) { $order_way = "DESC"; } $order_by_prefix = false; if ($order_by == 'product_id' || $order_by == 'date_add' || $order_by == 'date_upd') { $order_by_prefix = "product"; } elseif ($order_by == 'name') { $order_by_prefix = "product_lang"; } elseif ($order_by == 'manufacturer') { $order_by_prefix = "manufacturer"; $order_by = "name"; } elseif ($order_by == 'position') { $order_by_prefix = "product"; } if ($order_by == 'price') { $order_by = 'order_price'; } if (!JeproshopTools::isOrderBy($order_by) || !JeproshopTools::isOrderWay($order_way)) { die(JError::raiseError()); } $supplier_id = (int) $app->input->get('supplier_id'); /* Return only the number of products */ $query = "SELECT COUNT(product." . $db->quoteName('product_id') . ") AS total FROM " . $db->quoteName('#__jeproshop_product') . " AS product "; $query .= JeproshopShopModelShop::addSqlAssociation('product') . " WHERE product_shop." . $db->quoteName('visibility') . " IN ('both', 'catalog')"; $query .= " AND product_shop." . $db->quoteName('published') . " = 1 " . ($supplier_id ? " AND product.supplier_id = " . (int) $supplier_id : ""); $db->setQuery($query); $total = (int) $db->loadResult(); $number_days_new_product = JeproshopSettingModelSetting::getValue('number_days_new_product'); $query = "SELECT product.*, product_shop.*, stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity, MAX(product_attribute_shop.product_attribute_id) AS "; $query .= "product_attribute_id, product_attribute_shop.minimal_quantity AS product_attribute_minimal_quantity, product_lang." . $db->quoteName('description'); $query .= ", product_lang." . $db->quoteName('short_description') . ", product_lang." . $db->quoteName('available_now') . ", product_lang." . $db->quoteName('available_later'); $query .= ", product_lang." . $db->quoteName('link_rewrite') . ", product_lang." . $db->quoteName('meta_description') . ", product_lang." . $db->quoteName('meta_keywords'); $query .= ", product_lang." . $db->quoteName('meta_title') . ", product_lang." . $db->quoteName('name') . ", MAX(image_shop." . $db->quoteName('image_id') . " ) AS "; $query .= "image_id, image_lang." . $db->quoteName('legend') . ", manufacturer." . $db->quoteName('name') . " AS manufacturer_name, DATEDIFF(product_shop." . $db->quoteName('date_add'); $query .= ", DATE_SUB(NOW(), INTERVAL " . (JeproshopTools::isUnsignedInt($number_days_new_product) ? $number_days_new_product : 20) . "\tDAY)) > 0 AS new, product_shop.price AS"; $query .= " order_price FROM " . $db->quoteName('#__jeproshop_product') . " AS product " . JeproshopShopModelShop::addSqlAssociation('product') . " LEFT JOIN "; $query .= $db->quoteName('#__jeproshop_product_attribute') . " AS product_attribute ON (product." . $db->quoteName('product_id') . " = product_attribute." . $db->quoteName('product_id'); $query .= ") " . JeproshopShopModelShop::addSqlAssociation('product_attribute', false, 'product_attribute_shop.`default_on` = 1'); $query .= JeproshopProductModelProduct::sqlStock('product', 'product_attribute_shop', false, $context->shop) . " LEFT JOIN " . $db->quoteName('#__jeproshop_product_lang'); $query .= " AS product_lang ON (product." . $db->quoteName('product_id') . " = product_lang." . $db->quoteName('product_id') . " AND product_lang." . $db->quoteName('lang_id') . " = " . (int) $lang_id . JeproshopShopModelShop::addSqlRestrictionOnLang('product_lang'); $query .= ") LEFT JOIN " . $db->quoteName('#__jeproshop_image') . " AS image ON (image." . $db->quoteName('product_id') . " = product." . $db->quoteName('product_id') . ") " . JeproshopShopModelShop::addSqlAssociation('image', false, 'image_shop.cover=1') . " LEFT JOIN "; $query .= $db->quoteName('#__jeproshop_image_lang') . " AS image_lang ON (image_shop." . $db->quoteName('image_id') . " = image_lang." . $db->quoteName('image_id') . " AND image_lang." . $db->quoteName('lang_id') . " = " . (int) $lang_id . ") LEFT JOIN "; $query .= $db->quoteName('#__jeproshop_manufacturer') . " AS manufacturer ON manufacturer." . $db->quoteName('manufacturer_id') . " = product." . $db->quoteName('manufacturer_id') . "\tWHERE product_shop." . $db->quoteName('shop_id') . " = " . (int) $context->shop->shop_id; $query .= " AND product_shop." . $db->quoteName('published') . " = 1 AND product_shop." . $db->quoteName('visibility') . " IN ('both', 'catalog') "; $query .= ($supplier_id ? " AND product.supplier_id = " . (int) $supplier_id : "") . " GROUP BY product_shop.product_id"; if ($random === true) { $query .= " ORDER BY RAND() LIMIT " . (int) $random_number_products; } else { //$query .= " ORDER BY " . (!empty($order_by_prefix) ? $order_by_prefix. "." : "") . $db->quoteName($order_by); $query .= " " . $order_way . " LIMIT " . (int) $limit_start . ", " . (int) $limit; } $db->setQuery($query); $result = $db->loadObjectList(); if ($order_by == 'order_price') { JeproshopTools::orderbyPrice($result, $order_way); } if (!$result) { return array(); } self::$_pagination = new JPagination($total, $limit_start, $limit); /* Modify SQL result */ return JeproshopProductModelProduct::getProductsProperties($lang_id, $result); }
"><strong><?php echo JText::_('COM_JEPROSHOP_TOTAL_LABEL'); ?> </strong></td> <td colspan="<?php if ($this->order->hasProductReturned()) { ?> 5<?php } else { ?> 4<?php } ?> "> <span class="price"><?php echo JeproshopProductModelProduct::displayWtPriceWithCurrency($this->order->total_paid, $this->currency); ?> </span> </td> </tr> </tfoot> </table> </div> <?php if ($this->return_allowed) { ?> <div id="returnOrderMessage"> <h3 class="page-heading bottom-indent"><?php echo JText::_('COM_JEPROSHOP_MERCHANDISE_RETURN_LABEL'); ?> </h3>
/** * This function returns the total cart amount * * Possible values for $type: * JeproshopCartModelCart::ONLY_PRODUCTS * JeproshopCartModelCart::ONLY_DISCOUNTS * JeproshopCartModelCart::BOTH * JeproshopCartModelCart::BOTH_WITHOUT_SHIPPING * JeproshopCartModelCart::ONLY_SHIPPING * JeproshopCartModelCart::ONLY_WRAPPING * JeproshopCartModelCart::ONLY_PRODUCTS_WITHOUT_SHIPPING * JeproshopCartModelCart::ONLY_PHYSICAL_PRODUCTS_WITHOUT_SHIPPING * * @param bool $with_taxes * @param integer $type Total type * @param null $products * @param null $carrier_id * @param boolean $use_cache Allow using cache of the method CartRule::getContextualValue * @internal param bool $withTaxes With or without taxes * @return float Order total */ public function getOrderTotal($with_taxes = true, $type = JeproshopCartModelCart::BOTH, $products = null, $carrier_id = null, $use_cache = true) { if (!$this->cart_id) { return 0; } $type = (int) $type; $array_type = array(JeproshopCartModelCart::ONLY_PRODUCTS, JeproshopCartModelCart::ONLY_DISCOUNTS, JeproshopCartModelCart::BOTH, JeproshopCartModelCart::BOTH_WITHOUT_SHIPPING, JeproshopCartModelCart::ONLY_SHIPPING, JeproshopCartModelCart::ONLY_WRAPPING, JeproshopCartModelCart::ONLY_PRODUCTS_WITHOUT_SHIPPING, JeproshopCartModelCart::ONLY_PHYSICAL_PRODUCTS_WITHOUT_SHIPPING); // Define virtual context to prevent case where the cart is not the in the global context $virtual_context = JeproshopContext::getContext()->cloneContext(); $virtual_context->cart = $this; if (!in_array($type, $array_type)) { die(Tools::displayError()); } $with_shipping = in_array($type, array(JeproshopCartModelCart::BOTH, JeproshopCartModelCart::ONLY_SHIPPING)); // if cart rules are not used if ($type == JeproshopCartModelCart::ONLY_DISCOUNTS && !JeproshopCartRuleModelCartRule::isFeaturePublished()) { return 0; } // no shipping cost if is a cart with only virtual products $virtual = $this->isVirtualCart(); if ($virtual && $type == JeproshopCartModelCart::ONLY_SHIPPING) { return 0; } if ($virtual && $type == JeproshopCartModelCart::BOTH) { $type = JeproshopCartModelCart::BOTH_WITHOUT_SHIPPING; } if ($with_shipping || $type == JeproshopCartModelCart::ONLY_DISCOUNTS) { if (is_null($products) && is_null($carrier_id)) { $shipping_fees = $this->getTotalShippingCost(null, (bool) $with_taxes); } else { $shipping_fees = $this->getPackageShippingCost($carrier_id, (bool) $with_taxes, null, $products); } } else { $shipping_fees = 0; } if ($type == JeproshopCartModelCart::ONLY_SHIPPING) { return $shipping_fees; } if ($type == JeproshopCartModelCart::ONLY_PRODUCTS_WITHOUT_SHIPPING) { $type = JeproshopCartModelCart::ONLY_PRODUCTS; } $param_product = true; if (is_null($products)) { $param_product = false; $products = $this->getProducts(); } if ($type == JeproshopCartModelCart::ONLY_PHYSICAL_PRODUCTS_WITHOUT_SHIPPING) { foreach ($products as $key => $product) { if ($product['is_virtual']) { unset($products[$key]); } } $type = JeproshopCartModelCart::ONLY_PRODUCTS; } $order_total = 0; if (JeproshopTaxModelTax::taxExcludedOption()) { $with_taxes = false; } foreach ($products as $product) { if ($virtual_context->shop->shop_id != $product->shop_id) { $virtual_context->shop = new JeproshopShopModelShop((int) $product->shop_id); } if (JeproshopSettingModelSetting::getValue('tax_address_type') == 'address_invoice_id') { $address_id = (int) $this->address_invoice_id; } else { $address_id = (int) $product->address_delivery_id; } // Get delivery address of the product from the cart if (!JeproshopAddressModelAddress::addressExists($address_id)) { $address_id = null; } if ($this->_taxCalculationMethod == COM_JEPROSHOP_TAX_EXCLUDED) { $null = null; // Here taxes are computed only once the quantity has been applied to the product price $price = JeproshopProductModelProduct::getStaticPrice((int) $product->product_id, false, (int) $product->product_attribute_id, 2, null, false, true, $product->cart_quantity, false, (int) $this->customer_id ? (int) $this->customer_id : null, (int) $this->cart_id, $address_id, $null, true, true, $virtual_context); $total_ecotax = $product->ecotax * (int) $product->cart_quantity; $total_price = $price * (int) $product->cart_quantity; if ($with_taxes) { $product_tax_rate = (double) JeproshopTaxModelTax::getProductTaxRate((int) $product->product_id, (int) $address_id, $virtual_context); $product_eco_tax_rate = JeproshopTaxModelTax::getProductEcotaxRate((int) $address_id); $total_price = ($total_price - $total_ecotax) * (1 + $product_tax_rate / 100); $total_ecotax = $total_ecotax * (1 + $product_eco_tax_rate / 100); $total_price = JeproshopValidator::roundPrice($total_price + $total_ecotax, 2); } } else { $null = null; if ($with_taxes) { $price = JeproshopProductModelProduct::getStaticPrice((int) $product->product_id, true, (int) $product->product_attribute_id, 2, null, false, true, $product->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, $virtual_context); } else { $price = JeproshopProductModelProduct::getStaticPrice((int) $product->product_id, false, (int) $product->product_attribute_id, 2, null, false, true, $product->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, $virtual_context); } $total_price = JeproshopValidator::roundPrice($price * (int) $product->cart_quantity, 2); } $order_total += $total_price; } $order_total_products = $order_total; if ($type == JeproshopCartModelCart::ONLY_DISCOUNTS) { $order_total = 0; } // Wrapping Fees $wrapping_fees = 0; if ($this->gift) { $wrapping_fees = JeproshopValidator::convertPrice(JeproshopValidator::roundPrice($this->getGiftWrappingPrice($with_taxes), 2), JeproshopCurrencyModelCurrency::getCurrencyInstance((int) $this->currency_id)); } if ($type == JeproshopCartModelCart::ONLY_WRAPPING) { return $wrapping_fees; } $order_total_discount = 0; if (!in_array($type, array(JeproshopCartModelCart::ONLY_SHIPPING, JeproshopCartModelCart::ONLY_PRODUCTS)) && JeproshopCartRuleModelCartRule::isFeaturePublished()) { // First, retrieve the cart rules associated to this "getOrderTotal" if ($with_shipping || $type == JeproshopCartModelCart::ONLY_DISCOUNTS) { $cart_rules = $this->getCartRules(JeproshopCartRuleModelCartRule::JEPROSHOP_FILTER_ACTION_ALL); } else { $cart_rules = $this->getCartRules(JeproshopCartRuleModelCartRule::JEPROSHOP_FILTER_ACTION_REDUCTION); // Cart Rules array are merged manually in order to avoid doubles foreach ($this->getCartRules(JeproshopCartRuleModelCartRule::JEPROSHOP_FILTER_ACTION_GIFT) as $tmp_cart_rule) { $flag = false; foreach ($cart_rules as $cart_rule) { if ($tmp_cart_rule->cart_rule_id == $cart_rule->cart_rule_id) { $flag = true; } } if (!$flag) { $cart_rules[] = $tmp_cart_rule; } } } $address_delivery_id = 0; if (isset($products[0])) { $address_delivery_id = is_null($products) ? $this->address_delivery_id : $products[0]->address_delivery_id; } $package = array('carrier_id' => $carrier_id, 'address_id' => $address_delivery_id, 'products' => $products); // Then, calculate the contextual value for each one foreach ($cart_rules as $cart_rule) { // If the cart rule offers free shipping, add the shipping cost if (($with_shipping || $type == Cart::ONLY_DISCOUNTS) && $cart_rule->obj->free_shipping) { $order_total_discount += JeproshopValidator::roundPrice($cart_rule->obj->getContextualValue($with_taxes, $virtual_context, CartRule::FILTER_ACTION_SHIPPING, $param_product ? $package : null, $use_cache), 2); } // If the cart rule is a free gift, then add the free gift value only if the gift is in this package if ((int) $cart_rule['obj']->gift_product) { $in_order = false; if (is_null($products)) { $in_order = true; } else { foreach ($products as $product) { if ($cart_rule['obj']->gift_product == $product['id_product'] && $cart_rule['obj']->gift_product_attribute == $product['id_product_attribute']) { $in_order = true; } } } if ($in_order) { $order_total_discount += $cart_rule->obj->getContextualValue($with_taxes, $virtual_context, JeproshopCartRuleModelCartRule::FILTER_ACTION_GIFT, $package, $use_cache); } } // If the cart rule offers a reduction, the amount is prorated (with the products in the package) if ($cart_rule['obj']->reduction_percent > 0 || $cart_rule['obj']->reduction_amount > 0) { $order_total_discount += JeproshopValidator::roundPrice($cart_rule['obj']->getContextualValue($with_taxes, $virtual_context, CartRule::FILTER_ACTION_REDUCTION, $package, $use_cache), 2); } } $order_total_discount = min(JeproshopValidator::roundPrice($order_total_discount, 2), $wrapping_fees + $order_total_products + $shipping_fees); $order_total -= $order_total_discount; } if ($type == JeproshopCartModelCart::BOTH) { $order_total += $shipping_fees + $wrapping_fees; } if ($order_total < 0 && $type != JeproshopCartModelCart::ONLY_DISCOUNTS) { return 0; } if ($type == JeproshopCartModelCart::ONLY_DISCOUNTS) { return $order_total_discount; } return JeproshopValidator::roundPrice((double) $order_total, 2); }
public function renderView($tpl = null) { if (!$this->loadObject(true)) { return; } if (!isset($this->context)) { $this->context = JeproshopContext::getContext(); } $customer = new JeproshopCustomerModelCustomer($this->cart->customer_id); $currency = new JeproshopCurrencyModelCurrency($this->cart->currency_id); $this->context->cart = $this->cart; $this->context->currency = $currency; $this->context->customer = $customer; //$this->toolbar_title = sprintf($this->l('Cart #%06d'), $this->context->cart->cart_id); $products = $this->cart->getProducts(); $customized_datas = JeproshopProductModelProduct::getAllCustomizedDatas((int) $this->cart->cart_id); JeproshopProductModelProduct::addCustomizationPrice($products, $customized_datas); $summary = $this->cart->getSummaryDetails(); /* Display order information */ $order_id = (int) JeproshopOrderModelOrder::getOrderIdByCartId($this->cart->cart_id); $order = new JeproshopOrderModelOrder($order_id); if (JeproshopTools::isLoadedObject($order, 'order_id')) { $tax_calculation_method = $order->getTaxCalculationMethod(); $shop_id = (int) $order->shop_id; } else { $shop_id = (int) $this->cart->shop_id; $tax_calculation_method = JeproshopGroupModelGroup::getPriceDisplayMethod(JeproshopGroupModelGroup::getCurrent()->group_id); } if ($tax_calculation_method == COM_JEPROSHOP_TAX_EXCLUDED) { $total_products = $summary->total_products; $total_discounts = $summary->total_discounts_tax_exc; $total_wrapping = $summary->total_wrapping_tax_exc; $total_price = $summary->total_price_without_tax; $total_shipping = $summary->total_shipping_tax_exc; } else { $total_products = $summary->total_products_wt; $total_discounts = $summary->total_discounts; $total_wrapping = $summary->total_wrapping; $total_price = $summary->total_price; $total_shipping = $summary->total_shipping; } foreach ($products as $k => &$product) { if ($tax_calculation_method == COM_JEPROSHOP_TAX_EXCLUDED) { $product->product_price = $product->price; $product->product_total = $product->total; } else { $product->product_price = $product->price_wt; $product->product_total = $product->total_wt; } $image = array(); $db = JFactory::getDBO(); if (isset($product->product_attribute_id) && (int) $product->product_attribute_id) { $query = "SELECT " . $db->quoteName('image_id') . " FROM " . $db->quoteName('#__jeproshop_product_attribute_image') . " WHERE product_attribute_id = " . (int) $product->product_attribute_id; $db->setQuery($query); $image = $db->loadObject(); } if (!isset($image->image_id)) { $query = "SELECT " . $db->quoteName('image_id') . " FROM " . $db->quoteName('#__jeproshop_image') . " WHERE " . $db->quoteName('product_id') . " = " . (int) $product->product_id . " AND cover = 1 "; $db->setQuery($query); $image = $db->loadObject(); } $product_obj = new JeproshopProductModelProduct($product->product_id); $product->qty_in_stock = JeproshopStockAvailableModelStockAvailable::getQuantityAvailableByProduct($product->product_id, isset($product->product_attribute_id) ? $product->product_attribute_id : null, (int) $shop_id); $image_product = new JeproshopImageModelImage($image->image_id); $product->image = isset($image->image_id) ? JeproshopImageManager::thumbnail(COM_JEPROSHOP_IMAGE_DIR . 'products/' . $image_product->getExistingImagePath() . '.jpg', 'product_mini_' . (int) $product->product_id . (isset($product->product_attribute_id) ? '_' . (int) $product->product_attribute_id : '') . '.jpg', 45, 'jpg') : '--'; } /*$helper = new HelperKpi(); $helper->id = 'box-kpi-cart'; $helper->icon = 'icon-shopping-cart'; $helper->color = 'color1'; $helper->title = $this->l('Total Cart', null, null, false); $helper->subtitle = sprintf($this->l('Cart #%06d', null, null, false), $cart->id); $helper->value = Tools::displayPrice($total_price, $currency); $kpi = $helper->generate(); */ //$this->assignRef('kpi', $kpi); $this->assignRef('products', $products); $discounts = $this->cart->getCartRules(); $this->assignRef('discounts', $discounts); $this->assignRef('order', $order); $this->assignRef('currency', $currency); $this->assignRef('customer', $customer); $customerStats = $customer->getStats(); $this->assignRef('customer_stats', $customerStats); $this->assignRef('total_products', $total_products); $this->assignRef('total_discounts', $total_discounts); $this->assignRef('total_wrapping', $total_wrapping); $this->assignRef('total_price', $total_price); $this->assignRef('total_shipping', $total_shipping); $this->assignRef('customized_datas', $customized_datas); if ($this->getLayout() != 'modal') { $this->addToolBar(); $this->sideBar = JHtmlSidebar::render(); } parent::display($tpl); }
public function update() { if ($this->viewAccess() && JeproshopTools::checkProductToken()) { $app = JFactory::getApplication(); $product_id = $app->input->get('product_id'); if (isset($product_id) && $product_id > 0) { $productModel = new JeproshopProductModelProduct($product_id); $productModel->updateProduct(); } } }
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); }
public static function getPacksTable($product_id, $lang_id, $full = false, $limit = null) { if (!JeproshopProductPack::isFeaturePublished()) { return array(); } $db = JFactory::getDBO(); $query = "SELECT GROUP_CONCAT(pack." . $db->quoteName('product_pack_id') . ") FROM " . $db->quoteName('#__jeproshop_pack') . " AS pack WHERE pack." . $db->qsuoteName('product_item_id') . " = " . (int) $product_id; $db->quoteName($query); $packs = $db->loadResult(); if (!(int) $packs) { return array(); } $query = "SELECT product.*, product_shop.*, product_lang.*, MAX(image_shop." . $db->quoteName('image_id') . ") image_id, image_lang." . $db->quoteName('legend') . " FROM " . $db->quoteName('#__jeproshop_product') . " AS product NATURAL LEFT JOIN "; $query .= $db->quoteName('#__jeproshop_product_lang') . " AS product_lang " . JeproshopShopModelShop::addSqlAssociation('product') . " LEFT JOIN " . $db->quoteName('#__jeproshop_image') . " AS image ON (image." . $db->quoteName('product_id') . " = product."; $query .= $db->quoteName('product_id') . ") " . JeproshopShopModelShop::addSqlAssociation('image', false, 'image_shop.cover=1') . "\tLEFT JOIN " . $db->quoteName('#__jeproshop_image_lang') . " AS image_lang ON (image." . $db->quoteName('image_id'); $query .= " = image_lang." . $db->quoteName('image_id') . " AND image_lang." . $db->quoteName('lang_id') . " = " . (int) $lang_id . ") WHERE product_lang." . $db->quoteName('lang_id') . " = " . (int) $lang_id . JeproshopShopModelShop::addSqlRestrictionOnLang('product_lang'); $query .= "\tAND product." . $db->quoteName('product_id') . " IN (" . $packs . ") GROUP BY product_shop.product_id"; if ($limit) { $query .= " LIMIT " . (int) $limit; } $db->setQuery($query); $result = $db->loadObjectList(); if (!$full) { return $result; } $array_result = array(); foreach ($result as $row) { if (!JeproshopProductPack::isPacked($row->product_id)) { $array_result[] = JeproshopProductModelProduct::getProductProperties($lang_id, $row); } } return $array_result; }
/** * 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; }
/** * Return current category products * * @param integer $lang_id Language ID * * @return mixed Products or number of products */ public function getProducts($lang_id, $check_access = true, JeproshopContext $context = null) { //$p, $n, $order_by = null, $order_way = null, $get_total = false, $active = true, $random = false, $random_number_products = 1, , if (!$context) { $context = JeproshopContext::getContext(); } if ($check_access && !$this->checkAccess($context->customer->customer_id)) { return false; } $front = true; if (!in_array($context->controller->controller_type, array('front', 'modulefront'))) { $front = false; } if ($p < 1) { $p = 1; } if (empty($order_by)) { $order_by = 'position'; } else { /* Fix for all modules which are now using lowercase values for 'orderBy' parameter */ $order_by = strtolower($order_by); } if (empty($order_way)) { $order_way = 'ASC'; } $order_by_prefix = false; if ($order_by == 'id_product' || $order_by == 'date_add' || $order_by == 'date_upd') { $order_by_prefix = 'p'; } elseif ($order_by == 'name') { $order_by_prefix = 'pl'; } elseif ($order_by == 'manufacturer') { $order_by_prefix = 'm'; $order_by = 'name'; } elseif ($order_by == 'position') { $order_by_prefix = 'cp'; } if ($order_by == 'price') { $order_by = 'order_price'; } if (!Validate::isBool($active) || !Validate::isOrderBy($order_by) || !Validate::isOrderWay($order_way)) { die(Tools::displayError()); } $id_supplier = (int) Tools::getValue('id_supplier'); /* Return only the number of products */ if ($get_total) { $sql = 'SELECT COUNT(cp.`id_product`) AS total FROM `' . _DB_PREFIX_ . 'product` p ' . Shop::addSqlAssociation('product', 'p') . ' LEFT JOIN `' . _DB_PREFIX_ . 'category_product` cp ON p.`id_product` = cp.`id_product` WHERE cp.`id_category` = ' . (int) $this->id . ($front ? ' AND product_shop.`visibility` IN ("both", "catalog")' : '') . ($active ? ' AND product_shop.`active` = 1' : '') . ($id_supplier ? 'AND p.id_supplier = ' . (int) $id_supplier : ''); return (int) Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql); } $sql = 'SELECT p.*, product_shop.*, stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity, MAX(product_attribute_shop.id_product_attribute) id_product_attribute, product_attribute_shop.minimal_quantity AS product_attribute_minimal_quantity, pl.`description`, pl.`description_short`, pl.`available_now`, pl.`available_later`, pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`, MAX(image_shop.`id_image`) id_image, il.`legend`, m.`name` AS manufacturer_name, cl.`name` AS category_default, DATEDIFF(product_shop.`date_add`, DATE_SUB(NOW(), INTERVAL ' . (Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20) . ' DAY)) > 0 AS new, product_shop.price AS orderprice FROM `' . _DB_PREFIX_ . 'category_product` cp LEFT JOIN `' . _DB_PREFIX_ . 'product` p ON p.`id_product` = cp.`id_product` ' . Shop::addSqlAssociation('product', 'p') . ' LEFT JOIN `' . _DB_PREFIX_ . 'product_attribute` pa ON (p.`id_product` = pa.`id_product`) ' . Shop::addSqlAssociation('product_attribute', 'pa', false, 'product_attribute_shop.`default_on` = 1') . ' ' . Product::sqlStock('p', 'product_attribute_shop', false, $context->shop) . ' LEFT JOIN `' . _DB_PREFIX_ . 'category_lang` cl ON (product_shop.`id_category_default` = cl.`id_category` AND cl.`id_lang` = ' . (int) $id_lang . Shop::addSqlRestrictionOnLang('cl') . ') LEFT JOIN `' . _DB_PREFIX_ . 'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = ' . (int) $id_lang . Shop::addSqlRestrictionOnLang('pl') . ') LEFT JOIN `' . _DB_PREFIX_ . 'image` i ON (i.`id_product` = p.`id_product`)' . Shop::addSqlAssociation('image', 'i', false, 'image_shop.cover=1') . ' LEFT JOIN `' . _DB_PREFIX_ . 'image_lang` il ON (image_shop.`id_image` = il.`id_image` AND il.`id_lang` = ' . (int) $id_lang . ') LEFT JOIN `' . _DB_PREFIX_ . 'manufacturer` m ON m.`id_manufacturer` = p.`id_manufacturer` WHERE product_shop.`id_shop` = ' . (int) $context->shop->id . ' AND cp.`id_category` = ' . (int) $this->id . ($active ? ' AND product_shop.`active` = 1' : '') . ($front ? ' AND product_shop.`visibility` IN ("both", "catalog")' : '') . ($id_supplier ? ' AND p.id_supplier = ' . (int) $id_supplier : '') . ' GROUP BY product_shop.id_product'; if ($random === true) { $sql .= ' ORDER BY RAND() LIMIT ' . (int) $random_number_products; } else { $sql .= ' ORDER BY ' . (!empty($order_by_prefix) ? $order_by_prefix . '.' : '') . '`' . bqSQL($order_by) . '` ' . pSQL($order_way) . ' LIMIT ' . ((int) $p - 1) * (int) $n . ',' . (int) $n; } $db->setQuery($query); $result = $db->loadObjectList(); if ($order_by == 'order_price') { JeproshopTools::orderByPrice($result, $order_way); } if (!$result) { return array(); } /* Modify SQL result */ return JeproshopProductModelProduct::getProductsProperties($lang_id, $result); }
public function delete() { @unlink(_PS_DOWNLOAD_DIR_ . $this->file); $db = JFactory::getDBO(); $query = "SELECT product_id FROM " . $db->quoteName('#__jeproshop_product_attachment') . " WHERE attachment_id = " . (int) $this->attachment_id; $db->setQuery($query); $products = $db->loadObjectList(); $query = "DELETE FROM " . $db->quoteName('#__jeproshop_product_attachment') . " WHERE attachment_id = " . (int) $this->attachment_id; $db->setQuery($query); $db->query(); foreach ($products as $product) { JeproshopProductModelProduct::updateCacheAttachment((int) $product->product_id); } return parent::delete(); }
/** * 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); }
public function delete() { $db = JFactory::getDBO(); $this->clearCache(); $result = true; if (JeproshopShopModelShop::isTableAssociated('product_attribute')) { $shopListIds = JeproshopShopModelShop::getContextListShopIds(); if (count($this->shop_list_id)) { $shopListIds = $this->shop_list_id; } $query = "DELETE FROM " . $db->quoteName('#__jeproshop_product_attribute_shop') . " WHERE " . $db->quoteName('product_attribute_id') . " = " . (int) $this->product_attribute_id . " AND " . $db->quoteName('shop_id') . " IN (" . implode($shopListIds) . ")"; $db->setQuery($query); $result &= $db->query(); } $hasMultiShopEntries = $this->hasMultiShopEntries(); if ($result && !$hasMultiShopEntries) { $query = "DELETE FROM " . $db->quoteName('#__jeproshop_product_attribute') . " WHERE " . $db->quoteName('product_attribute_id') . " = " . (int) $this->product_attribute_id; $db->setQuery($query); $result &= $db->query(); } if ($this->multi_lang && !$hasMultiShopEntries) { $query = "DELETE FROM " . $db->quoteName('#__jeproshop_product_attribute_lang') . " WHERE " . $db->quoteName('product_attribute_id') . " = " . (int) $this->product_attribute_id; $db->setQuery($query); $result &= $db->query(); } if (!$result) { return false; } // Removes the product from StockAvailable, for the current shop JeproshopStockAvailableModelStockAvailable::removeProductFromStockAvailable((int) $this->product_id, (int) $this->product_attribute_id); if ($specific_prices = JeproshopSpecificPriceModelSpecificPrice::getByProductId((int) $this->product_id, (int) $this->product_attribute_id)) { foreach ($specific_prices as $specific_price) { $price = new JeproshopSpecificPriceModelSpecificPrice((int) $specific_price->specific_price_id); $price->delete(); } } if (!$this->hasMultishopEntries() && !$this->deleteAssociations()) { return false; } $this->deleteFromSupplier($this->product_id); JeproshopProductModelProduct::updateDefaultAttribute($this->product_id); return true; }
public static function getItems($product_id, $lang_id) { if (!JeproshopProductPack::isFeaturePublished()) { return array(); } if (array_key_exists($product_id, self::$cachePackItems)) { return self::$cachePackItems[$product_id]; } $db = JFactory::getDBO(); $query = "SELECT product_item_id, quantity FROM " . $db->quoteName('#__jeproshop_pack') . " WHERE product_pack_id = " . (int) $product_id; $db->setQuery($query); $result = $db->loadObjectList(); $array_result = array(); foreach ($result as $row) { $product = new JeproshopProductModelProduct($row->product_item_id, false, $lang_id); $product->loadStockData(); $product->pack_quantity = $row->quantity; $array_result[] = $product; } self::$cachePackItems[$product_id] = $array_result; return self::$cachePackItems[$product_id]; }
/** * Get order products * * @param bool $products * @param bool $selectedProducts * @param bool $selectedQty * @return array Products with price, quantity (with tax and without) */ public function getProducts($products = false, $selectedProducts = false, $selectedQty = false) { if (!$products) { $products = $this->getProductsDetail(); } $customized_datas = JeproshopProductModelProduct::getAllCustomizedDatas($this->cart_id); $resultArray = array(); foreach ($products as $row) { // Change qty if selected if ($selectedQty) { $row->product_quantity = 0; foreach ($selectedProducts as $key => $product_id) { if ($row->order_detail_id == $product_id) { $row->product_quantity = (int) $selectedQty[$key]; } } if (!$row->product_quantity) { continue; } } $this->setProductImageInformations($row); $this->setProductCurrentStock($row); // Backward compatibility 1.4 -> 1.5 $this->setProductPrices($row); $this->setProductCustomizedDatas($row, $customized_datas); // Add information for virtual product if ($row->download_hash && !empty($row->download_hash)) { $row->filename = JeproshopProductDownloadModelProductDownload::getFilenameFromProductId((int) $row->product_id); // Get the display filename $row->display_filename = JeproshopProductDownloadModelProductDownload::getFilenameFromFilename($row->filename); } $row->address_delivery_id = $this->address_delivery_id; /* Stock product */ $resultArray[(int) $row->order_detail_id] = $row; } if ($customized_datas) { JeproshopProductModelProduct::addCustomizationPrice($resultArray, $customized_datas); } return $resultArray; }
/** * Create a link to a product * * @param mixed $product Product object (can be an ID product, but deprecated) * @param string $alias * @param string $category * @param string $ean13 * @param null $lang_id * @param null $shop_id * @param int $product_attribute_id ID product attribute * @param bool $force_routes * @throws JException * @internal param int $id_lang * @internal param int $id_shop (since 1.5.0) ID shop need to be used when we generate a product link for a product in a cart * @return string */ public function getProductLink($product, $alias = null, $category = null, $ean13 = null, $lang_id = null, $shop_id = null, $product_attribute_id = 0, $force_routes = false) { if (!$lang_id) { $lang_id = JeproshopContext::getContext()->language->lang_id; } if (!is_object($product)) { if (is_array($product) && isset($product['product_id'])) { $product = new JeproshopProductModelProduct($product['product_id'], false, $lang_id, $shop_id); } elseif ((int) $product) { $product = new JeproshopProductModelProduct((int) $product, false, $lang_id, $shop_id); } else { throw new JException(JText::_('COM_JEPROSHOP_INVALID_PRODUCT_VARS_MESSAGE')); } } // Set available keywords $anchor = '&task=view&product_id=' . $product->product_id . (!$alias ? '&rewrite=' . $product->getFieldByLang('link_rewrite') : $alias) . (!$ean13 ? '&ean13=' . $product->ean13 : $ean13); $anchor .= '&meta_keywords=' . JeproshopTools::str2url($product->getFieldByLang('meta_keywords')) . '&meta_title=' . JeproshopTools::str2url($product->getFieldByLang('meta_title')); if ($this->hasKeyword('product', $lang_id, 'manufacturer', $shop_id)) { $params['manufacturer'] = JeproshopTools::str2url($product->isFullyLoaded ? $product->manufacturer_name : JeproshopManufacturerModelManufacturer::getNameById($product->manufacturer_id)); } if ($this->hasKeyword('product', $lang_id, 'supplier', $shop_id)) { $params['supplier'] = JeproshopTools::str2url($product->isFullyLoaded ? $product->supplier_name : JeproshopSupplierModelSupplier::getNameById($product->supplier_id)); } if ($this->hasKeyword('product', $lang_id, 'price', $shop_id)) { $params['price'] = $product->isFullyLoaded ? $product->price : JeproshopProductModelProduct::getStaticPrice($product->product_id, false, null, 6, null, false, true, 1, false, null, null, null, $product->specific_price); } if ($this->hasKeyword('product', $lang_id, 'tags', $shop_id)) { $params['tags'] = JeproshopTools::str2url($product->getTags($lang_id)); } if ($this->hasKeyword('product', $lang_id, 'category', $shop_id)) { $params['category'] = !is_null($product->category) && !empty($product->category) ? JeproshopTools::str2url($product->category) : JeproshopTools::str2url($category); } if ($this->hasKeyword('product', $lang_id, 'reference', $shop_id)) { $params['reference'] = JeproshopTools::str2url($product->reference); } if ($this->hasKeyword('product', $lang_id, 'categories', $shop_id)) { $params['category'] = !$category ? $product->category : $category; $cats = array(); foreach ($product->getParentCategories() as $cat) { if (!in_array($cat->category_id, Link::$category_disable_rewrite)) { //remove root and home category from the URL $cats[] = $cat->link_rewrite; } } $params['categories'] = implode('/', $cats); } $anchor .= $product_attribute_id ? '&product_attribute_id=' . $product_attribute_id : ''; return JRoute::_('index.php?option=com_jeproshop&view=product' . $anchor); }