Jump to content

Need to decode a SKU with php?


Recommended Posts

Hello everyone! I maintain a e-commerce site for someone, and I would like to be able to decode a SKU number. The SKU is created in a way that it can decribe a products quality, year, etc... so a SKU like: 252AER2 would mean:

Part No: 252

Compatable With Model: 555 (a)

Power Source: 12V (e)

etc...

 

The SKU is displayed on each of the product pages. Is there a way to parse the SKU at load and decode it into a description?  I want to be able to serve up a description purely based on the SKU alone. A "plug-n-play" solution if you will.

Link to comment
https://forums.phpfreaks.com/topic/200987-need-to-decode-a-sku-with-php/
Share on other sites

There will be a definite amount of chunks. (252) (A) (E) ® (2)

 

(A) will always mean a specific value such as "555" with the words "Model No." placed behind it.

 

(A) and the others will always be a specific value, the letters will change depending on attributes so (A) = "555" always. (B) may always represent "444".

 

(2) Represents a level of quality so 2 = "Quality: Good Condition/Only Light Scratches"

(1) would represent "Quality: Like new condition / No scratches"

 

I want to input the SKU on my product, and have a script fill the description for me based off the SKU. The script will include all possible values for each section of the SKU. Currently there are 5 sections. The script will be plugged into the description box of every product without being modified. This is why it will need to grab the SKU off of the page.

 

Thanks!

Use substr to break the string into parts then use the parts to plug into arrays to get what you want.

ie.

condition(1=>'excellent condition/no scratches',2=>'Good Condition/Only Light Scratches'3=>'fair condition/moderate scratching'4=>'poor condition/heavy scratching'5=>'usless condition/looks like cat scratch fever')

echo "$condition[$part_condition]";

 

or use the $str_condition to pull from a DB.

 

 

HTH

Teamatomic

You can use a regular expression to extract it.

 

Well, as easy as it sounds, I don't know how to write a RegEx that would take my text and push it into a varable. I honestly don't know much at all about PHP in a programming sense. My programming levels are good, just not with PHP.

 

This PHP script will be placed inside the "body" of a Drupal type page. Drupal has ways of using PHP code in a description box.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.