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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

I will need to parse the page as well in order to grab the SKU as a string. How could I do this? The HTML of the loaded page is in a DIV

<div class="product-info model">SKU: 252AER2</div>

You can use a regular expression to extract it.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

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

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.