Link to home
Start Free TrialLog in
Avatar of sharingsunshine
sharingsunshineFlag for United States of America

asked on

Sale Category Sort Needs To Be Limited to Itself

This is a follow-on to the question.  
https://www.experts-exchange.com/questions/29109489/Need-Woocommerce-Category-Sorted-by-Description-Within-Product.html

Open in new window


The plugin works great for the sale category but it seems to be making all of the categories behave in the same manner.  Is it possible, to just specify in the plugin to use its logic just for the sale category?
Avatar of Adrian Thompson
Adrian Thompson
Flag of United Kingdom of Great Britain and Northern Ireland image

Hello,

Thanks for posting this follow-up question. It would be useful for me to see your other categories before I update the plugin. However your website is offline at the moment as it says "Sorry, your request cannot be accepted": http://www.theherbsplace.com

Looking at your other questions, it seems you are in the process of installing security software or a WAF (Web Application Firewall).

Please can you post here again when your website is back online? After that, I will take a look at your other categories and update the plugin accordingly.

Thanks,
Adrian
Avatar of sharingsunshine

ASKER

I didn't know it was offline.  Can you pm me your IP so I can check the logs and see what is blocking you?
I worked it out already ;-)

You are not blocking my IP - you are blocking based on Geographic location. I am in the UK and it looks like you are blocking all traffic from this country! Can you unblock my country please ;-)
Glad you told me.  I thought the plugin had the uk whitelisted.  I deleted that plugin since it wasn't working correctly.  Let me know if you can get in.
Ah good. I can see your website again now so that's great. I'll get working on the plugin and post back here when its ready, probably tomorrow.

In the meantime, why don't you install WordFence? I've used WordFence and its great. Just don't go blocking the UK ;-)

https://en-gb.wordpress.org/plugins/wordfence/
I have wordfence but they don't block via country on the free option.  On my old server I used ipsets but I wanted something more dynamic on the new site.  I am using iThemes and Stop Robots.  IP Geo Block was what blocked you out accidentally.

Here is another question you can probably answer quickly - https://www.experts-exchange.com/questions/29110063/Need-List-Of-Woo-Commerce-Image-Dimensions-Stored-On-DB.html#questionAdd
Here is v0.5 of the plugin. If you go to the WCAS Settings, there is a new option to select "Product Category". You can choose "Sort All Products" or you can choose a specific category, in order to isolate the sorting process.
agt-wc-autosort-v05.rar
this download is showing as a rar archive instead of a zip archive.  Consequently, it won't load properly.  Here is the error I am receiving.

https://gyazo.com/00b526346077f520eb772db058b49ad9
it is sorting the header now.  I deactivated the plugin, cleared cache and it is still showing the same sort pattern.

https://gyazo.com/6dcd0d204b4d53200cb2dd2dcb61e5f7

I believe it should be Shop A-Z, Membership, Heartworm, Herbs for Pets, Sale, More

I picked the on sale category and it sorted 69 products and the sale page looked great.  Just need it to get to leave alone the header.
Hello,

Please can you confirm the plugin is now only sorting your "On Sale" category? And all other categories are now correct?

If this is the case, the plugin is working as it should.

However, I have checked my plugin code it is "resetting" the order of everything (including menus) when you click "Auto Sort". It should only reset the order of products (i.e. it should not reset the order of everything else such as your menu!). Apologies for this.

You will need to manually set your menu order again:
https://www.theherbsplace.com/wp-admin/nav-menus.php

This updated plugin (v0.6) will no longer "reset" your menu! It will only affect your products, as is intended. Apologies for this oversight. If you get your menu in the right order then use the new plugin v0.6 (below) it will be fine.

Here is the new plugin:
agt-wc-autosort-v06.zip
It still isn't working.  I went to the link for resetting menus and picked the menus that I am using and re-saved them.  I then autosorted just on "on sale" the header never changed and if you look at the A-Z tab you will see the drop downs aren't in alphabetical order anymore.

There also seems to be a new wrinkle on the sales.  When you looked at them initially most of the sales were created on a Mac so that's why the encoded character was predominant.  However, I now use a windows machine and when I use a dash it isn't creating the encoded character.  So, I think the best option is to change them all over to the dash I am using on the Windows system.

I'm sorry I didn't realize that until I began adding dashes and seeing they aren't being sorted correctly.

I don't know the sql commands to switch the site to a regular dash.  So if you want I can ask another question once we get this sort working.
This command replaces the encoded dash with a simple dash:
(you just need to replace "YOUR-DATABASE-NAME" with your actual database name)
UPDATE `YOUR-DATABASE-NAME`.`wp_posts`
SET post_title=REPLACE(post_title,'–','-')
WHERE post_type='product'
AND post_status='publish';

Open in new window


QUESTION - Are you using v0.6 and did you make sure your menu was 100% correct before you clicked the "Auto Sort" button?

Let me know. Thanks!
yes, I am using the latest version but it is now putting all of the $2's together.  I have ran the sql query changing everything, changed the settings, did the sort and refreshed the browser.

Here are my settings

https://gyazo.com/cc3d70ae090ccda164fc10219b747872
In your plugin settings, you are using - (dash) but on your website you are using – (long dash). You need to look closely to see the difference but they are two different symbols, which is why your new settings are not working.

Look at the sizes of these two symbols and you will see they are both different:
–  
-

Also see:
https://en.oxforddictionaries.com/grammar/dash-and-em-dash

And this is the code reference (known as ASCII):
https://www.ascii.cl/htmlcodes.htm

User generated image

At the moment, the plugin does not support the long dash. I will now include this for you in the plugin. After I post the new plugin version here, there will be an option for - (dash) and an option for – (long dash) in the plugin settings page.

If you choose - (dash) in the plugin settings page but you are using – (long dash) in your website then it will never work so consistency is important.
Sorry, my mistake - I wrote my last comment from memory. In fact, the plugin already supports both the dash and the long dash. Although I call them by different names:

User generated image
The first option (dash) is actually the long dash and the second option (minus sign / hypen) is actually the short dash.

Your settings are therefore correct but you still have encoded dashes on your website, which is the problem:
User generated image
I think you may have forgot to run this code (this replaces all encoded dashes (short dashes) with raw (not encoded) long dashes:
UPDATE `YOUR-DATABASE-NAME`.`wp_posts`
SET post_title=REPLACE(post_title,'–','–')
WHERE post_type='product'
AND post_status='publish';

Open in new window

Anyway, this is all getting complicated so I have another idea that will make this simple!!

I will make another version of the plugin where the separator can be "ANY SYMBOL (EXCEPT CURRENCY)" then it will fix all this! So please ignore all of the above and wait for the next version where you can select this new option ;-)
thanks for sticking with me on this.  I had ran the query so the new separator approach will certainly be better.
Version 7 is now ready. Make sure "Any symbol" is selected:
User generated image
Here is the plugin to download:
agt-wc-autosort-v07.zip
I deleted the other plugin, loaded the new one, selected the on sale category, saved and then hit sort.  Refreshed the browser and it still doesn't work.

By the way, the plugin still shows version .06
I forgot to update the number but the file I sent you is indeed v0.7 and it should work fine.

As its not working for you, the fastest solution would be if you can export your database and send me a copy to test. Is this possible?

If so, you could use a file transfer service such as www.wetransfer.com with a password protection. Then you could send me a private message on here with the link and the password. For speed, it would also be good if you can create me an account before you do the export such as:
username: adrian
password: test

make the account a full admin then do the export then you can immediately delete the account again so I don't have access to the live site, only the test export you are sending me. Passwords are encrypted in the export so I would not be able to view other user account info.

We could continue troubleshooting if you like but this would be much faster as I can see first hand what is happening without asking you to keep testing. Let me know your thoughts.

Thanks
I sent you the db.  I needed to update this question.
I have looked at the database export you gave me and it is incomplete.

All WordPress installations have a table "wp_posts" in the database but this table is missing. On the Live DB, please can you delete the PS tables (PrestaShop tables) then recreate my WordPress Dashboard Admin Account then export again making sure that you include ALL TABLES in the export including "wp_posts". Remember to backup your database first!

This page shows all the tables that a WordPress installation should include:
https://codex.wordpress.org/Database_Description
Just under the diagram on this page there is heading "Table Overview", under this heading it states:
"This section is the overview of all the tables created during the WordPress standard installation"
Therefore please ensure all these tables are included in your export.

As you are missing some of these tables including the most important "wp_posts" I am unable to work with it. Once you re-export your database to include this table I can continue.

You are also missing the Woo Commerce tables in the export. This link shows a list of WooCommerce tables that should be in your DB:
https://github.com/woocommerce/woocommerce/wiki/Database-Description

The above link is referenced from the official documentation here:
https://docs.woocommerce.com/document/installed-database-tables/

Have you accidentally exported the wrong database? Or did you forget to include all tables? Let me know because this is very unusual, especially because you have PrestaShop tables included which are not relevant.

I look forward to your response.
I have just had a look at your database and all your products "on sale" are in the correct order. Also I looked at your live site:
https://www.theherbsplace.com/product-category/on-sale/

All your 66 products in this section are in the correct order. Did you set all these manually? I assume you must have done, otherwise the plugin is working fine for you. Please confirm how you got them in the right order (manually or another method). It would be good for me to know. Thanks
I have just tested my plugin on the database you sent me and its working perfectly.

Please can you show me an example of where this is not working? I need to find something that is not working in order to fix it... if everything is already perfect that there is nothing for me to fix ;)
By the way, I know the original question was "Sale Category Sort Needs To Be Limited to Itself" but we already fixed that earlier... As far as I remember, this is what we have done:

1. Before you asked this question, the plugin was working but it wrongly sorted other categories
2. You asked this new question so I can update the plugin to only update the "on sale" category
3. After I did this, it completely stopped working as you changed your separator symbol, so I updated the plugin with a new option:
"Any Symbol"
4. After I made this update you said it is not working at all. I therefore asked if you can send me a copy of your database.

Now I have a copy of your database I have tested the plugin on your database and it is working perfectly. Also your website seems perfect.

I hope this helps to clarify the current status of this question (this post is probably more for my benefit as I was losing track!)
You are correct you have successfully been able to limit this to the sales category.  But as you can see, this product isn't sorting in the normal order:
https://gyazo.com/3cff7b68784d309484d34552fb476c9b

This is what prompted you to want the db to see if you could tell why it was out of sequence.
ASKER CERTIFIED SOLUTION
Avatar of Adrian Thompson
Adrian Thompson
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Everything, works great.  Thanks for sticking with this.