marty.net 1001 Postcards Love Love Love Meep Meep ZenZodiac DailyQuotation

YOU ARE HERE:
Product Type Numbers String = "Product Typ" output

HOME

CPSHOP|

|

|

EMAIL MARTY
  marty.net message board
  « Product Type Numbers String = "Product Typ" output »
Welcome, Guest. Please Login or Register.
12/16/17 at 08:59:14
Home Help Search Login Register
   marty.net message board
   About cpshop
   Feature Requests
   Product Type Numbers String = "Product Typ" output
(Moderator: Marty)
Pages: 1 2 3 4 5 6 » Reply Notify of replies Send the topic Print 
   Author  Topic: Product Type Numbers String = "Product Typ" output  (Read 9362 times)
brattytees
Gold Dragon
****

Posts: 439



ack!
   

Product Type Numbers String = "Product Typ" output
« on: 01/07/11 at 19:54:17 »
Reply with quote Modify message

Would there be an easy way to take a group of (or individual) product type numbers - for example all products that CP has named "t-shirt" - and output the word "t-shirt", maybe as a tag, for use in the Product page template?

As another thought, I was looking at how the sortorder text files are setup. Would it be possible to do something like that where we could input the type number string and output the text we wanted? I'm not sure how we would specify where to use the text in that scenario though. Option 1 makes more sense, option 2 I was trying to make less work for Marty and put more on us.
Logged
brattytees
Gold Dragon
****

Posts: 439



ack!
   

Re: Product Type Numbers String = "Product Typ" ou
« Reply #1 on: 01/12/11 at 19:42:06 »
Reply with quote Modify message

So I'm brain dead and that functionality is partially there using hooks. I have to try something.
« Last Edit: 01/12/11 at 19:55:02 by brattytees » Logged
brattytees
Gold Dragon
****

Posts: 439



ack!
   

Re: Product Type Numbers String = "Product Typ" ou
« Reply #2 on: 01/12/11 at 21:00:46 »
Reply with quote Modify message

What about creating an "all" producttype hook like

cpshop.cgi.type.all.hookname.txt

and being able to format it like we can with sortorder files like

<if 4,23,103,128,244,245,246,247,249>Hoodies and Sweatshirts
<if 15,80,295,296>Underwear
etc...

Or if not that then the next best thing would be the ability to string several type #s together like

cpshop.cgi.type.5,80,295,296.hookname.txt
Logged
Hex Angel - Patrick
Gold Dragon
****

Posts: 500



Our nature lies in movement; complete calm is death.
   

WWW
Re: Product Type Numbers String = "Product Typ" ou
« Reply #3 on: 12/05/11 at 11:18:20 »
Reply with quote Modify message

For other purposes, I created a hash table of product information in cpshop.cgi. It could also serve this function.

I originally created it after you got me thinking about ways to repair truncated product names, even the gnarly ones like 'Holy Roller Women's Plus Size Scoop Nec' which could be either dark, or not dark.

It's turned out to be rather useful, and is also serving up google pagemap data for refinement labels so the (not-yet-released) google Custom Search Engine will have a series of tabs to filter for section and product thumbnail pages, product detail pages, men's wear, hats and bags, greeting cards, wall art, etc.
Logged

CPSHOP
www.PeaceAndLoveShop.com Namaste
BLOG
www.TheNomadicSpirit.com Inspired by travel
www.GodBeautyPerfectionLove.com Inspired by spirit
www.MyMuseMoviesMusicAndBooks.com Inspired by the arts
brattytees
Gold Dragon
****

Posts: 439



ack!
   

Re: Product Type Numbers String = "Product Typ" ou
« Reply #4 on: 12/05/11 at 16:59:29 »
Reply with quote Modify message

Yeah, I've since hacked at it and came up with what I wanted for the above. I wish I could shorten up the code, but sometimes when I start trying to do shorthand in perl it gets ugly so I leave it with what works even though there may be a better way. And thanks for bringing this up because I had forgotten to add the pjs and mens tanks to my list.

I also thought I had fixed all the gnarly truncated names like Holy Roller Women's Plus Size Scoop Nec but I just ran across one variation I somehow missed. Thanks for bringing that up too.

I'd be curious to see what your doing with the hash table if your up to sharing. I'm sure it's prettier than some of my hacks.  
Logged
Hex Angel - Patrick
Gold Dragon
****

Posts: 500



Our nature lies in movement; complete calm is death.
   

WWW
Re: Product Type Numbers String = "Product Typ" ou
« Reply #5 on: 12/05/11 at 22:22:34 »
Reply with quote Modify message

lol

sure, I'm in a giving mood.  

'Peace Love Life Harmony Women's Plus Size Scoop Ne' is missing several important keywords that could be appearing in several places on several pages.  You really want them all. And you want to move the (dark) out of the parentheses and into someplace that makes sense, 'Scoop Neck Dark T-Shirt' works fine for me.

You need to create a hash table like the one below and put it inside your cpshop.cgi, or in a separate .lib file that you load into the .cgi, somewhere before you need the data (but not inside a subroutine).


Code:
%product_names = (
 '152' => { 'target' => 'Dark T', 'replace' => 'Men\'s Dark T-Shirt' },
 '251' => { 'target' => 'Organic Me', 'replace' => 'Organic Men\'s Dark T-Shirt' },             
.
.
.
 '122' => { 'target' => '2.25" Ma', 'replace' => '2.25 Inch Magnets ~ Pack of 10' },
 '138' => { 'target' => 'Rectangle Ma', 'replace' => 'Rectangle Magnets ~ Pack of 10' }
);


There are a lot of rows in the space '...' but you get the gist. Leftmost is the <[producttypeno]> -- we'll use 'target' and 'replace' to repair/replace broken/ugly CP product identifier strings. The idea is, if you know the product type for a name string you've been given, you can find a fairly short target string in it, and thus know which portion of the string to replace with your new, unbroken and improved product identifier string.

So, any place you can put the cpshop tags <[productname]> and <[producttypeno]> you can repair/replace the product name. Here's how.  Replace every occurrence of <[productname]> in your templates and cpadmin product thumbnail cells with this:


Code:
<|clean_product:<[productname]>|<[producttypeno]>|>



Now, just before the end of your cpshop.cgi file, just before the '1;' that appears at the very end, insert this code:


Code:
# replace an ugly and possibly broken product name string with a beautiful, SEO-pure one
sub clean_product_name {
       my $hash_ref = $_[0];
     my $productname = $_[1];
     my $producttypeno = $_[2];
     my $before = $_[3];
     my $after = $_[4];
     
        my %product_names = %$hash_ref;
     
     if (defined $product_names{ $producttypeno })
     {
         $productname =~ s/^(.*)$product_names{$producttypeno}->{'target'}.*?$/$1$product_names{$producttypeno}->{'replace'}/; # this is one line of code
     }

     if (defined $after) { $productname = $productname . $after; }
     if (defined $before) { $productname = $before . $productname; }

     return $productname;
}


Now, here's the tricky trippy part ... we're going to run this function inside a string replacement statement like this:


Code:
$content =~ s/<\|clean_product:(.*?)\|(.*?)\|>/@{[clean_product_name(\%product_names,$1,$2,"","")]}/sgi; # careful, this is all one line!


And, voila! -- that's the line I use to repair all the product name strings in a product thumbnail file.  All that etra gobbledygook in the replacement portion says:whenever you find that funny-looking string, pull out the productname and producttypeno, send it to clean_product_name along with the hash table, and replace the gobbledygook with the result.

You can use this method to clean the product names appearing in titles and breadcrumbs of detail pages as well. The $before and $after parameters for subroutine clear_product_names are useful for replacing the <span ...> and </span> tags in the breadcrumb after you've stripped them to find the product name. That one looks like this, with $1 and $3 restoring the spans:


Code:
$breadcrumb =~ s/(.*?<span class=\"cpshopbreadcrumbtext\">)(.*)(<\/span>.*$)/@{[clean_product_name(\%product_names,$2,$producttypeno,$1,$3)]}/si;  # careful, this is all one line!


Careful.... that's all one line.

Merry Holiday Bonanza fellow shopkeepers!
« Last Edit: 12/14/11 at 18:27:54 by Hex Angel - Patrick » Logged

CPSHOP
www.PeaceAndLoveShop.com Namaste
BLOG
www.TheNomadicSpirit.com Inspired by travel
www.GodBeautyPerfectionLove.com Inspired by spirit
www.MyMuseMoviesMusicAndBooks.com Inspired by the arts
brattytees
Gold Dragon
****

Posts: 439



ack!
   

Re: Product Type Numbers String = "Product Typ" ou
« Reply #6 on: 12/06/11 at 21:35:00 »
Reply with quote Modify message

Hmm, thanks for sharing, looks interesting. I'll have to find time to play with it. I've been using regex to fix truncated product names and change 'T-shirt (dark)' to 'Dark T-shirt', etc, but every now and then I get hung up on one that won't change. Like I said I thought I had them all covered, but the Dark Women's Plus tees are refusing to change, in particular the '...Scoop Neck Dar' on the thumbnail page, but the V-Neck of the same description seems to be fine and goes out all the way to '...Dark T-shirt'. And then I have a fight with those same items on the product pages where they all (dark and light) either want to be Dark, or Not. I tried every combo I could think of and nothing works. And then the page title and the breadcrumb refuse to change for them too. I don't know what it is about those, but I'm about out of my mind and ready to say f it to those 4 items until I can find time to play with your way. I made some changes today and now I need to go back and make sure something else didn't break, outside of those 4 shirts.
Logged
Hex Angel - Patrick
Gold Dragon
****

Posts: 500



Our nature lies in movement; complete calm is death.
   

WWW
Re: Product Type Numbers String = "Product Typ" ou
« Reply #7 on: 12/07/11 at 00:09:57 »
Reply with quote Modify message

yah -- I hear ya.

I've long been frustrated by the dang truncated product name identifiers. If you're blindly going through a list of text, or a list of known product names, or even just a single product name, and find 'Women's Plus Size Scoop Ne' you're hooped, because you don't know if it's light or dark, unless you know the producttypeno and use it to lookup what *should* be there.

I'm pretty sure a method which uses the producttypeno as a key into a small db, like I've outlined above, is the *only* way to reliably get them all. And it's pretty efficient, actually, aside from the humongous hash table.

Since you only sell a limited selection of t-shirt styles, your hash table will be much smaller than mine. And that method will resolve all those finicky issues you've run into... guaranteed.
Logged

CPSHOP
www.PeaceAndLoveShop.com Namaste
BLOG
www.TheNomadicSpirit.com Inspired by travel
www.GodBeautyPerfectionLove.com Inspired by spirit
www.MyMuseMoviesMusicAndBooks.com Inspired by the arts
brattytees
Gold Dragon
****

Posts: 439



ack!
   

Re: Product Type Numbers String = "Product Typ" ou
« Reply #8 on: 12/07/11 at 14:05:30 »
Reply with quote Modify message

Ok, two questions:

1. So I'm used to regex where you have to do (Men|Me|M). If you have say 'target' => 'Organic Me', 'replace' => 'Organic Men\'s Dark T-Shirt', how does it also know to replace the string 'Organic Men'? Or if you have 'target' => 'Dark T', 'replace' => 'Men\'s Dark T-Shirt', how does it not replace Women's Dark T with Women's Men's Dark T-shirt?

2. I see how it replaces things on the thumbnail page and can also in the breadcrumb and title, but I don't see how/where it replaces the main product name on the product page, the bit to the right of the product image right above the product description and price.

After I look at it more I may figure out the answers to both questions, but it's still early and I'm only on coffee #1 and my brain is still pounding on my head after an entire day of some pretty intense regex yesterday.

ETA - Nevermind the second part of #1, it's using the product type # to differentiate between Men's and Women's. See, more coffee = good.

ETA2 - I just noticed the .*?$ part, so that answers the first part of #1.
« Last Edit: 12/07/11 at 21:17:39 by brattytees » Logged
brattytees
Gold Dragon
****

Posts: 439



ack!
   

Re: Product Type Numbers String = "Product Typ" ou
« Reply #9 on: 12/07/11 at 17:35:11 »
Reply with quote Modify message

Ok, playing around with this I have two observations so far.

1. I changed this one
'184' => { 'target' => 'Neck Dar', 'replace' => 'Neck Dark T-shirt' }, #Plus Size Scoop
It worked fine, but it also truncated two of the other Plus tees that had not been truncated (they had actually responded to my previous regex and were fine). Maybe a regex/hash table conflict? I'll mess with it.

2. In the page source the Alt and Title tags are still truncated.

Ok, maybe 3 observations, It did fix the description on the product page also, although I'm still not sure how, but the Title and Meta Desc are still truncated.

So far most of that is an improvement.

ETA - It didn't fix the product page descriptions, that was my regex. I just killed all my regex (except (dark) to Dark) to make sure there weren't any conflicts and now the product pages are truncated again.
« Last Edit: 12/07/11 at 19:23:04 by brattytees » Logged
Hex Angel - Patrick
Gold Dragon
****

Posts: 500



Our nature lies in movement; complete calm is death.
   

WWW
Re: Product Type Numbers String = "Product Typ" ou
« Reply #10 on: 12/08/11 at 02:45:54 »
Reply with quote Modify message


on 12/07/11 at 14:05:30, brattytees wrote:
1. So I'm used to regex where you have to do (Men|Me|M).


[grin] yes, and it's not very efficient... I was well into coding this when the eureka moment hit: if you have the product number, you know what the product identifying string is supposed to look like.  It's not necessary to test for all possible truncations.


Quote:
2. I see how it replaces things on the thumbnail page and can also in the breadcrumb and title, but I don't see how/where it replaces the main product name on the product page, the bit to the right of the product image right above the product description and price.


I'm wondering if you haven't already figured this out too...:


Code:
<!-- Product Name/Caption
<div id="productCaption" class="pageTitle head"><h1Peace Love Life Harmony Men's Dark Sweats</h1></div>


You just need to write an eplicit regex to repair the stuff between <h1> and </h1> =)


Code:
$content =~ s/(<div id\=\"productCaption\" class\=\"pageTitle head\"><h1>)(.*?)(<\/h1>)/@{[clean_product_name(\%product_names,$2,$producttypeno,$1,$3)]}/si; # product detail title


That's what mine looks like.
« Last Edit: 12/08/11 at 02:54:04 by Hex Angel - Patrick » Logged

CPSHOP
www.PeaceAndLoveShop.com Namaste
BLOG
www.TheNomadicSpirit.com Inspired by travel
www.GodBeautyPerfectionLove.com Inspired by spirit
www.MyMuseMoviesMusicAndBooks.com Inspired by the arts
Hex Angel - Patrick
Gold Dragon
****

Posts: 500



Our nature lies in movement; complete calm is death.
   

WWW
Re: Product Type Numbers String = "Product Typ" ou
« Reply #11 on: 12/08/11 at 03:03:36 »
Reply with quote Modify message



on 12/07/11 at 17:35:11, brattytees wrote:
1. I changed this one
'184' => { 'target' => 'Neck Dar', 'replace' => 'Neck Dark T-shirt' }, #Plus Size Scoop
It worked fine, but it also truncated two of the other Plus tees that had not been truncated (they had actually responded to my previous regex and were fine). Maybe a regex/hash table conflict? I'll mess with it.


Hmmmm....strange. The way this is coded, that entry in the hash table should only be invoked on prodtype 184. If it's affecting other product types, then something's awry in the code that invokes it.


Quote:
2. In the page source the Alt and Title tags are still truncated.


Could you post relevant sections from your templates and page source?


Quote:
So far most of that is an improvement.


YAY! =0)

Logged

CPSHOP
www.PeaceAndLoveShop.com Namaste
BLOG
www.TheNomadicSpirit.com Inspired by travel
www.GodBeautyPerfectionLove.com Inspired by spirit
www.MyMuseMoviesMusicAndBooks.com Inspired by the arts
Hex Angel - Patrick
Gold Dragon
****

Posts: 500



Our nature lies in movement; complete calm is death.
   

WWW
Re: Product Type Numbers String = "Product Typ" ou
« Reply #12 on: 12/08/11 at 03:07:02 »
Reply with quote Modify message



on 01/07/11 at 19:54:17, brattytees wrote:
Would there be an easy way to take a group of (or individual) product type numbers - for example all products that CP has named "t-shirt" - and output the word "t-shirt", maybe as a tag, for use in the Product page template?


You realise, of course, the hash table you've created can be etended to perform this function.

It's great when you start one process, believe you've gone off on a tanget to another one, then realise, all along, you were solving the original problem. =)
Logged

CPSHOP
www.PeaceAndLoveShop.com Namaste
BLOG
www.TheNomadicSpirit.com Inspired by travel
www.GodBeautyPerfectionLove.com Inspired by spirit
www.MyMuseMoviesMusicAndBooks.com Inspired by the arts
brattytees
Gold Dragon
****

Posts: 439



ack!
   

Re: Product Type Numbers String = "Product Typ" ou
« Reply #13 on: 12/08/11 at 17:12:25 »
Reply with quote Modify message

Let's address this first.

Quote:
Hmmmm....strange. The way this is coded, that entry in the hash table should only be invoked on prodtype 184. If it's affecting other product types, then something's awry in the code that invokes it.

Yeah, it's weird, haven't figured it out yet.



Quote:
Could you post relevant sections from your templates and page source?

Thumbnail grid

Code:
<div class="thmbgridcellcontainer">
     <div><[linkstarts]><[thumbnail]><[linkends]></div>
     <img src="/img/swatches/type-<[producttypeno]>.png" width=150 height=15 border=0 alt="color swatch" style="margin: 2px 0;">
     <div class="thumbpagelink"><[linkstarts]><|clean_product:<[productname]>|<[producttypeno]>|><[linkends]><br>
     <[productcost]></div>
</div>


Page source snippet

Code:
<div class="thmbgridcellcontainer">
     <div><a href="http://www.brattytees.com/cgi-bin/store/holiday-tees.cgi/ive_been_naughty_spank_me/naughty_spankme.491756581"><img border="0" height="150" oldwidth="150" src="http://images1.cpcache.com/product/491756581v4_150x150_Front_Color-Black.jpg" alt="Naughty, Spank Me Women's Plus Size Scoop Neck Dar" title="Naughty, Spank Me Women's Plus Size Scoop Neck Dar"></a></div>
     <img src="/img/swatches/type-184.png" width=150 height=15 border=0 alt="color swatch" style="margin: 2px 0;">
     <div class="thumbpagelink"><a href="http://www.brattytees.com/cgi-bin/store/holiday-tees.cgi/ive_been_naughty_spank_me/naughty_spankme.491756581">Naughty, Spank Me Women's Plus Size Scoop Neck Dark T-Shirt</a><br>
     $30.99</div>
</div>


ETA - I just now thought of something, I'm running your code (and some of my hacks) out of a lib file and that could be the cause of some things not changing...wait, no, the lib file is linked to cpdata but not cppage so that shouldn't be the issue right here. I need to think about this.
« Last Edit: 12/08/11 at 17:20:33 by brattytees » Logged
Hex Angel - Patrick
Gold Dragon
****

Posts: 500



Our nature lies in movement; complete calm is death.
   

WWW
Re: Product Type Numbers String = "Product Typ" ou
« Reply #14 on: 12/08/11 at 17:33:53 »
Reply with quote Modify message

Have you tried tossing a die in sub clean_product_name ? Something like this inside the decision statement.


Code:
my $temp = $productname;

$productname =~ s/^(.*)$product_names{$producttypeno}->{'target'}.*?$/$1$product_names{$producttypeno}->{'replace'}/; # this is one line of code

if ( $producttypeno eq "184" ) {
die ' before ' . $temp . '  after ' . $productname;
}


That should tell us whether the code's ever being called corrrectly, and perhaps why it's not doing what we expect.
« Last Edit: 12/08/11 at 17:35:13 by Hex Angel - Patrick » Logged

CPSHOP
www.PeaceAndLoveShop.com Namaste
BLOG
www.TheNomadicSpirit.com Inspired by travel
www.GodBeautyPerfectionLove.com Inspired by spirit
www.MyMuseMoviesMusicAndBooks.com Inspired by the arts
Pages: 1 2 3 4 5 6 » Reply Notify of replies Send the topic Print 
Jump to:


marty.net message board (http://www.marty.net/cgi/marty/board/messageboard)

Powered by YaBB 1 Gold - Release (Yet Another Bulletin Board)
Copyright 2000-2001, X-Null. All Rights Reserved.