Jump to content



Latest News: (loading..)

- - - - -

Is there still really no way to apply specials to attributes?


  • Please log in to reply
7 replies to this topic

#1   uncommonhound

uncommonhound
  • Members
  • 43 posts
  • Real Name:Leslie Fournier

Posted 22 November 2011 - 03:53 AM

I've searched through all the add-ons and read the forums for the past few hours (and many times before). With all the generous contributions for osCommerce.. is there really no add-on that will apply specials correctly to products with attributes? ..meaning a percentage discount on the total attribute price, and not just the base price prior to the additional attribute price.

Thanks so much to anyone that can point me in the right direction!

#2   uncommonhound

uncommonhound
  • Members
  • 43 posts
  • Real Name:Leslie Fournier

Posted 22 November 2011 - 04:01 PM

Does anyone even want to have a discussion about this? Isn't it a feature that many people need?

#3   hookswitch

hookswitch
  • Members
  • 5 posts
  • Real Name:CB

Posted 15 March 2012 - 06:54 PM

I need this, too.    If I come up with a solution I'll post it.

#4   DunWeb

DunWeb

    The Censored One

  • Members
  • 12,732 posts
  • Real Name:Chris
  • Gender:Male
  • Location:Ontario, Canada

Posted 15 March 2012 - 06:55 PM

@hookswitch

I don't believe there is currently a way to put an attribute on sale.



Chris
:|: Was this post helpful ? Click the LIKE THIS button :|:

See my Profile (click here)

#5   hookswitch

hookswitch
  • Members
  • 5 posts
  • Real Name:CB

Posted 15 March 2012 - 11:14 PM

I got this figured out for osCommerce 2.3.1.   To apply the specials_percent discount to any product which has a specials_percent entry in the specials table,  I modified calculate_price() in includes/classes/currencies.php:

function calculate_price($products_price, $products_tax, $quantity = 1, $product_id = '') {
	  global $currency;
	 
	  if($product_id){
	   // Apply specials_percent discount
	   $discount = get_specials_discount_percent($product_id);
	   if($discount > 0){
				// Don't apply if specials_percent is zero (as in the case of products with a static discount amount
		$products_price = $products_price * $discount;
	   }
   }
  
	  return tep_round(tep_add_tax($products_price, $products_tax), $this->currencies[$currency]['decimal_places']) * $quantity;
	}



And also add the argument to display_price():

	function display_price($products_price, $products_tax, $quantity = 1, $product_id = '') {
	  return $this->format($this->calculate_price($products_price, $products_tax, $quantity, $product_id));
	}





After that, you need the new function get_specials_discount_percent().  

In includes/functions/general.php:

////
// Return the specials_percent for a given product so we can apply it to attributes option values
// TABLES: specials
function get_specials_discount_percent($product_id){
$product_query = tep_db_query("select specials_percent from " . TABLE_SPECIALS . " where products_id = '" . (int)$product_id . "' and status = 1");
	$product = tep_db_fetch_array($product_query);
	return $product['specials_percent'];
}



NOW,  2 things need to happen:
  • Add the product_id as the 4th argument wherever display_price() or calculate_price() are called.
  • Modify product_info.php  to display the discounted price in the options list.


#1:

In includes/classes/shopping_cart.php (in 2 spots):

$this->total -= $currencies->calculate_price($attribute_price['options_values_price'], $products_tax, $qty, (int)$prid);


In shopping_cart.php (different file):


	  echo '		<td valign="top">' . $products_name . '</td>' .
		   '		<td align="right" valign="top"><strong>' . $currencies->display_price($products[$i]['final_price'], tep_get_tax_rate($products[$i]['tax_class_id']), $products[$i]['quantity'], $products[$i]['id']) . '</strong></td>' .
		   '	  </tr>';



In checkout_process.php:

//------insert customer choosen option eof ----
	$products_ordered .= $order->products[$i]['qty'] . ' x ' . $order->products[$i]['name'] . ' (' . $order->products[$i]['model'] . ') = ' . $currencies->display_price($order->products[$i]['final_price'], $order->products[$i]['tax'], $order->products[$i]['qty'], $order->products[$i]['id']) . $products_ordered_attributes . "\n";


In checkout_confirmation.php:


	echo '			<td align="right" valign="top">' . $currencies->display_price($order->products[$i]['final_price'], $order->products[$i]['tax'], $order->products[$i]['qty'], $order->products[$i]['id']) . '</td>' . "\n" .
		 '		  </tr>' . "\n";



and in includes/classes/order.php:

		$shown_price = $currencies->calculate_price($this->products[$index]['final_price'], $this->products[$index]['tax'], $this->products[$index]['qty'], $products[$i]['id']);





#2:

In product_info.php:


// Apply specials_percent discount to attributes option values
		 $discount = get_specials_discount_percent((int)$HTTP_GET_VARS['products_id']);
		 $products_options['options_values_price'] = $products_options['options_values_price'] * $discount;



I hope I didn't forget anything.    No time to make a contribution out of it right now,  but maybe someone else would like to do that,  or osCommerce devs might consider somehow making this a toggle-able option in the admin under Specials. Good luck.

#6   hookswitch

hookswitch
  • Members
  • 5 posts
  • Real Name:CB

Posted 19 March 2012 - 06:08 PM

I DID forget something.   Or rather,  didn't notice.    Line item prices shown in admin/orders.php  and admin/invoice.php also need some help displaying the price minus discount (though with my above changes the Subtotal and Totals are summed correctly with tax applied).

Anyway,  it needs to be applied in the class, but first we need the previously-used function get_specials_discount_percent() from general.php to be present in admin/includes/general.php  (there are slightly different "includes" under admin/  in case you didn't notice):

In admin/includes/functions/general.php:

////
// Return the specials_percent for a given product so we can apply it to attributes option values - CB 03-19-2012
// TABLES: specials
function get_specials_discount_percent($product_id){
$product_query = tep_db_query("select specials_percent from " . TABLE_SPECIALS . " where products_id = '" . (int)$product_id . "' and status = 1");
	$product = tep_db_fetch_array($product_query);
	return $product['specials_percent'];
} 
////
// Return the price with the specials discount applied
function apply_specials_discount($product_id, $price){
	  $discount = get_specials_discount_percent($product_id);
	  if($discount &amp;--#62; 0){
	   $price = $price * $discount;
	  }
	 return $price;
}



In admin/includes/classes/order.php,  wherever you see a "price" being displayed,  wrap that value in our function call (you have to pass the product_id too, of course, so that it can look up the specials discount percent):


while ($orders_products = tep_db_fetch_array($orders_products_query)) {
		$this-&amp;--#62;products[$index] = array('qty' =&amp;--#62; $orders_products['products_quantity'],
										'name' =&amp;--#62; $orders_products['products_name'],
										'model' =&amp;--#62; $orders_products['products_model'],
										'tax' =&amp;--#62; $orders_products['products_tax'],
										'price' =&amp;--#62; apply_specials_discount($orders_products['products_id'],$orders_products['products_price']),
										'final_price' =&amp;--#62; apply_specials_discount($orders_products['products_id'],$orders_products['final_price']));
		$subindex = 0;
		$attributes_query = tep_db_query("select products_options, products_options_values, options_values_price, price_prefix from " . TABLE_ORDERS_PRODUCTS_ATTRIBUTES . " where orders_id = '" . (int)$order_id . "' and orders_products_id = '" . (int)$orders_products['orders_products_id'] . "'");
		if (tep_db_num_rows($attributes_query)) {
		  while ($attributes = tep_db_fetch_array($attributes_query)) {
			$this-&amp;--#62;products[$index]['attributes'][$subindex] = array('option' =&amp;--#62; $attributes['products_options'],
																	 'value' =&amp;--#62; $attributes['products_options_values'],
																	 'prefix' =&amp;--#62; $attributes['price_prefix'],
																	 'price' =&amp;--#62; apply_specials_discount($orders_products['products_id'],$attributes['options_values_price']));
			$subindex++;
		  }
		}
		$index++;
	  }


OK, done.



NOTE:

This seems odd:   the final_price in the database for each item of the order is displayed as the product price without the discount applied.   We applied it in the shopping cart calculation,  however, so the customer was charged appropriately and the totals reflect the amount charged.   If this becomes a problem, and it becomes necessary to make sure that final_price is inserted as the price less the discount,   I'll post about it.   So far, so good,  however.

Edited by hookswitch, 19 March 2012 - 06:09 PM.


#7   limar

limar
  • Members
  • 3 posts

Posted 05 September 2012 - 02:45 PM

Isn't this possible with the master/slave products contribution?

#8   modem2.0

modem2.0
  • Members
  • 70 posts
  • Real Name:Modem 2.0

Posted 16 September 2012 - 06:16 PM

View Posthookswitch, on 19 March 2012 - 06:08 PM, said:

NOTE:

This seems odd:   the final_price in the database for each item of the order is displayed as the product price without the discount applied.   We applied it in the shopping cart calculation,  however, so the customer was charged appropriately and the totals reflect the amount charged.   If this becomes a problem, and it becomes necessary to make sure that final_price is inserted as the price less the discount,   I'll post about it.   So far, so good,  however.
Hi hookswitch,

is there a way to fix this?

Thanks!