public static function getWholesalePrice($id_product, $id_product_attribute = 0, $id_supplier = 0) { // If there's a supplier if (!empty($id_supplier)) { // Getting supplier's price first $prices = ErpProductSupplier::getProductSupplierPrice($id_product, $id_product_attribute, $id_supplier, true); $price = $prices['product_supplier_price_te']; } // If no supplier's price, or supplier's price null, we look for the price of the product or variation if (empty($price) || $price == '0.000000') { // No variation, looking for product's price if ($id_product_attribute == 0) { $query = new DbQuery(); $query->select('wholesale_price'); $query->from('product'); $query->where('id_product = ' . (int) $id_product); $price = Db::getInstance()->getValue($query); } else { $query = new DbQuery(); $query->select('p.wholesale_price as wholesale_price_product, pa.wholesale_price as wholesale_price_product_attribute'); $query->from('product_attribute', 'pa'); $query->where('pa.id_product = ' . (int) $id_product); $query->where('pa.id_product_attribute = ' . (int) $id_product_attribute); $query->innerJoin('product', 'p', ' p.id_product = pa.id_product'); $prices = Db::getInstance()->getRow($query); // if variation's price if (!empty($prices['wholesale_price_product_attribute']) && $prices['wholesale_price_product_attribute'] != '0.000000') { $price = $prices['wholesale_price_product_attribute']; } elseif (!empty($prices['wholesale_price_product']) && $prices['wholesale_price_product'] != '0.000000') { $price = $prices['wholesale_price_product']; } else { $price = '0.00000'; } } } return $price; }
public static function getWholesalePrice($id_product, $id_product_attribute = 0, $id_supplier = 0) { // If there is a supplier if (!empty($id_supplier)) { //On récupère tout d'abord le prix du fournisseur $prices = ErpProductSupplier::getProductSupplierPrice($id_product, $id_product_attribute, $id_supplier, true); if (isset($prices['product_supplier_price_te'])) { $price = $prices['product_supplier_price_te']; } } // If no price for this supplier, or supplier price null, // get the price of the product or variation if (empty($price) || $price == '0.000000') { // pas de décliaison, on cherche le prix du produit if ($id_product_attribute == 0) { $query = new DbQuery(); $query->select('wholesale_price'); $query->from('product'); $query->where('id_product = ' . (int) $id_product); $price = Db::getInstance()->getValue($query); } else { $query = new DbQuery(); $query->select('p.wholesale_price as wholesale_price_product, pa.wholesale_price as wholesale_price_product_attribute'); $query->from('product_attribute', 'pa'); $query->where('pa.id_product = ' . (int) $id_product); $query->where('pa.id_product_attribute = ' . (int) $id_product_attribute); $query->innerJoin('product', 'p', ' p.id_product = pa.id_product'); $prices = Db::getInstance()->getRow($query); //If variation has a price if ($prices['wholesale_price_product_attribute'] == '0.000000') { $price = $prices['wholesale_price_product']; } elseif ($prices['wholesale_price_product_attribute'] != '0.000000') { $price = $prices['wholesale_price_product_attribute']; } else { $price = '0.00000'; } } } return $price; }