public function get_product_price_with_properties() { $pid = $this->input->get('id', 0, 'int'); $val_prop_id = $this->input->get('val_prop_id', 0, 'int'); $prop_id = $this->input->get('prop_id', 0, 'int'); $selectedProperties = $this->input->get('properties', array(), 'array'); $db = JFactory::getDBO(); $app = JFactory::getApplication(); $properties = KSMProducts::getProperties($pid, $prop_id, $val_prop_id); $productProperties = KSMProducts::getProperties($pid); $prices = KSMProducts::getProductPrices($pid); $price = $prices->price; $price_type = $prices->price_type; $checked = array(); foreach ($productProperties as $property) { foreach ($selectedProperties as $selectedPropId => $selectedProperty) { foreach ($selectedProperty as $selectedValueId => $selectedValue) { if (isset($selectedValue['checked'])) { $checked[$selectedValue['valueId']] = $selectedValue['checked']; } if ($property->property_id == $selectedValue['propId'] && $val_prop_id != $property->values[$selectedValueId]->id) { $edit_priceC = $property->values[$selectedValueId]->price; $edit_price_symC = substr($edit_priceC, 0, 1); $this->getCalcPriceAsProperties($edit_price_symC, $edit_priceC, $price); $property->values[$selectedValueId]->id . '-' . $price . "\n\t"; } } } } foreach ($properties as $property) { $edit_price = null; if ($property->edit_price) { if ($property->view == 'checkbox') { $value = array_pop($property->values); if ($checked[$value->id]) { $edit_price = $value->price; } } elseif ($property->view == 'select' || $property->view == 'radio') { if ($val_prop_id != 0) { $edit_price = $property->values[$val_prop_id]->price; } } } if ($edit_price) { $edit_price_sym = substr($edit_price, 0, 1); $this->getCalcPriceAsProperties($edit_price_sym, $edit_price, $price); } } $price = KSMPrice::getPriceInCurrentCurrency($price, $price_type); $app->close($price . '^^^' . $price); }
public static function getPriceWithProperties($product_id, $properties = array(), $price = null) { $db = JFactory::getDBO(); if (empty($price)) { $product = KSSystem::loadDbItem($product_id, 'products'); $price = KSMPrice::getPriceInCurrentCurrency($product->price, $product->price_type); } foreach ($properties as $property_id => $values) { $query = $db->getQuery(true); $query->select('edit_price')->from('#__ksenmart_properties'); $query->where('id=' . $property_id); $db->setQuery($query); $edit_price = $db->loadResult(); if ($edit_price == 1) { foreach ($values as $value_id) { $query = $db->getQuery(true); $query->select('price')->from('#__ksenmart_product_properties_values'); $query->where('property_id=' . $property_id)->where('value_id=' . $value_id)->where('product_id=' . $product_id); $db->setQuery($query); $under_price = $db->loadResult(); if ($under_price && !empty($under_price)) { $under_price_act = substr($under_price, 0, 1); switch ($under_price_act) { case '+': $price += substr($under_price, 1, strlen($under_price) - 1); break; case '-': $price -= substr($under_price, 1, strlen($under_price) - 1); break; case '/': $price = $price / substr($under_price, 1, strlen($under_price) - 1); break; case '*': $price = $price * substr($under_price, 1, strlen($under_price) - 1); break; default: $price += $under_price; } } } } } return $price; }