Example #1
0
 public static function getReturnedCustomizedProducts($order_id)
 {
     $returns = JeproshopCustomization::getReturnedCustomizations($order_id);
     $order = new JeproshopOrderModelOrder((int) $order_id);
     if (!JeproshopValidate::isLoadedObject($order, 'order_id')) {
         die(Tools::displayError());
     }
     $products = $order->getProducts();
     foreach ($returns as &$return) {
         $return->product_id = (int) $products[(int) $return['id_order_detail']]['product_id'];
         $return->product_attribute_id = (int) $products[(int) $return['id_order_detail']]['product_attribute_id'];
         $return->name = $products[(int) $return['id_order_detail']]['product_name'];
         $return->reference = $products[(int) $return['id_order_detail']]['product_reference'];
         $return->address_delivery_id = $products[(int) $return['id_order_detail']]['id_address_delivery'];
     }
     return $returns;
 }
Example #2
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 #3
0
 /**
  * Update products cart address delivery with the address delivery of the cart
  */
 public function setNoMultiShipping()
 {
     $emptyCache = false;
     $db = JFactory::getDBO();
     if (JeproshopSettingModelSetting::getValue('allow_multi_shipping')) {
         // Upgrading quantities
         $query = "SELECT sum(" . $db->quoteName('quantity') . ") AS quantity, product_id, product_attribute_id, count(*) as count FROM ";
         $query .= $db->quoteName('#__jeproshop_cart_product') . " WHERE " . $db->quoteName('cart_id') . " = " . (int) $this->cart_id . " AND ";
         $query .= $db->quoteName('shop_id') . " = " . (int) $this->shop_id . " GROUP BY product_id, product_attribute_id HAVING count > 1";
         $db->setQuery($query);
         $products = $db->loadObjectList();
         foreach ($products as $product) {
             $query = "UPDATE " . $db->quoteName('#__jeproshop_cart_product') . " SET " . $db->quoteName('quantity') . " = " . $product->quantity;
             $query .= "\tWHERE " . $db->quoteName('cart_id') . " = " . (int) $this->cart_id . " AND " . $db->quoteName('shop_id') . " = " . (int) $this->shop_id;
             $query .= " AND product_id = " . $product->product_id . " AND product_attribute_id = " . $product->product_attribute_id;
             $db->setQuery($query);
             if ($db->query()) {
                 $emptyCache = true;
             }
         }
         // Merging multiple lines
         $query = "DELETE cart_product_1 FROM " . $db->quoteName('#__jeproshop_cart_product') . " AS cart_product_1 INNER JOIN ";
         $query .= $db->quoteName('#__jeproshop_cart_product') . " AS cart_product_2 ON ((cart_product_1.cart_id = cart_product_2.";
         $query .= "cart_id) AND (cart_product_1.product_id = cart_product_2.product_id) AND (cart_product_1.product_attribute_id = ";
         $query .= "cart_product_2.product_attribute_id) AND (cart_product_1.address_delivery_id <> cart_product_2.address_delivery_id) ";
         $query .= " AND (cart_product_1.date_add > cart_product_2.date_add) )";
         $db->setQuery($query);
         $db->query();
     }
     // Update delivery address for each product line
     $query = "UPDATE " . $db->quoteName('#__jeproshop_cart_product') . " SET " . $db->quoteName('address_delivery_id') . " = ( SELECT ";
     $query .= $db->quoteName('address_delivery_id') . " FROM " . $db->quoteName('#__jeproshop_cart') . " WHERE " . $db->quoteName('cart_id');
     $query .= " = " . (int) $this->cart_id . " AND " . $db->quoteName('shop_id') . " = " . (int) $this->shop_id . ") WHERE " . $db->quoteName('cart_id');
     $query .= " = " . (int) $this->cart_id . (JeproshopSettingModelSetting::getValue('allow_multi_shipping') ? " AND " . $db->quoteName('shop_id') . " = " . (int) $this->shop_id : "");
     $db->setQuery($query);
     $cache_id = 'jeproshop_cart_set_no_multi_shipping' . (int) $this->cart_id . '_' . (int) $this->shop_id . (isset($this->address_delivery_id) && $this->address_delivery_id ? '-' . (int) $this->address_delivery_id : '');
     if (!JeproshopCache::isStored($cache_id)) {
         $db->setQuery($query);
         if ($result = (bool) $db->query()) {
             $emptyCache = true;
         }
         JeproshopCache::store($cache_id, $result);
     }
     if (JeproshopCustomization::isFeaturePublished()) {
         //Db::getInstance()->execute(
         $query = " UPDATE " . $db->quoteName('#__jeproshop_customization') . " SET " . $db->quoteName('address_delivery_id') . " = ( SELECT ";
         $query .= $db->quoteName('address_delivery_id') . " FROM " . $db->quoteName('#__jeproshop_cart') . " WHERE " . $db->quoteName('cart_id');
         $query .= " = " . (int) $this->cart_id . " ) WHERE " . $db->quoteName('cart_id') . " = " . (int) $this->cart_id;
         $db->setQuery($query);
         $db->query();
     }
     if ($emptyCache) {
         $this->_products = null;
     }
 }
Example #4
0
 public static function getStaticRequiredCustomizableFields($product_id)
 {
     if (!$product_id || !JeproshopCustomization::isFeaturePublished()) {
         return array();
     }
     $db = JFactory::getDBO();
     $query = "SELECT " . $db->quoteName('customization_field_id') . ", " . $db->quoteName('type') . " FROM " . $db->quoteName('#__jeproshop_customization_field');
     $query .= " WHERE " . $db->quoteName('product_id') . " = " . (int) $product_id . " AND " . $db->quoteName('required') . " = 1";
     $db->setQuery($query);
     return $db->loadObjectList();
 }
Example #5
0
 public static function getAllCustomizedDatas($cart_id, $lang_id = null, $only_in_cart = true)
 {
     if (!JeproshopCustomization::isFeaturePublished()) {
         return false;
     }
     // No need to query if there isn't any real cart!
     if (!$cart_id) {
         return false;
     }
     if (!$lang_id) {
         $lang_id = JeproshopContext::getContext()->language->lang_id;
     }
     $db = JFactory::getDBO();
     $query = "SELECT customized_data." . $db->quoteName('customization_id') . ", customization." . $db->quoteName('address_delivery_id');
     $query .= ", customization." . $db->quoteName('product_id') . ", customization_field_lang." . $db->quoteName('customization_field_id');
     $query .= ", customization." . $db->quoteName('product_attribute_id') . ", customized_data." . $db->quoteName('type') . ", ";
     $query .= "customized_data." . $db->quoteName('index') . ", customized_data." . $db->quoteName('value') . ", ";
     $query .= "customization_field_lang." . $db->quoteName('name') . " FROM " . $db->quoteName('#__jeproshop_customized_data') . " AS ";
     $query .= " customized_data NATURAL JOIN " . $db->quoteName('#__jeproshop_customization') . " AS customization LEFT JOIN ";
     $query .= $db->quoteName('#__jeproshop_customization_field_lang') . " AS customization_field_lang ON (customization_field_lang.";
     $query .= "customization_field_id = customized_data." . $db->quoteName('index') . " AND lang_id = " . (int) $lang_id . ") WHERE ";
     $query .= "customization." . $db->quoteName('cart_id') . " = " . (int) $cart_id . ($only_in_cart ? " AND customization." . $db->quoteName('in_cart') . " = 1" : "");
     $query .= " ORDER BY " . $db->quoteName('product_id') . ", " . $db->quoteName('product_attribute_id') . ", " . $db->quoteName('type') . ", " . $db->quoteName('index');
     $db->seQuery($query);
     $result = $db->loadObjectList();
     if (!$result) {
         return false;
     }
     $customized_datas = array();
     foreach ($result as $row) {
         $customized_datas[(int) $row->product_id][(int) $row->product_attribute_id][(int) $row->address_delivery_id][(int) $row->customization_id]['datas'][(int) $row->type][] = $row;
     }
     $query = "SELECT " . $db->quoteName('product_id') . ", " . $db->quoteName('product_attribute_id') . ", " . $db->quoteName('customization_id');
     $query .= ", " . $db->quoteName('address_delivery_id') . ", " . $db->quoteName('quantity') . ", " . $db->quoteName('quantity_refunded') . ", ";
     $query .= $db->quoteName('quantity_returned') . " FROM " . $db->quoteName('#__jeproshop_customization') . " WHERE " . $db->quoteName('cart_id');
     $query .= " = " . (int) $cart_id . ($only_in_cart ? " AND " . $db->quoteName('in_cart') . " = 1" : "");
     $db->seQuery($query);
     $result = $db->loadObjectList();
     if (!$result) {
         return false;
     }
     foreach ($result as $row) {
         $customized_datas[(int) $row->product_id][(int) $row->product_attribute_id][(int) $row->address_delivery_id][(int) $row->customization_id]['quantity'] = (int) $row->quantity;
         $customized_datas[(int) $row->product_id][(int) $row->product_attribute_id][(int) $row->address_delivery_id][(int) $row->customization_id]['quantity_refunded'] = (int) $row->quantity_refunded;
         $customized_datas[(int) $row->product_id][(int) $row->product_attribute_id][(int) $row->address_delivery_id][(int) $row->customization_id]['quantity_returned'] = (int) $row->quantity_returned;
     }
     return $customized_datas;
 }