Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Attribute Percentage


Jack_mcs

Recommended Posts

This contribution allows you to add a product attribute that will add a percentage of the products price instead of using the plus or minus.

 

 

Jack

Edited by Jack_mcs

Support Links:

For Hire: Contact me for anything you need help with for your shop: upgrading, hosting, repairs, code written, etc.

All of My Addons

Get the latest versions of my addons

Recommended SEO Addons

Link to comment
Share on other sites

  • Replies 50
  • Created
  • Last Reply

Top Posters In This Topic

This contribution allows you to add a product attribute that will add a percentage of the products price instead of using the plus or minus.

Jack

Well, I got to the last step in the installation, which is product_info.php, and after finding the statement it says to find, I find this in the instructions:

 

ADD THIS UNDER IT:

 

 

That's it.

 

I'm assuming I was supposed to find the line in product_info.php in order to add something below it, but there's no line in the instructions to add.

Link to comment
Share on other sites

Oops - guess that won't work like that. It should have the following to add

		   // BOC Attribute Percentage
	   if ($products_options['price_prefix'] == ATTRIBUTE_PERCENTAGE_SYMBOL)
		$products_options_array[sizeof($products_options_array)-1]['text'] .= ' (' . $products_options['price_prefix'] . $currencies->display_price_percentage($products_options['options_values_price'], tep_get_tax_rate($product_info['products_tax_class_id'])) .') ';
	   else
	   // EOC Attribute Percentage

 

Jack

Support Links:

For Hire: Contact me for anything you need help with for your shop: upgrading, hosting, repairs, code written, etc.

All of My Addons

Get the latest versions of my addons

Recommended SEO Addons

Link to comment
Share on other sites

  • 1 month later...

hi there jack.

 

i've followed your instructions to the letter and cannot get this contrib to work.

 

what am i doing?

 

i'm creating a new product option (maintenance), a new option value (one year free maintenance) and a new product attribute (.20) and then the operator *

 

when i enter the * as is stipulated in my english.php it doesn't calculate percentage. Matter of fact, with * as the operator the page 'product_info.php' stops rendering at the point where the Maintenance drop down is supposed to display. So when i enter a + instead, it actually adds $19.80 to the order total.

 

i've tried entering different operators in my english.php and matching that up and nothing seems to work.

 

help?

Link to comment
Share on other sites

Does the shop work if you don't enter an attribute with the *? It sounds like there was a mistake in the installation.

 

Jack

Support Links:

For Hire: Contact me for anything you need help with for your shop: upgrading, hosting, repairs, code written, etc.

All of My Addons

Get the latest versions of my addons

Recommended SEO Addons

Link to comment
Share on other sites

the shop works fine. it's just that your contribution doesn't. i followed the instructions to a T and have been using osc for 2+ years. with 20+ contributions integrated and having developed my own contrib, i can assure you the contrib was implemented to the letter.

 

ideas?

Link to comment
Share on other sites

The contribution works fine. I have installed it into a number of shops. It is either a mistake on the installation or a conflict with some other change you have made.

 

Jack

Support Links:

For Hire: Contact me for anything you need help with for your shop: upgrading, hosting, repairs, code written, etc.

All of My Addons

Get the latest versions of my addons

Recommended SEO Addons

Link to comment
Share on other sites

Jack,

 

i finally got time to look at this and figured it out. the instructions in the readme are a bit different for currencies.php and result in an existing currencies.php ending up differently than the included currencies.php.

 

so, i just used your included currencies.php and it works.

 

BUT, i have an issue that i'm hoping you can help with.

 

my catalog has a base product with a base price of $100.

customers add options to that base product and end up with a total price greater than the base product.

there are scenarios where the total order could be $1,000.

your Attribute Percentage contribution calculates on the product price, not the order total.

 

What needs to be changed in order for this to be fixed?

Link to comment
Share on other sites

That's not the intention of the contribution. It applies a percentage to a particular attribute. If you have a number of attributes to be added, they would all have to be setup to use the percentage.

 

Jack

Support Links:

For Hire: Contact me for anything you need help with for your shop: upgrading, hosting, repairs, code written, etc.

All of My Addons

Get the latest versions of my addons

Recommended SEO Addons

Link to comment
Share on other sites

Jack,

 

do you have an idea as how to do this?

 

I have base product. it's $100. it's software.

 

i have an attribute called "License" where the customer can select a license from $100 all the way up to $1,000.

 

so the total value of a product could be $200 all the way to $1,100.

 

if a customer wants maintence/support we charge 20%.

 

the way i've implemented maintenace/support is by using your attribute percentage contrib on a new option called "maintenance." but it only calculates percentage on base price.

 

any ideas?

 

thx

Link to comment
Share on other sites

The code would have to be rewritten to deal with that. In the classes/shopping_cart.php file, the percentage is figured using the base price. The code would need to be changed to add in whatever attributes were chosen along with it. It is not something I can tell you how to do in the forums. But, if you are able, there are only two places in that file that perform the calculations so I don't think the change would be too involved.

 

Jack

Support Links:

For Hire: Contact me for anything you need help with for your shop: upgrading, hosting, repairs, code written, etc.

All of My Addons

Get the latest versions of my addons

Recommended SEO Addons

Link to comment
Share on other sites

Jack,

 

Is there anyway you could give a pointer as to what in your code needs to be changed?

 

I would greatly apreciate it.

 

If you provide a solution, I'd gladly pay you... do you have paypal or something or could I send you a check?

Link to comment
Share on other sites

The code to be changed is the code for the contribution (or around it) and that is indicated by beginning and ending markers in the code.

 

Jack

Support Links:

For Hire: Contact me for anything you need help with for your shop: upgrading, hosting, repairs, code written, etc.

All of My Addons

Get the latest versions of my addons

Recommended SEO Addons

Link to comment
Share on other sites

  • 1 month later...

Well I installed it and am getting the following error when I go to an item:

 

Fatal error: Call to undefined function: display_price_percentage() in /home/public_html/product_info.php on line 140

 

I am also using STS v4.4, and I wonder if that might be the problem.

 

Any help will be appreceated!

 

Thanks,

 

Tom

Link to comment
Share on other sites

That error means it can't find the new code this contribution adds. It is either because of a mistake in the installation of it or STS is not loading it somehow. You could try turning STS off to see if that makes a difference.

 

Jack

Support Links:

For Hire: Contact me for anything you need help with for your shop: upgrading, hosting, repairs, code written, etc.

All of My Addons

Get the latest versions of my addons

Recommended SEO Addons

Link to comment
Share on other sites

Jack,

 

I've shut STS off and get the same error. Here is the code I have at the end of my currencies.php:

 

  // BOC Attribute Percentage
     function format_percentage($number, $calculate_currency_value = true, $currency_type = '', $currency_value = '') {
       global $currency;

       if (empty($currency_type)) $currency_type = $currency;
       if ($calculate_currency_value == true) {
         $rate = (tep_not_null($currency_value)) ? $currency_value : $this->currencies[$currency_type]['value'];
         $format_string = number_format(tep_round($number * $rate, $this->currencies[$currency_type]['decimal_places']), $this->currencies[$currency_type]['decimal_places'], $this->currencies[$currency_type]['decimal_point'], $this->currencies[$currency_type]['thousands_point']) . "%";
 // if the selected currency is in the european euro-conversion and the default currency is euro,
 // the currency will displayed in the national currency and euro currency
         if ( (DEFAULT_CURRENCY == 'EUR') && ($currency_type == 'DEM' || $currency_type == 'BEF' || $currency_type == 'LUF' || $currency_type == 'ESP' || $currency_type == 'FRF' || $currency_type == 'IEP' || $currency_type == 'ITL' || $currency_type == 'NLG' || $currency_type == 'ATS' || $currency_type == 'PTE' || $currency_type == 'FIM' || $currency_type == 'GRD') ) {
           $format_string .= ' <small>[' . $this->format($number, true, 'EUR') . ']</small>';
         }
       } else {
         $format_string = number_format(tep_round($number, $this->currencies[$currency_type]['decimal_places']), $this->currencies[$currency_type]['decimal_places'], $this->currencies[$currency_type]['decimal_point'], $this->currencies[$currency_type]['thousands_point']) . "%";
       }

       return $format_string;
     }
     // EOC Attribute Percentage

     // BOC Attribute Percentage
     function display_price_percentage($products_price, $products_tax, $quantity = 1) {
       return $this->format_percentage(tep_add_tax($products_price, $products_tax) * $quantity);
     }
   // EOC Attribute Percentage
?>

 

I'm not a programmer but I don't see any obvious problems with it (but, as I said, I'm not a programmer so ...).

 

Tom

Link to comment
Share on other sites

Try changing where it says display_price_percentage to display_price on the product_info page. That will cause it to use the stock code. The percentage option won't work but the change will tell you where the problem is at. If you still get a failure, then the problem doesn't have to do with this contribution. If it runs, then the contributions code isn't installed correctly somehow.

 

Jack

Support Links:

For Hire: Contact me for anything you need help with for your shop: upgrading, hosting, repairs, code written, etc.

All of My Addons

Get the latest versions of my addons

Recommended SEO Addons

Link to comment
Share on other sites

When setting an attribute of .15 * for a product I get an error when the line says display_price_percentage and no error when it is changed to display_price although it does show the attribute in the correct drop down as "attribute name (*$0.15) and when I add the item to the cart with that attribute it does add 15% to the price.

 

So after changing the line to display_price the attribute works correctly but doesn't display correctly in the drop down list.

 

Any ideas?

 

 

Tom

Link to comment
Share on other sites

It means your code can see the currencies class but cannot see the new code added to it. So I would have to question if the code is actually in the currencies class file.

 

Jack

Support Links:

For Hire: Contact me for anything you need help with for your shop: upgrading, hosting, repairs, code written, etc.

All of My Addons

Get the latest versions of my addons

Recommended SEO Addons

Link to comment
Share on other sites

Here is the complete text of me currencies.php from /includes/classes/

 

<?php
/*
 $Id: currencies.php,v 1.16 2003/06/05 23:16:46 hpdl Exp $

 osCommerce, Open Source E-Commerce Solutions
 [url="http://www.oscommerce.com"]http://www.oscommerce.com[/url]

 Copyright © 2003 osCommerce

 Released under the GNU General Public License
*/

////
// Class to handle currencies
// TABLES: currencies
 class currencies {
   var $currencies;

// class constructor
   function currencies() {
     $this->currencies = array();
     $currencies_query = tep_db_query("select code, title, symbol_left, symbol_right, decimal_point, thousands_point, decimal_places, value from " . TABLE_CURRENCIES);
     while ($currencies = tep_db_fetch_array($currencies_query)) {
       $this->currencies[$currencies['code']] = array('title' => $currencies['title'],
                                                      'symbol_left' => $currencies['symbol_left'],
                                                      'symbol_right' => $currencies['symbol_right'],
                                                      'decimal_point' => $currencies['decimal_point'],
                                                      'thousands_point' => $currencies['thousands_point'],
                                                      'decimal_places' => $currencies['decimal_places'],
                                                      'value' => $currencies['value']);
     }
   }

// class methods
   function format($number, $calculate_currency_value = true, $currency_type = '', $currency_value = '') {
     global $currency;

     if (empty($currency_type)) $currency_type = $currency;

     if ($calculate_currency_value == true) {
       $rate = (tep_not_null($currency_value)) ? $currency_value : $this->currencies[$currency_type]['value'];
       $format_string = $this->currencies[$currency_type]['symbol_left'] . number_format(tep_round($number * $rate, $this->currencies[$currency_type]['decimal_places']), $this->currencies[$currency_type]['decimal_places'], $this->currencies[$currency_type]['decimal_point'], $this->currencies[$currency_type]['thousands_point']) . $this->currencies[$currency_type]['symbol_right'];
// if the selected currency is in the european euro-conversion and the default currency is euro,
// the currency will displayed in the national currency and euro currency
       if ( (DEFAULT_CURRENCY == 'EUR') && ($currency_type == 'DEM' || $currency_type == 'BEF' || $currency_type == 'LUF' || $currency_type == 'ESP' || $currency_type == 'FRF' || $currency_type == 'IEP' || $currency_type == 'ITL' || $currency_type == 'NLG' || $currency_type == 'ATS' || $currency_type == 'PTE' || $currency_type == 'FIM' || $currency_type == 'GRD') ) {
         $format_string .= ' <small>[' . $this->format($number, true, 'EUR') . ']</small>';
       }
     } else {
       $format_string = $this->currencies[$currency_type]['symbol_left'] . number_format(tep_round($number, $this->currencies[$currency_type]['decimal_places']), $this->currencies[$currency_type]['decimal_places'], $this->currencies[$currency_type]['decimal_point'], $this->currencies[$currency_type]['thousands_point']) . $this->currencies[$currency_type]['symbol_right'];
     }

     return $format_string;
   }

   function is_set($code) {
     if (isset($this->currencies[$code]) && tep_not_null($this->currencies[$code])) {
       return true;
     } else {
       return false;
     }
   }

   function get_value($code) {
     return $this->currencies[$code]['value'];
   }

   function get_decimal_places($code) {
     return $this->currencies[$code]['decimal_places'];
   }

   function display_price($products_price, $products_tax, $quantity = 1) {
     return $this->format(tep_add_tax($products_price, $products_tax) * $quantity);
   }
 }
 // BOC Attribute Percentage
     function format_percentage($number, $calculate_currency_value = true, $currency_type = '', $currency_value = '') {
       global $currency;

       if (empty($currency_type)) $currency_type = $currency;
       if ($calculate_currency_value == true) {
         $rate = (tep_not_null($currency_value)) ? $currency_value : $this->currencies[$currency_type]['value'];
         $format_string = number_format(tep_round($number * $rate, $this->currencies[$currency_type]['decimal_places']), $this->currencies[$currency_type]['decimal_places'], $this->currencies[$currency_type]['decimal_point'], $this->currencies[$currency_type]['thousands_point']) . "%";
 // if the selected currency is in the european euro-conversion and the default currency is euro,
 // the currency will displayed in the national currency and euro currency
         if ( (DEFAULT_CURRENCY == 'EUR') && ($currency_type == 'DEM' || $currency_type == 'BEF' || $currency_type == 'LUF' || $currency_type == 'ESP' || $currency_type == 'FRF' || $currency_type == 'IEP' || $currency_type == 'ITL' || $currency_type == 'NLG' || $currency_type == 'ATS' || $currency_type == 'PTE' || $currency_type == 'FIM' || $currency_type == 'GRD') ) {
           $format_string .= ' <small>[' . $this->format($number, true, 'EUR') . ']</small>';
         }
       } else {
         $format_string = number_format(tep_round($number, $this->currencies[$currency_type]['decimal_places']), $this->currencies[$currency_type]['decimal_places'], $this->currencies[$currency_type]['decimal_point'], $this->currencies[$currency_type]['thousands_point']) . "%";
       }

       return $format_string;
     }
     // EOC Attribute Percentage

     // BOC Attribute Percentage
     function display_price_percentage($products_price, $products_tax, $quantity = 1) {
       return $this->format_percentage(tep_add_tax($products_price, $products_tax) * $quantity);
     }
   // EOC Attribute Percentage
?>

 

That should be the correct currency file, right?

 

Tom

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...