Jump to content



Latest News: (loading..)

* * * * * 1 votes

Attribute Product Codes [Contribution]


  • Please log in to reply
55 replies to this topic

#41   roquetsynce

roquetsynce
  • Members
  • 96 posts
  • Real Name:Roquet Synce
  • Location:Vancouver, BC

Posted 18 December 2007 - 07:48 PM

I have two sizes for one product, then there are multiple flavours for each...

Base # ID1

1 oz - Suffix = 6
2 oz - Suffix = 7

Apple - Suffix = 00
Pear - Suffix = 01
- Suffix = 02

etc

On the orders page the product model numbers are backwards! It is showing as  "ID1-00-6", I need it to be "ID1-6-00". I have changed the suffix order but that doesnt seem to have an effect.

Thoughts?

Thanks in advance!

~Roq

#42   abrown1982

abrown1982
  • Members
  • 2 posts
  • Real Name:Allan

Posted 09 January 2008 - 09:51 AM

Hi All,

Im having an issue where the "products_code" isint being inserted into the database.  From looking at the code I think this should be done in checkout_process.php around line 160 right?  When is checkout_process.php called, and is it possible that if im using a different payment method that this isint the file which is doing the inserting?

Thanks,

Allan

#43   jemmasta

jemmasta
  • Members
  • 23 posts
  • Real Name:Aarne Salminen

Posted 25 February 2008 - 12:54 AM

View Postabrown1982, on Jan 9 2008, 09:51 AM, said:

Hi All,

Im having an issue where the "products_code" isint being inserted into the database.  From looking at the code I think this should be done in checkout_process.php around line 160 right?  When is checkout_process.php called, and is it possible that if im using a different payment method that this isint the file which is doing the inserting?

Thanks,

Allan


Do note that in file catalog/includes/classes/shopping_cart.php the change has to be in function get_products().

#44   jemmasta

jemmasta
  • Members
  • 23 posts
  • Real Name:Aarne Salminen

Posted 25 February 2008 - 01:08 AM

I have a problem in getting this to work. For some reason the suffix won't go through.

In catalog/includes/classes/shopping_cart.php and in function get_products() the following:

		$attribute_code_array = array();
		if (is_array($this->contents[$products_id]['attributes'])) {
		while (list($option, $value) = each($this->contents[$products_id]['attributes'])) {
		  $attribute_code_query = tep_db_query("select code_suffix, suffix_sort_order from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . (int)$prid . "' and options_id = '" . (int)$option . "' and options_values_id = '" . (int)$value . "'");
		  $attribute_code = tep_db_fetch_array($attribute_code_query);
		  if (tep_not_null($attribute_code['code_suffix'])) {
			$attribute_code_array[(int)$attribute_code['suffix_sort_order']] = $attribute_code['code_suffix'];
			}
		  }

		$separator = '';
		if (count($attribute_code_array) > 1) {
		  $separator = '-';
		} elseif (count($attribute_code_array) == 1) {
		  $separator = '/';
		}

		$products_code = $products['products_model'] . $separator . implode("/", $attribute_code_array);
		}

The function won't go in to while loop: while (list($option, $value) = each($this->contents[$products_id]['attributes'])) {

and thus won't get the suffix from database and by that it returns wrong code, which is the product_model only. I can't figure out why the while clausule would be false in this case. Could someone smarter help? I've tested that $this->contents[$products_id]['attributes'] does have correct values. For some reason that while is just being ignored!

Edited by jemmasta, 25 February 2008 - 01:13 AM.


#45   jemmasta

jemmasta
  • Members
  • 23 posts
  • Real Name:Aarne Salminen

Posted 25 February 2008 - 01:58 AM

Did a reinstall, no change.

Also tried with while (each($this->contents[$products_id]['attributes'])){

And even then while was not entered. So
each($this->contents[$products_id]['attributes'])
for some reason returns false even if it has correct array values right before, I'm stumbled.

#46   jemmasta

jemmasta
  • Members
  • 23 posts
  • Real Name:Aarne Salminen

Posted 25 February 2008 - 03:10 AM

Ok, found the following:

Quote

If the internal pointer for the array points past the end of the array contents, each() returns FALSE.

and

Quote

After each() has executed, the array cursor will be left on the next element of the array, or past the last element if it hits the end of the array. You have to use reset() if you want to traverse the array again using each.

Wouldn't this mean, that since each() has been used in while (list($products_id, ) = each($this->contents)) {

It would point to left on the NEXT product in while when it reaches each($this->contents[$products_id]['attributes']) and so would return FALSE, because pointer is actually at the end of the array contents.

Is there any workaround available for this problem?

#47   jemmasta

jemmasta
  • Members
  • 23 posts
  • Real Name:Aarne Salminen

Posted 25 February 2008 - 03:48 AM

Ok, managed to fix this. :)

I changed this part:
		if (is_array($this->contents[$products_id]['attributes'])) {
		while (list($option, $value) = each($this->contents[$products_id]['attributes'])) {
		  $attribute_code_query = tep_db_query("select code_suffix, suffix_sort_order from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . (int)$prid . "' and options_id = '" . (int)$option . "' and options_values_id = '" . (int)$value . "'");
		  $attribute_code = tep_db_fetch_array($attribute_code_query);
		  if (tep_not_null($attribute_code['code_suffix'])) {
			$attribute_code_array[(int)$attribute_code['suffix_sort_order']] = $attribute_code['code_suffix'];
			}
		  }

to this:

		if (is_array($this->contents[$products_id]['attributes'])) {
			$i = 0;
	   	foreach ($this->contents[$products_id]['attributes'] as $attributes){
			$option = array_keys($this->contents[$products_id]['attributes']);
			$value = $this->contents[$products_id]['attributes'];
	   		$attribute_code_query = tep_db_query("select code_suffix, suffix_sort_order from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . (int)$prid . "' and options_id = '" . (int)$option[$i] . "' and options_values_id = '" . (int)$value[$option[$i]] . "'");
		  $attribute_code = tep_db_fetch_array($attribute_code_query);
		  if (tep_not_null($attribute_code['code_suffix'])) {
			$attribute_code_array[(int)$attribute_code['suffix_sort_order']] = $attribute_code['code_suffix'];
			}
				  $i++;
		}

So changed while logic to foreach and removed the each() by fetching key values by array_keys and using those values to point to correct option values. Perhaps a bit crude, but now it works as it should've in the first place. :) It really seems that reusing each() within a loop that has already used each() caused this problem, at least in PHP5. This solves the problem.

Edited by jemmasta, 25 February 2008 - 03:50 AM.


#48   celtic78

celtic78
  • Members
  • 2 posts
  • Real Name:Jiri

Posted 25 February 2008 - 12:35 PM

Hey,

It seems that this module isn't working with latest osCommerce version (2.2rc2a)?

Am I right?

#49   jemmasta

jemmasta
  • Members
  • 23 posts
  • Real Name:Aarne Salminen

Posted 25 February 2008 - 03:38 PM

View Postceltic78, on Feb 25 2008, 12:35 PM, said:

Hey,

It seems that this module isn't working with latest osCommerce version (2.2rc2a)?

Am I right?

The above modification allows it to work with 2.2rc2a. Don't know if the problem mentioned is on other revisions, but I have it working on 2.2rc2a after installation just make the modification I've mentioned above your post. :)

#50   celtic78

celtic78
  • Members
  • 2 posts
  • Real Name:Jiri

Posted 26 February 2008 - 09:11 AM

Yeah,

Got it working just like it should.

#51   Ian Stanley

Ian Stanley
  • Members
  • 1 posts
  • Real Name:Ian Stanley
  • Gender:Male

Posted 17 March 2010 - 12:56 PM

Is it possible to adapt this contribution, to have completely unique product codes per attribute for a particular product option instead of appending to the product's main code? Further options would append as per the original. Using the Apples example, this would become something like:

Red Apple - RED-AP
Large Red Apple - RED-AP-LG
Green Apple - GRE-AP
Large Green Apple - GRE-AP-LG
Rotten Apple - MUSHY
Large Rotten Apple - MUSHY-LG

Also, would all attributes require a product code to be entered? (so rotten apples and large rotten apples could be sold under the product code 'MUSHY')

Thanks in advance.


Ian

#52   ase2007

ase2007
  • Members
  • 35 posts
  • Real Name:Andy Everson
  • Gender:Male
  • Location:Uk/Cotswolds

Posted 23 January 2012 - 01:01 PM

has anyone managed to get this excellent contribution working with Ajax Attribute Manager?

I have mangaed to get the code copied over to the attribute manager by parrot fashion but cannot get my head around the .js part.
I have got the fields into attribute manager but it will not save to the db, guess this is where the java script comes in.
Not being a programmer I have just about got my head around the php part but .js baffles me.

If anyone can point me in the right direction on integrating code suffix into the java script of attribute manager I will upload the rest that I have done once it is working.

Regards Andy

#53   matta

matta
  • Members
  • 26 posts
  • Real Name:Matt

Posted 20 March 2012 - 06:51 AM

View Postroquetsynce, on 18 December 2007 - 07:48 PM, said:

I have two sizes for one product, then there are multiple flavours for each...

Base # ID1

1 oz - Suffix = 6
2 oz - Suffix = 7

Apple   - Suffix = 00
Pear   - Suffix = 01
Orange - Suffix = 02

etc

On the orders page the product model numbers are backwards! It is showing as  "ID1-00-6", I need it to be "ID1-6-00". I have changed the suffix order but that doesnt seem to have an effect.

Thoughts?

Thanks in advance!

~Roq

I have the same problem as @roquetsynce: It doesn't matter what you set the Suffix Order to, they always report back in the same order.

For example:

Base # ID1
1 oz - Suffix = 6, Order = 1
2 oz - Suffix = 7, Order = 1
Apple   - Suffix = 00, Order = 2
Pear   - Suffix = 01, Order = 2
Orange - Suffix = 02, Order = 2

Ordering a 1oz Apple could result in the code "AP1-00-6" instead of the desired "AP1-6-00".  I found out what is happening is that the php function "implode" the converts the array to a string does not sort by the key, instead sorting by the order it was typed in.  What we need to do is use the php function "KSORT" just before the code is generated.

In catalog\admin\classes\shopping_cart.php
Find (about line 358):

        $products_code = $products['products_model'] . $separator . implode("/", $attribute_code_array);

Add BEFORE:

        ksort($attribute_code_array);

I've added this to the contribution update V1.2 along with some other corrections.

#54   OSC-Sevilla

OSC-Sevilla
  • Members
  • 391 posts
  • Real Name:George
  • Gender:Male
  • Location:Sevilla, Spain

Posted 13 June 2012 - 02:50 PM

Does anyone have this working ok with QT-PRO installed??????????????

admin side working ok, storing suffix, showing  OK on shopping_cart.php,

but not on roder, inovices packing slips, checkout_confirmation.php


was working before QT-PRO....
OSC 2.3.1
INSTALLED:Document Manager / Monthly Sales and Tax Returns / Batch Print Invoices / Ultimate HTML EMAILs / AJAX Attribute Manager / OSC PDF Catalog / Move Bookmarks / Sort Order / Easy Populate / Sales Reports / Low Stock Report / Admin: Model # on Category / Product Administration Screen / Mini images in admin / SLiCK reCaptcha / Google + / Beautiful Breadcrumbs / 2.3.1 - Banner Language Mod / ADD New Page / EASY MAP (google) v.3.0 / Who's Online Enhancement for 2.3.1 / Admin Notes / scrambled order number / remove_unused_images / Quantity Select / Unit Weight / Product Specifions (filter results) / AJAX Product Attributes/ Attribute Codes/ Date & Order No. to Invoice/ O.P.I. 2.0 / Attribute Images / Manual Order Editor / Attributes Clone / Order Editor / Create Order / Company VAT No. / Add customer/  CKEditor 2.3.1 / Page Manager / Default images via admin / Percentage Shipping Price / QTPro / Scroll to Top / PDF Invoice / Featured Products / Product Listing Enhancements / AutoBackups /  Ultimate SEO URLS 5 Pro / Kiss Tags/ ..Custom Admin Mods /

#55   OSC-Sevilla

OSC-Sevilla
  • Members
  • 391 posts
  • Real Name:George
  • Gender:Male
  • Location:Sevilla, Spain

Posted 25 June 2012 - 10:42 AM

View Postjemmasta, on 25 February 2008 - 03:48 AM, said:

Ok, managed to fix this. [img]http://forums.oscommerce.com/public/style_emoticons/default/smile.gif[/img]

I changed this part:
		if (is_array($this->contents[$products_id]['attributes'])) {
		while (list($option, $value) = each($this->contents[$products_id]['attributes'])) {
		  $attribute_code_query = tep_db_query("select code_suffix, suffix_sort_order from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . (int)$prid . "' and options_id = '" . (int)$option . "' and options_values_id = '" . (int)$value . "'");
		  $attribute_code = tep_db_fetch_array($attribute_code_query);
		  if (tep_not_null($attribute_code['code_suffix'])) {
			$attribute_code_array[(int)$attribute_code['suffix_sort_order']] = $attribute_code['code_suffix'];
			}
		  }

to this:

		if (is_array($this->contents[$products_id]['attributes'])) {
			$i = 0;
	   	foreach ($this->contents[$products_id]['attributes'] as $attributes){
			$option = array_keys($this->contents[$products_id]['attributes']);
			$value = $this->contents[$products_id]['attributes'];
	   		$attribute_code_query = tep_db_query("select code_suffix, suffix_sort_order from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . (int)$prid . "' and options_id = '" . (int)$option[$i] . "' and options_values_id = '" . (int)$value[$option[$i]] . "'");
		  $attribute_code = tep_db_fetch_array($attribute_code_query);
		  if (tep_not_null($attribute_code['code_suffix'])) {
			$attribute_code_array[(int)$attribute_code['suffix_sort_order']] = $attribute_code['code_suffix'];
			}
				  $i++;
		}

So changed while logic to foreach and removed the each() by fetching key values by array_keys and using those values to point to correct option values. Perhaps a bit crude, but now it works as it should've in the first place. [img]http://forums.oscommerce.com/public/style_emoticons/default/smile.gif[/img] It really seems that reusing each() within a loop that has already used each() caused this problem, at least in PHP5. This solves the problem.

BINGO!!!!!! Boom we are back in the game! NIce one!
OSC 2.3.1
INSTALLED:Document Manager / Monthly Sales and Tax Returns / Batch Print Invoices / Ultimate HTML EMAILs / AJAX Attribute Manager / OSC PDF Catalog / Move Bookmarks / Sort Order / Easy Populate / Sales Reports / Low Stock Report / Admin: Model # on Category / Product Administration Screen / Mini images in admin / SLiCK reCaptcha / Google + / Beautiful Breadcrumbs / 2.3.1 - Banner Language Mod / ADD New Page / EASY MAP (google) v.3.0 / Who's Online Enhancement for 2.3.1 / Admin Notes / scrambled order number / remove_unused_images / Quantity Select / Unit Weight / Product Specifions (filter results) / AJAX Product Attributes/ Attribute Codes/ Date & Order No. to Invoice/ O.P.I. 2.0 / Attribute Images / Manual Order Editor / Attributes Clone / Order Editor / Create Order / Company VAT No. / Add customer/  CKEditor 2.3.1 / Page Manager / Default images via admin / Percentage Shipping Price / QTPro / Scroll to Top / PDF Invoice / Featured Products / Product Listing Enhancements / AutoBackups /  Ultimate SEO URLS 5 Pro / Kiss Tags/ ..Custom Admin Mods /

#56   tunetti

tunetti
  • Members
  • 1 posts
  • Real Name:Shelly

Posted 03 March 2013 - 08:05 PM

This add on worked great for my needs. However, there are a couple things that are not working properly. When I add something to the cart, it is added to the cart but the next page that is displayed is blank as well as the checkout process.

Also, the next and previous buttons are showing IMAGE_BUTTON_PREVIOUS_PRODUCT.

Any thoughts on which page may be incorrect?