Jump to content

Possible to Set a Default Google Category?


Dirty Butter

Recommended Posts

Almost all of our products fall in the Toys & Games>Toys>Dolls, Playsets &Toy Figures>Stuffed Animals. Most o those that don't are dolls, and that category is not far from the Stuffed Animals category.

 

So.... would it be possible to have that Category filled in by default, with the option of course to change it if necessary? I'm guessing it's a matter of putting a default value in the _inventory table instead of NULL. But I don't want to stop being able to choose from the whole list.

Link to comment
Share on other sites

In the admin template file products.index.php, find this near line 170:

{foreach from=$GOOGLE_CATS item=cat}<option value="{$cat}" {if $cat==$PRODUCT.google_category && !empty($PRODUCT.google_category)}selected="selected"{/if}>{$cat}</option>{/foreach}

Let's look at just this part:

{if $cat==$PRODUCT.google_category && !empty($PRODUCT.google_category)}selected="selected"{/if}

If the product already has a google_category, then make that option selected. We need to add the {else} part. After "selected", add just this:

{elseif $cat=="Toys & Games>Toys>Dolls, Playsets & Toy Figures>Stuffed Animals"}selected="selected"

Make sure your specific google_category is spelled correctly!

 

This is the quick-n-dirty solution. A more flexible solution is to add an admin-settable choice (on the Store Settings, Stock tab?) which will serve as the default.

Link to comment
Share on other sites

Make sure your specific google_category is spelled correct

Just to emphasize, it's not just spelling, but spacing that has to be perfect, or it won't work. I tried typing it in, and it did not work. Copied it straight from a correct cpanel _inventory entry, and voila there it was, already filled in for me.

Link to comment
Share on other sites

The quick n dirty way doesn't work properly when the category is NOT the default. Each time I Save & Reload while I'm creating the listing - it changes back to the default. I tried making the last change to the Google category, but it won't "stick" as a Doll, instead reverts to Stuffed Animal on Save.

Link to comment
Share on other sites

{if $GOOGLE_CATS}
	  	<select name="google_category" id="google_category" class="textbox" style="font-size: 10px;">
		<option value="">{$LANG.common.please_select} &hellip;</option>
		  {foreach from=$GOOGLE_CATS item=cat}<option value="{$cat}" {if $cat==$PRODUCT.google_category && !empty($PRODUCT.google_category)}selected="selected"{elseif $cat=="Toys & Games > Toys > Dolls, Playsets & Toy Figures > Stuffed Animals"}selected="selected"{/if}>{$cat}</option>{/foreach}
		</select>
	  {else}
	  <input name="google_category" id="google_category" class="textbox" type="text" value="{$PRODUCT.google_category}" maxlength="250" />
	  {/if}

The database DOES show the correct choice, but only if a Save or Save&Reload is performed. At that point the Product listing in Admin shows the Default again.

Link to comment
Share on other sites

Interesting.

 

Please try this:

  <option value="{$cat}"
  {if $cat == $PRODUCT.google_category && !empty($PRODUCT.google_category)}selected="selected"
  {elseif $cat == "Toys & Games > Toys > Dolls, Playsets & Toy Figures > Stuffed Animals"}selected="selected"
  {/if}>{$cat}</option>
The only difference is that there are spaces on either side of the double equals signs. (Smarty syntax requirement.)
Link to comment
Share on other sites

Let's do this:

  <option value="{$cat}"
  {if $cat == $PRODUCT.google_category && !empty($PRODUCT.google_category)}selected="selected"
  {elseif empty($PRODUCT.google_category) && $cat == "Toys & Games > Toys > Dolls, Playsets & Toy Figures > Stuffed Animals"}selected="selected"
  {/if}>{$cat}</option>

The change here is that if there is no current google_cat assigned to the product (empty($PRODUCT.google_category)) and also, if while working through the list, we happen upon the default google_cat, then make this option selected.

 

Prior to this, the option list was getting two options selected:

  • the product's actual google_cat (when iterating through the list got to this item):
    if $cat == $PRODUCT.google_category
  • and always the default (when iterating through the list got to this item):
    elseif $cat == "Toys & Games > Toys > Dolls, Playsets & Toy Figures > Stuffed Animals"

Thus, with two list options selected, the browser will always show the first selected (or last, depending on the browser).

 

Working through the google list, we are looking at only one item at a time, and for each item, it will match either the first, the second, or neither.

 

Earlier, the attempt was to code for $cat to be more than one thing at the same iteration.

Link to comment
Share on other sites

I think I've lost track of what to change and what to leave as is. The page loads without Debug warning of issues, but the drop down box has no google choices. It's a black box just a few pixels wide.

{if $GOOGLE_CATS}
	  	<select name="google_category" id="google_category" class="textbox" style="font-size: 10px;">
<option value="{$cat}"
  {if $cat == $PRODUCT.google_category && !empty($PRODUCT.google_category)}selected="selected"
  {elseif empty($PRODUCT.google_category) && $cat == "Toys & Games > Toys > Dolls, Playsets & Toy Figures > Stuffed Animals"}selected="selected"
  {/if}>{$cat}</option>
</select>
	  {else}
	  <input name="google_category" id="google_category" class="textbox" type="text" value="{$PRODUCT.google_category}" maxlength="250" />
	  {/if}
Link to comment
Share on other sites

Here's the complete chunk of code:

        <div><label for="google_cat_code">{$LANG.catalogue.product_google_category}</label><span>
        {if $GOOGLE_CATS}
        <select name="google_category" id="google_category" class="textbox" style="font-size: 10px;">
            <option value="">{$LANG.common.please_select} &hellip;</option>
            {foreach from=$GOOGLE_CATS item=cat}
            <option value="{$cat}"
                {if $cat == $PRODUCT.google_category && !empty($PRODUCT.google_category)}selected="selected"
                {elseif empty($PRODUCT.google_category) && $cat == "Toys & Games > Toys > Dolls, Playsets & Toy Figures > Stuffed Animals"}selected="selected"
                {/if}>{$cat}</option>
            {/foreach}
        </select>
        {else}
        <input name="google_category" id="google_category" class="textbox" type="text" value="{$PRODUCT.google_category}" maxlength="250" />
        {/if}
        </span></div>
Double check the spelling!
Link to comment
Share on other sites

As far as I can tell, it's working properly. The database is correct, the chosen non-default category shows properly, and a new product shows the default category properly. It looks like you've done it!!!

 

So, if CC wanted to incorporate this, they would do something like create a Smarty expression for the chosen default, with an Admin place in Store Settings to designate the default?

Link to comment
Share on other sites

"Create a Smarty expression for the chosen default, with an Admin place in Store Settings to designate the default?"

 

Correct.

 

However, I would expect them to take the opportunity to "manage" this list from Google.

 

It would be extremely easy to convert this string (really, really, really long string) into an xml file, only display the top levels in one drop-down, then ajax for the child levels.

 

As each level is chosen, the "breadcrumbs", or "path" would be built up and displayed in the text field. The text field would display the existing/default choice when the highest level drop-down says "Please Select".

 

I wish to draw Devellion's attention to this:

http://www.celebird.com/news/pr-celebird-taxonomy-app.html

Link to comment
Share on other sites

 

It would be extremely easy to convert this string (really, really, really long string) into an xml file, only display the top levels in one drop-down, then ajax for the child levels.

 

As each level is chosen, the "breadcrumbs", or "path" would be built up and displayed in the text field. The text field would display the existing/default choice when the highest level drop-down says "Please Select".

 

This is EXACTLY the way Google used to do it themselves. It was SO much easier to use that way. Now you have to download the xml file from Google and search for what you need, if done from the Google site.

Link to comment
Share on other sites

  • 7 months later...
  • 1 year later...

Take a note of the Google category you have as default. Be extremely careful of the exact spelling and spaces.

In admin, Maintenance, Query Database tab, look above the Query box. If there is a mention of a database table prefix pre_, be sure to use it as follows. Otherwise do not use the pre_:

In the query box, enter:

UPDATE pre_CubeCart_inventory SET `google_category` = "default-category-noted-earlier" WHERE `google_category` = "";

Note the names of columns are enclosed in backticks (above the tab key), not apostrophes.

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