Jump to content
Rochdalemark

Attribute Product Codes [Contribution]

Recommended Posts

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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....

Share this post


Link to post
Share on other sites

Ok, managed to fix this. smile.gif

 

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. smile.gif 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!

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×