Permalink
Browse files

Global Fixing display variants price with tax

Signed-off-by: Gergely <t-gely@freemail.hu>
  • Loading branch information...
tgely committed Aug 3, 2010
1 parent bc1a2ba commit 7b3ce84b8ac83d6966a8cc4469ff66c0763e111a
Showing with 72 additions and 5 deletions.
  1. +72 −5 osCommerce/OM/Core/Site/Shop/Product.php
@@ -109,7 +109,8 @@ public function __construct($id) {
$Qsubproducts->execute();
while ( $Qsubproducts->next() ) {
- $this->_data['variants'][$Qsubproducts->valueInt('products_id')]['data'] = array('price' => $Qsubproducts->value('products_price'),
+ $this->_data['variants'][$Qsubproducts->valueInt('products_id')]['data'] = array('products_id' => $Qsubproducts->value('products_id'), //by Gergely
+ 'price' => $Qsubproducts->value('products_price'),
'tax_class_id' => $Qsubproducts->valueInt('products_tax_class_id'),
'model' => $Qsubproducts->value('products_model'),
'quantity' => $Qsubproducts->value('products_quantity'),
@@ -209,15 +210,15 @@ public function getTags() {
return $this->_data['tags'];
}
- public function getPrice($with_special = false) {
+ public function getPrice($with_special = false, $variants_id = null) {
$OSCOM_Service = Registry::get('Service');
$OSCOM_Currencies = Registry::get('Currencies');
if ( ($with_special === true) && $OSCOM_Service->isStarted('Specials') && ($new_price = Registry::get('Specials')->getPrice($this->_data['id'])) ) {
$price = $OSCOM_Currencies->displayPriceRaw($new_price, $this->_data['tax_class_id']);
} else {
if ( $this->hasVariants() ) {
- $price = $OSCOM_Currencies->displayPriceRaw($this->getVariantMinPrice(), $this->_data['tax_class_id']);
+ $price = $OSCOM_Currencies->displayPriceRaw(( $variants_id != null) ? $this->getVariantExactPrice($variants_id) : $this->getVariantMinPrice(), ( $variants_id != null) ? $this->getVariantExactPrice($variants_id) : $this->getVariantMinPriceTaxClassId($variants_id));
} else {
$price = $OSCOM_Currencies->displayPriceRaw($this->_data['price'], $this->_data['tax_class_id']);
}
@@ -226,15 +227,15 @@ public function getPrice($with_special = false) {
return $price;
}
- public function getPriceFormated($with_special = false) {
+ public function getPriceFormated($with_special = false, $variants_id = null) {
$OSCOM_Service = Registry::get('Service');
$OSCOM_Currencies = Registry::get('Currencies');
if ( ($with_special === true) && $OSCOM_Service->isStarted('Specials') && ($new_price = Registry::get('Specials')->getPrice($this->_data['id'])) ) {
$price = '<s>' . $OSCOM_Currencies->displayPrice($this->_data['price'], $this->_data['tax_class_id']) . '</s> <span class="productSpecialPrice">' . $OSCOM_Currencies->displayPrice($new_price, $this->_data['tax_class_id']) . '</span>';
} else {
if ( $this->hasVariants() ) {
- $price = 'from&nbsp;' . $OSCOM_Currencies->displayPrice($this->getVariantMinPrice(), $this->_data['tax_class_id']);
+ $price = 'from&nbsp;' . $OSCOM_Currencies->displayPrice(( $variants_id != null) ? $this->getVariantExactPrice($variants_id) : $this->getVariantMinPrice(), ( $variants_id != null) ? $this->getVariantExactTaxClassId($variants_id) : $this->getVariantMinPriceTaxClassId($variants_id));
} else {
$price = $OSCOM_Currencies->displayPrice($this->_data['price'], $this->_data['tax_class_id']);
}
@@ -267,6 +268,72 @@ public function getVariantMaxPrice() {
return $price;
}
+ public function getVariantMaxPriceTaxClassId() {
+ $taxclassid = 0;
+
+ foreach ( $this->_data['variants'] as $variant ) {
+ if ( $variant['data']['price'] > $price ) {
+ $taxclassid = $variant['data']['tax_class_id'];
+ }
+ }
+
+ return $taxclassid;
+ }
+
+ public function getVariantMinPriceTaxClassId() {
+ $taxclassid = null;
+
+ foreach ( $this->_data['variants'] as $variant ) {
+ if ( ($price === null) || ($variant['data']['price'] < $price) ) {
+ $price = $variant['data']['tax_class_id'];
+ }
+ }
+
+ return ( $taxclassid !== null ) ? $taxclassid : 0;
+ }
+
+ public function getVariantExactPrice($variants_id) {
+ $price = null;
+
+ if ( $this->hasVariants() ) {
+ foreach ( $this->_data['variants'] as $subproduct_id => $variants ) {
+ foreach ( $variants['values'] as $group_id => $values ) {
+ foreach ( $values as $value_id => $data ) {
+ if ( $variants['data']['products_id'] == $variants_id) {
+ $price = $variants['data']['price'];
+
+ break 3;
+ }
+ }
+ }
+
+ }
+ }
+
+ return ( $price !== null ) ? $price : 0;
+ }
+
+ public function getVariantExactTaxClassId($variants_id) {
+ $taxclassid = 0;
+
+ if ( $this->hasVariants() ) {
+ foreach ( $this->_data['variants'] as $subproduct_id => $variants ) {
+ foreach ( $variants['values'] as $group_id => $values ) {
+ foreach ( $values as $value_id => $data ) {
+ if ( $variants['data']['products_id'] == $variants_id) {
+ $taxclass = $variants['data']['tax_class_id'];
+
+ break 3;
+ }
+ }
+ }
+
+ }
+ }
+
+ return $taxclassid;
+ }
+
public function getQuantity() {
$quantity = $this->_data['quantity'];

0 comments on commit 7b3ce84

Please sign in to comment.