Forums / General Questions / Product ID with numbers and letters

Product ID with numbers and letters

Views: 3,768

Results 1 to 8 of 8
22 Nov 2011, 8:23 PM
#1
farmex avatar

farmex

New Zenner

Join Date:
Nov 2011
Posts:
21
Plugin Contributions:
0

Product ID with numbers and letters

Okay, to make a story little bit shorter here is the previous thread http://www.zen-cart.com/forum/showthread.php?t=188401

What I need to do is to add thousands of products to the catalog. I got manufacturers pricing spread sheets, which I can reformat to import them into the database. Here's the question... ARI(check previous thread) using SKU, in our case it should be products_id. Some of them are just numbers, but some of them are numbers and letters for expample NN10798. Is it possible to use letters and numbers in product_id field in database?
So the link would look like this
website.com/index.php?action=buy_now&products_id=NN10798

Or is there any other way the product could be added to the shopping cart without using products_id?

I would appreciate any help and suggestions.

22 Nov 2011, 9:28 PM
#2
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Product ID with numbers and letters

The product id is an auto-incrementing field in the database, and any attempt to alter it would be very risky if not impossible.

Using some other field, either existing or newly created, would be your best bet.

22 Nov 2011, 10:33 PM
#3
farmex avatar

farmex

New Zenner

Join Date:
Nov 2011
Posts:
21
Plugin Contributions:
0

Re: Product ID with numbers and letters

I've already created couple products with "custom" id and it works fine, but those were just with numbers. I'll try some with letters and numbers, to see if that's going to work. I was just wondering if there might be better options. ARI application passing link like
...buy_now&arisku=4229&arireturnurl={arireturnurl}&ariqty={aripartqty}&ariprice=139.5&aribrand=BRG&ariassemblyid=172540&ariparentassemblyid=0&aripartid=2344492

Can I create new attribute ARISKU for the product and make both links adding products to the shopping cart

for example

...buy_now&arisku=A92531GS
...buy_now&products_id=56

And they would do the same thing.

I'm not very good with MySQL , but if anyone could set the direction for where to look and what things to consider to make it work, I'd appreciate that.

23 Nov 2011, 2:24 AM
#4
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Product ID with numbers and letters

Zen Cart has a products_model field. If you populate that with the SKU number, when you're inserting all their products into your database, then you could customize the code to do add-to-cart actions based on products_model instead of products_id.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

23 Nov 2011, 5:04 PM
#5
farmex avatar

farmex

New Zenner

Join Date:
Nov 2011
Posts:
21
Plugin Contributions:
0

Re: Product ID with numbers and letters

DrByte:

Zen Cart has a products_model field. If you populate that with the SKU number, when you're inserting all their products into your database, then you could customize the code to do add-to-cart actions based on products_model instead of products_id.

Another thing is that there are about 16k parts in one of the manufacturers catalog, I got to upload around 20 of them. And I have no idea what might be the chance that some of the parts could have same sku...

But anyway, could you please tell me where do I look to change products_id to products_model

23 Nov 2011, 8:45 PM
#6
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Product ID with numbers and letters

Easy :blush:
Just add a new file, as follows:

/includes/extra_cart_actions/buy_now_by_model_number.php

<?php
/**
 * Custom shopping Cart actions
 *
 * @package initSystem
 * @copyright Copyright 2003-2011 Zen Cart Development Team
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 */
if (!defined('IS_ADMIN_FLAG')) {
  die('Illegal Access');
}

/**
 * check whether an "action" has been set. And if m= is set but no products_id is set,
 * then lookup products_id from products_model (m)
 */
if (isset($_GET['action']) && $_GET['action']=='buy_now' && isset($_GET['m']) && !isset($_GET['products_id']))
{
  $sql= "select products_id from " . TABLE_PRODUCTS . " where products_model = :themodel: LIMIT 1";
  $sql = $db->bindvars($sql, ':themodel:', $_GET['m'], 'string');
  $lookup = $db->Execute($sql);
  if ($lookup->RecordCount() == 1)
  {
    $_GET['products_id'] = $lookup->fields['products_id'];
    unset($_GET['m']);
    zen_redirect(zen_href_link($goto, zen_get_all_get_params('m')));
  }
}
```Now you can use URLs like this:
index.php?action=buy_now&m=THEMODELNUMBER

.. where THEMODELNUMBER is the case-sensitive model number assigned to your products_model field in your database's products table. (Same as the model number on the admin edit-product screen)

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

25 Nov 2011, 5:26 PM
#7
farmex avatar

farmex

New Zenner

Join Date:
Nov 2011
Posts:
21
Plugin Contributions:
0

Re: Product ID with numbers and letters

Doc, you the best! The only thing you forgot is to close php :blush:

THANK YOU!:clap:

25 Nov 2011, 6:58 PM
#8
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Product ID with numbers and letters

farmex:

Doc, you the best! The only thing you forgot is to close php :blush:Actually, that was very intentional: https://www.zen-cart.com/tutorials/index.php?article=313> farmex:

THANK YOU!:clap:You're welcome.
Happy Thanksgiving.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.