Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Attribute Product Codes [Contribution]


Guest

Recommended Posts

Hi Sean yeah that was an oversight. all you need to do is run this sql:

 

ALTER TABLE `products_attributes` ADD `suffix_sort_order` int( 11 ) NOT NULL default '0' AFTER `code_suffix`

 

Notice the only change is the default '0' instaead of default ''

 

I should realy make that change and add it to the contribution

 

worked like a champ, thank you!

 

Another question while I'm here: Is it possible to remove the slash in the final output from this contrib? I went over the install text again and it seems to me that the slash is there to let the system separate Product Sku's from Attribute Sku's when you do the final pull from the DB, but i'm not 100% sure. I'd love to remove it altogether, but I will settle for changing it to a dash (-) instead.

 

is this possible? --more importantly how easy is it? ;)

 

 

I suspect that the code that needs changing is in the "separator" area of the following code, but my store is fragile enough that I'm not willing to try in case it breaks!

 

$specials_query = tep_db_query("select specials_new_products_price from " . TABLE_SPECIALS . " where products_id = '" . (int)$prid . "' and status = '1'");
	  if (tep_db_num_rows($specials_query)) {
		$specials = tep_db_fetch_array($specials_query);
		$products_price = $specials['specials_new_products_price'];
	  }

$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);
	} else {
$products_code = $products['products_model'];
}

	  $products_array[] = array('id' => $products_id,
								'name' => $products['products_name'],
								'description' => $products['products_description'],
								'model' => $products['products_model'],
								'code' => $products_code,
								'image' => $products['products_image'],
								'price' => $products_price,
								'quantity' => $this->contents[$products_id]['qty'],
								'weight' => $products['products_weight'],
								'final_price' => ($products_price + $this->attributes_price($products_id)),
								'tax_class_id' => $products['products_tax_class_id'],
								'attributes' => (isset($this->contents[$products_id]['attributes']) ? $this->contents[$products_id]['attributes'] : ''));

 

 

Any help is most appreciated!

 

thanks

sean

Link to comment
Share on other sites

  • Replies 55
  • Created
  • Last Reply

Top Posters In This Topic

Hi Sean,

 

What caused your test site problem?

 

For anyone else that needs to change the seperators, as sean said the following is the code that you need to change to have the seperators anything you wish

 

$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);
	} else {
$products_code = $products['products_model'];

Link to comment
Share on other sites

You shouldnt have to delete any old attributes just to add this new contribution. You should just be able to edit the existing ones.

Either you have missed something in the install instructions or your other contributions are affecting this one, as you have attributes sets installed I'm not sure what that alters as I have never used it.

 

Me again, aren't you thrilled?

I used one bracelet kit as a test model. It has 12 crystal color options, 4 lengths, 2 pearl colors, 2 metal colors. I figured out that I had to delete the old attributes as the new ones do not overwrite. So, got all of the new ones in there, and it seemed to rearrange the order of display (what was Jan, Feb, Mar on the prod info page is now Mar, Jan, Feb), so I fixed that through Att Sets Plus. Put a test order through, it was missing 2 of my 4 options in the model number (only the pearl and metal colors showed up) in the emails, and no model number appears in the admin/orders page, and only the pearl and metal options are retaining the formating in the admin/prod attributes page. All of the others are now missing the code suffix and suffix order. (and before you ask, I made certain that I saved each and every one :D )

Grasshopper is confused, Master. (But that doesn't take much)

Thankyou for your time and patience

Link to comment
Share on other sites

Hi Sean,

 

What caused your test site problem?

 

For anyone else that needs to change the seperators, as sean said the following is the code that you need to change to have the seperators anything you wish

 

$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);
	} else {
$products_code = $products['products_model'];

 

 

Hi Rochdalemark,

 

I actually don't have any troubles with my test site, was just wondering about the separator.

 

How would you go about "removing" the separator altogether? It seems that it's necessary for your contribution to separate the attributes from the product's base SKU but i'm wondering if some type of regular expression replace PHP trick might work to get it out of the final output to the user, as well as to the store owner. All of her SKU's are set at the manufacturer level, and since her business has been running (offline) for so long, I would hate to have her have to change her system for this. She's willing to live with a dash instead of a slash, but is there an easy trick to get rid of it?

 

 

While I'm here: How is everyone else dealing with stock levels for specific SKU's? As far as I can tell, I can add stock levels for the "main" sku, but not for each of the sizes that I add with this contribution. Are there plans to add a stock level to this contrib in the future?

 

Thanks for a great contribution! Works like a champ.

 

Sean

Link to comment
Share on other sites

Update:

 

Well it seems that I do have a problem. My product codes (model numbers) etc are not showing up in my final invoice or packing slips. Yikes!

 

Will investigate further but if you have any thoughts on why they used to work but no longer work (now that i've added attributes to each product in my inventory) maybe when I return to my desk you will have suggested a good starting point to figure it out!

 

this is a useless post I guess. sorry. will update in a few hrs.

 

sean

Link to comment
Share on other sites

Hi Sean,

 

to remove the seperators just change the following

 

$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);
	} else {
$products_code = $products['products_model'];

 

to

 

$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);
	} else {
$products_code = $products['products_model'];

 

That should work I think.

 

As far as stocking levels go, I have no plans as yet to add this as I dont need it in my store but if you want to try and add it to the contribution then please be my guest :P

 

Hi Rochdalemark,

 

I actually don't have any troubles with my test site, was just wondering about the separator.

 

How would you go about "removing" the separator altogether? It seems that it's necessary for your contribution to separate the attributes from the product's base SKU but i'm wondering if some type of regular expression replace PHP trick might work to get it out of the final output to the user, as well as to the store owner. All of her SKU's are set at the manufacturer level, and since her business has been running (offline) for so long, I would hate to have her have to change her system for this. She's willing to live with a dash instead of a slash, but is there an easy trick to get rid of it?

While I'm here: How is everyone else dealing with stock levels for specific SKU's? As far as I can tell, I can add stock levels for the "main" sku, but not for each of the sizes that I add with this contribution. Are there plans to add a stock level to this contrib in the future?

 

Thanks for a great contribution! Works like a champ.

 

Sean

Link to comment
Share on other sites

Hi again Sean :P

 

Check the install instructions again, make sure you have completed the following.

 

********** In catalog/admin/packingslip.php *****************

 

Find: around line 109

 

echo '		</td>' . "\n" .
	   '		<td class="dataTableContent" valign="top">' . $order->products[$i]['model'] . '</td>' . "\n" .
	   '	  </tr>' . "\n";



Change To:

echo '		</td>' . "\n" .
	   '		<td class="dataTableContent" valign="top">' . $order->products[$i]['code'] . '</td>' . "\n" .
	   '	  </tr>' . "\n";

 

********** In catalog/admin/invoice.php *****************

 

Find: around line 116

 

echo '		</td>' . "\n" .
	   '		<td class="dataTableContent" valign="top">' . $order->products[$i]['model'] . '</td>' . "\n";



Change to:

echo '		</td>' . "\n" .
	   '		<td class="dataTableContent" valign="top">' . $order->products[$i]['code'] . '</td>' . "\n";

 

Hope that helps

 

Update:

 

Well it seems that I do have a problem. My product codes (model numbers) etc are not showing up in my final invoice or packing slips. Yikes!

 

Will investigate further but if you have any thoughts on why they used to work but no longer work (now that i've added attributes to each product in my inventory) maybe when I return to my desk you will have suggested a good starting point to figure it out!

 

this is a useless post I guess. sorry. will update in a few hrs.

 

sean

Edited by Rochdalemark
Link to comment
Share on other sites

Yup that's all there but while going over the install instructions again we noticed this:

 

#############################################################
**********   In catalog/admin/includes/classes/order.php  *****************

Find: around line 80

$orders_products_query = tep_db_query("select orders_products_id, products_name, products_model, products_price, products_tax, products_quantity, final_price from " . TABLE_ORDERS_PRODUCTS . " where orders_id = '" . (int)$order_id . "'");
     while ($orders_products = tep_db_fetch_array($orders_products_query)) {
       $this->products[$index] = array('qty' => $orders_products['products_quantity'],
                                       'name' => $orders_products['products_name'],
                                       'model' => $orders_products['products_model'],
                                       'tax' => $orders_products['products_tax'],
                                       'price' => $orders_products['products_price'],
                                       'final_price' => $orders_products['final_price']);



Change to:


$orders_products_query = tep_db_query("select orders_products_id, products_name, products_model, products_price, products_tax, products_quantity, final_price from " . TABLE_ORDERS_PRODUCTS . " where orders_id = '" . (int)$order_id . "'");
     while ($orders_products = tep_db_fetch_array($orders_products_query)) {
       $this->products[$index] = array('qty' => $orders_products['products_quantity'],
                                       'name' => $orders_products['products_name'],
                                       'model' => $orders_products['products_model'],
                                       'code' => $orders_products['products_code'],
                                       'tax' => $orders_products['products_tax'],
                                       'price' => $orders_products['products_price'],
                                       'final_price' => $orders_products['final_price']);

 

 

 

 

There is no "products_code" statement in the initial query, but there is in the subsequent array. We added it into the query as such:

 

$orders_products_query = tep_db_query("select orders_products_id, products_name, products_model, products_code,  products_price, products_tax, products_quantity, final_price from " . TABLE_ORDERS_PRODUCTS . " where orders_id = '" . (int)$order_id . "'");
     while ($orders_products = tep_db_fetch_array($orders_products_query)) {
       $this->products[$index] = array('qty' => $orders_products['products_quantity'],
                                       'name' => $orders_products['products_name'],
                                       'model' => $orders_products['products_model'],
                                       'code' => $orders_products['products_code'],
                                       'tax' => $orders_products['products_tax'],
                                       'price' => $orders_products['products_price'],
                                       'final_price' => $orders_products['final_price']);

 

 

But unfortunately it hasn't helped yet.

 

We've also found that while my orders_products_attributes table has a "code_suffix" column, there are no code suffixes that have actually made it in there. We're looking for that insert statement now. Just wanted to give an update on the above sql statement while I was still thinking of it.

 

Sean

Link to comment
Share on other sites

Yup that's all there but while going over the install instructions again we noticed this:

 

#############################################################
**********   In catalog/admin/includes/classes/order.php  *****************

Find: around line 80

$orders_products_query = tep_db_query("select orders_products_id, products_name, products_model, products_price, products_tax, products_quantity, final_price from " . TABLE_ORDERS_PRODUCTS . " where orders_id = '" . (int)$order_id . "'");
     while ($orders_products = tep_db_fetch_array($orders_products_query)) {
       $this->products[$index] = array('qty' => $orders_products['products_quantity'],
                                       'name' => $orders_products['products_name'],
                                       'model' => $orders_products['products_model'],
                                       'tax' => $orders_products['products_tax'],
                                       'price' => $orders_products['products_price'],
                                       'final_price' => $orders_products['final_price']);



Change to:


$orders_products_query = tep_db_query("select orders_products_id, products_name, products_model, products_price, products_tax, products_quantity, final_price from " . TABLE_ORDERS_PRODUCTS . " where orders_id = '" . (int)$order_id . "'");
     while ($orders_products = tep_db_fetch_array($orders_products_query)) {
       $this->products[$index] = array('qty' => $orders_products['products_quantity'],
                                       'name' => $orders_products['products_name'],
                                       'model' => $orders_products['products_model'],
                                       'code' => $orders_products['products_code'],
                                       'tax' => $orders_products['products_tax'],
                                       'price' => $orders_products['products_price'],
                                       'final_price' => $orders_products['final_price']);

 

 

 

 

There is no "products_code" statement in the initial query, but there is in the subsequent array. We added it into the query as such:

 

$orders_products_query = tep_db_query("select orders_products_id, products_name, products_model, products_code,  products_price, products_tax, products_quantity, final_price from " . TABLE_ORDERS_PRODUCTS . " where orders_id = '" . (int)$order_id . "'");
     while ($orders_products = tep_db_fetch_array($orders_products_query)) {
       $this->products[$index] = array('qty' => $orders_products['products_quantity'],
                                       'name' => $orders_products['products_name'],
                                       'model' => $orders_products['products_model'],
                                       'code' => $orders_products['products_code'],
                                       'tax' => $orders_products['products_tax'],
                                       'price' => $orders_products['products_price'],
                                       'final_price' => $orders_products['final_price']);

 

 

But unfortunately it hasn't helped yet.

 

We've also found that while my orders_products_attributes table has a "code_suffix" column, there are no code suffixes that have actually made it in there. We're looking for that insert statement now. Just wanted to give an update on the above sql statement while I was still thinking of it.

 

Sean

Link to comment
Share on other sites

Sorry for the double post - the Net is dodgy here today.

 

For the record, the above solution fixed my problem 100%, I was mistaken and had edited it in the open instructions file, and not the actual PHP! LOL too funny.

 

 

The code_suffix still does not populate or seem to get used at all in the orders_products_attributes table. --and it doesn't seem to matter?

 

I don't see why I would need to understand that, but I'm dying to know why. ;)

 

Thanks

sean

Link to comment
Share on other sites

No worries, glad I could help and that the contribution is of some use to you.

 

It's worth pointing out that the suggested code above to remove the separating slash in the final output works perfectly.

 

thanks, Rochdalemark - great work.

Link to comment
Share on other sites

No worries, glad I could help and that the contribution is of some use to you.

 

 

It's definitely worth a lot more than "some use" to me! w/o this contrib, I just might have lost a client as well as a couple of weeks' development! Great stuff.

 

BTW you might want to re-check your SQL since there doesn't seem to be a need for the suffix field in the orders_products_attributes table, since it's never been populated on mine. perhaps you had to do that on yours due to a different contribution you're using?

 

thanks again

Link to comment
Share on other sites

  • 7 months later...

Hi

Will this contrib be able to make an exact sales report?

No other salesreport have been able to separate between sold products with attributes, only products.

 

And

 

Have anyone installed it with ajax attribute manager?

Link to comment
Share on other sites

  • 1 month later...

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

Link to comment
Share on other sites

  • 3 weeks later...

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

Link to comment
Share on other sites

  • 1 month later...
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().

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Ok, found the following:

 

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

 

and

 

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?

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

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