Jump to content

Stop a category appearing in Latest Products feed ?


Nik Grey

Recommended Posts

Due to the nature of the custom 'Lettering Tool' design I have another problem to overcome..lol - it's fun :)

 

Every time someone uses the Lettering Tool to make a sign the text they have used appears in the Products list - with thanks to the knowledgeable forum members we have gotten over displaying this category BUT..

 

Now I see that by default these 'Products' are enabled to show in latest products - I dont want this so how could I disable this from happening ? I could of course go through each product, or delete them all but every time someone uses the Lettering Tool again I would have to go into admin and stop it appearing in the 'Latest Products' feed - this would become a problem.

 

IS there maybe the possibility of a Code Snippet for this ? I want my other products to appear in the 'Featured Product' box - oh, and I just noticed a 'Letting' product appearing in my 'Popular Products' box :(

 

 

Link to comment
Share on other sites

As for inventory showing up in the Latest Products area on the HomePage (the code calls LP items featured, while the Featured Product box has code that calls the item random), we need to find what is happening and how to change that.

 

Realistically speaking, any product recently added is a "Latest Product" and gets shown on the HomePage. In your case, where products are added to inventory as a requirement to sell your lettering fabrication, you don't want recently added products to have that property.

 

The database table CC_inventory has a 'featured' column that, if no value is given, defaults to 1. We need to change the default to 0. You can do that in phpMyAdmin. Hopefully, the developers have not given a value for this column when the lettering product is inserted into the inventory table. (And it's a black mark on the developers to not have noticed, or ignored, this side-effect.)

 

As for the Featured Product (a random inventory record), this is processed in GUI->_displayRandomProduct(). This function will make an attempt, up to 300 times, to find an eligible product to display. We can use the 'hide' column value of the CC_category table since it would be desirable for the "Lettering" category to be hidden anyway (not disabled!). CubeCart does not currently use this (for future versions, let's hope CubeCart uses this property for its obvious intended meaning), so let's set the value of the 'hide' column for the Lettering category to 1. You can do that in phpMyAdmin.

 

Then, in a snippet, we can test for the 'hide' value. If the random inventory record has its main category 'hidden', we can tell the function to try again. Create a new snippet:

Enabled: green tick

Unique ID: No_Prods_w_Hidden_PriCat_in_FP@Nik_Grey

Execution Order: 99

Description: Rejects a product if it's main category is hidden.

Trigger: class.gui.display_random_product

Version: 1.0

Author: forums.cubecart.com/topic/48080-stop-a-category-appearing-in-latest-products-feed/

PHP Code:

{php}
$query = sprintf("SELECT CI.* , C.hide FROM `%1$sCubeCart_category_index` AS CI, `%1$sCubeCart_category` AS C WHERE CI.cat_id = C.cat_id AND CI.primary = 1 ORDER BY CI.product_id", $GLOBALS['config']->get('config', 'dbprefix'));
if (($cat_hide_data = $GLOBALS['db']->query($query)) !== false) {
  foreach ($cat_hide_data as $data) {
    if ($data['hide'] == 1 && $data['primary'] == 1) { $p++; $this->_displayRandomProduct($p); }
  }
}
{/php}

@Al, please add C.hide (next to C.status) to Catalogue->getCategoryStatusByProductID().

 

What the PHP code does:

We need to make our own database call because the 'hide' value is not returned in getCategoryStatusByProductID(). Then, if the product's primary category is 'hidden', we increment the number of times trying to find an eligible product and ask the routine to try again.

 

 

As for the Popular Products box, we will look at that shortly.

Link to comment
Share on other sites

Excellent, I am happy with the above but before we go on:

 

In the CC_inventory table every instance of the 'Lettering' product has a 1 in the featured column.

 

BUT even though I have removed all of the 'Lettering' products from the 'Product Inventory' in CC Admin (I left x5 for testing with) I still see EVERY SINGLE entry in the database since Day 1 when the first version of this tool was installed.

 

So, I don't mind going through manually and deleting them all but wont they re-appear each time someone uses the tool? and require me to go into the database again to hide each one?

 

I sorted out the CC_category fix and they are not appearing in the 'Featured Product' box any longer :)

 

 

I may have miss-understood you but how do I make the default '0' (Other than going through each one and changing it from 1 to 0) ?

 

A little later - the snippet is applied now also: http://www.greyprint.co.uk/

Link to comment
Share on other sites

 

The database table CC_inventory has a 'featured' column that, if no value is given, defaults to 1. We need to change the default to 0. You can do that in phpMyAdmin.

 

If I'm understanding Brian correctly, these old test Lettering Tools products either need to be deleted or the featured value needs to be changed to zero.

 

Then go to the Structure of the table and change the default value from 1 to 0. Then any new product will not show in Latest Products unless YOU change the X to the green check in the Product Overview tab as you create the product listing.

Link to comment
Share on other sites

"Even though I have removed all of the 'Lettering' products from the 'Product Inventory' in CC Admin (I left x5 for testing with) I still see EVERY SINGLE entry in the database since Day 1 when the first version of this tool was installed."

 

Deleting a product will delete the respective table record from the database (as well as respective records from a few other tables). It is inconceivable that you can see a record in CC_inventory for a product that was deleted in CC's admin.

 

"I still see EVERY SINGLE entry in the database."

 

In which table?

Link to comment
Share on other sites

I realise it's not a very clear image but everything in the database on the right apart from the top one is an instance of the 'Lettering' tool:

 

db.jpg

 

As you can see on the left (In CC Admin) I only have x5 as I deleted the rest.

 

Thanks DB - I hadn't realised I had to go to the 'Structure' - I will find that now (remember - I am new to this but want to learn).

 

Oh, and when I select 'View All' (in CC Admin) nothing changes.

Link to comment
Share on other sites

Sorry, the images are so reduced in size to be impossible to see any data.

 

I'm guessing the CC admin screen has products filtered to show only from the Lettering category. There must be some other filtering happening if you have pagination with only 5 line items. (Or CC525's fix for pagination didn't resolve that problem for you.) What is the exact querystring part of the URL for that admin page? It will look something like: ?_g=products&sort[updated]=DESC&char=T&cat_id=2

 

I notice that the Product Code column is empty??? (In the database, 'product_code' would be null, as well as 'product_description'. Hey! We can use that!)

 

(On my installation, I see that, if the combined filtering of category and first letter filtering results in no matching products (and I get a red banner saying as such), the Any link does not restore back to allow any letter as the first letter. I'll have to look into that.)

Link to comment
Share on other sites

Here are the full size images:

 

http://nikgrey.com/demo-images/odd1.png

 

http://nikgrey.com/demo-images/odd2.png

 

Yes, I am filtering for 'Lettering' only. - the 2nd image is with 'View All' selected as it looked like I had more products not showing in the original 'small' image I showed you above.

 

You can see the string now but in admin it is:

http://www.greyprint.co.uk/admin.php?_g=products&cat_id=19&page=all

 

It disturbs me to see the entire history of each 'Lettering' product still in the database - surely I am doing something wrong somewhere.

Link to comment
Share on other sites

Of the records shown in the phpMyAdmin screen grab, other than the first one shown, they all have category ID of 2. You will need to determine what category has/had cat_id = 2.

 

According to trying to show categories 1-4 (index.php?_a=category&cat_id=4), Your store says these categories don't exist. If that's the case, then those inventory records won't show in the admin Products list filtered by "Lettering" - which is cat_id = 19.

Link to comment
Share on other sites

ok, I think I know what happened - originally when I got the first attempt at this tool it was displayed at a different address.. actually, I just found the old email - it was this:

http://greyprint.co.uk/index.php?_a=template&module=lettering

 

 

Then as things 'Progressed' the address of the tool page changed so maybe these are the old installation ?

 

As I do not now have anything as Category 2.

 

Does this mean I should go and manually delete each of these cat 2 records in the database? I can see that also cat 16 was used for this at some stage ! - delete these aswell?

Link to comment
Share on other sites

In CubeCart's admin, do not filter for anything. Start deleting from the Products list whatever you want. Don't try to do this from phpMyAdmin. (When CubeCart deletes a product, it also manages the deletion of any associations with categories, associations with images, associations with options, associations with etc.)

Link to comment
Share on other sites

ok, I think I have done everything listed above - I will be working on my Store this evening so will be able to see if everything is working as I hope - I am confident.

 

Thanks very much again for the continued help - this was the very reason I went with CC because of this forum :)

Link to comment
Share on other sites

I noticed that my 'Lettering' products were appearing in the 'Featured Products' box again after doing more testing - I re-visited Brian's Excellent instructions above and realised I had missed a step.. corrected that omission and now everything is working as I had hoped :)

Link to comment
Share on other sites

I see 5.2.7 :)

 

I wonder what the implications are for me though, with the changes we have made to 'Hide' the Lettering tool ? I just upgraded my 'Test Store' and the Lettering Tool is not appearing even though I made it visible.

 

When upgrading I had a message (Database is using 5.2.5 and you are now using 5.2.7 so use the 'Setup' which I did).

 

I'm tempted to go ahead and upgrade the 'Live Store' just to see what happens :)

Link to comment
Share on other sites

"The Lettering Tool is not appearing even though I made it visible."

 

That problem is not in the scope of our previous discussions about hiding the Lettering Tool as a category in the Shop by Category box.

 

Maybe you should elaborate on what you mean by not appearing.

Link to comment
Share on other sites

On the Test Store, the tool just doesn't appear at all:

http://test-store.greyprint.co.uk/index.php?_a=letter

 

I'm thinking before I can test the update properly I will need to clone the 'Live' store again and make sure all is well before proceeding.

 

I think it was just a case of using a database backup from the Live store and applying it to the 'Test' but the 'Database Message' I got when updating the Test has me a bit worried - I wonder what that could have meant ! It was something along the lines of "You are using 5.2.7 but your database is still using 5.2.5 - please use the 'Setup' again".

 

**

 

Rather than messing about with that maybe I should just update the 'Live' store and see what happens ? the reason I asked about it here is because a 'Tweak' we made for 'Hiding a category' may have clashed with the new update..

Link to comment
Share on other sites

"You are using 5.2.7 but your database is still using 5.2.5 - please use the 'Setup' again."

 

As a general rule, one should allow CubeCart to update the database to match the requirements of that particular codebase.

 

So, as a general rule, CubeCart will compare the version of the codebase with the last record in the database history table.

 

The question I have: is the "Lettering Tool" completely self-contained in its own folder within the /modules/external/ folder? Or are there perhaps modifications made, or new copies of the entire file, of core CubeCart files? (Not any of the files we edited, however.)

Link to comment
Share on other sites

Brian,

 

I completely understand that I am a complete PITA, I just want/need to understand how things work - I only post here when I am stuck.

My goal is to have a 'Simple' website but unfortunately I made the mistake of choosing the wrong developer to create a tool for me.

 

I am quite happy to send you the complete module, and do expect to pay you for your help - in the long run this will save me time and, certainly stress.

 

I will pack it now and offer it in a PM if it will help.

 

All I wanted to do was start a small business - the Website was supposed to give me no problems but has turned out to be the worst thing I have ever done (Not CC, but the bad choices I made in trying to save a few quid).

Link to comment
Share on other sites

"I completely understand that I am a complete PITA."

 

You are mistaken.

 

"My goal is to have a 'Simple' website."

 

No such thing.

 

"...has turned out to be the worst thing I have ever done."

 

You are still young (presumably).

 

 

I will PM you with my email address.

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