Flamekebab
Forum Replies Created
-
Ah, a much better place for it. Issue posted!
https://github.com/woocommerce/woocommerce/issues/25339Updated code that doesn’t rely on
is_tax
://Queries aren't respecting that out of stock items aren't to be shown - this affects search and the product catalogue: function fox_filter_query_results($query) { //Retrieve the query object using its method? Class? I'm in terminology hell right now: $queryObject = $query->get_queried_object(); //We need a conditional too to make sure weird stuff doesn't happen. //The query object can either be 'product' or it's a taxonomy thing in which case we want the WooCommerce taxonomies: if($queryObject->name == "product" || $queryObject->taxonomy == "product_cat"|| $queryObject->taxonomy == "product_tag"){ // only search the product post type $query->set('post_type', array('product', 'post')); //in principle this should only show results that are in stock. $query->set('meta_query', array( array( 'key' => '_stock_status', 'value' => 'instock',)) ); } return $query; } add_filter('pre_get_posts','fox_filter_query_results');
I was eventually able to determine what was happening – for whatever reason WooCommerce is not handling the filtering of a $query correctly.
This applies to searches, listing by tag, listing by categories, and probably other things too.
My shop is set to hide items that are out of stock and it does – but they’re not being correctly filtered out. I hacked together this fix and added it to the bottom of my theme’s
functions.php
:function fox_filter_query_results($query) { //We need a conditional too to make sure weird stuff doesn't happen. if($query->is_search || $query->is_tax){ // only deal with the 'product' post type $query->set('post_type', array('product', 'post')); //Only show results that are in stock. $query->set('meta_query', array( array( 'key' => '_stock_status', 'value' => 'instock',)) ); } return $query; } add_filter('pre_get_posts','fox_filter_query_results');
This fixed the problem. The total for search results and other things that use
$query
are now correctly pruned and a page of 30 products is 30 products long.Oddly enough I couldn’t get the query to behave with regards to checking whether a product category or tag was being viewed but both of those queries have
is_tax()
returning true so I went with that as the conditional instead. If someone could give me a better line of code to replace that though I’d be pleased as it feels a little hacky (given that it’s a check for taxonomy in a way I don’t really understand). Then again product_category and product_tag are both custom taxonomy so maybe that’s what it’s for?Further work on this issue has revealed a likely cause of the problem:
hidden items aren’t removed properly.
I have various items that are out of stock and the option to hide them is enabled (
Hide out of stock items from the catalog
for those of you in the audience googling).For a start those items are not being hidden from
$total
(and this applies when visiting this site as a user, not an admin too). This leads to an incorrect search/catalogue result count:
Furthermore it leads to items being removed page by page – not from the complete query.
For example if I do a search that should get 30 results and there are only 26 visible products strange things happen when the site is set to show 10 per page.
The first page will show 6 products, the second 10, the third 10. Or maybe it’ll be 9 on the first page, 7 on the second, and 10 on the last (depending on where in the array the products are marked as hidden, presumably).How do I fix this?
Forum: Plugins
In reply to: [WooCommerce] Product search results and theme supportI’ve been prodding and poking further and it seems that one more element of the puzzle has been solved – I hadn’t declared theme support.
function mytheme_add_woocommerce_support() { add_theme_support( 'woocommerce' ); } add_action( 'after_setup_theme', 'mytheme_add_woocommerce_support' );
I’ve now done that and it changed a few things.
The search page is now working, to an extent, but it has its own issues. I’ve created a separate topic for those.
Forum: Plugins
In reply to: [Jigoshop eCommerce] Getting a product’s image using the API?How are things progressing on this bug?
Forum: Plugins
In reply to: [Jigoshop eCommerce] Syntax for API PUT operations? [Potential Bug]Follow up on the user-agent thing – there’s an extension I have for blocking various crawlers. It was blocking python-requests. Nothing to do with Jigoshop ??
Forum: Plugins
In reply to: [Jigoshop eCommerce] Syntax for API PUT operations? [Potential Bug]Another odd one – it seems like if one doesn’t supply a user agent the API just provides “200 OK” and does nothing. As in any given request won’t throw an error but also won’t do anything.
Forum: Plugins
In reply to: [Jigoshop eCommerce] Syntax for API PUT operations? [Potential Bug]Excellent stuff. That seems to be working.
There’s a related issue that might be a symptom of another problem – when issuing a PUT command to update the stock the returned data lists all the categories the shop supports.
For example:
Product “API_test” appears in the category “Fox Box”A GET command on it lists the following:
{ "success": true, "data": { "id": 7354, "type": "simple", "name": "API_test", "description": "", "sku": "", "brand": "", "gtin": "", "mpn": "", "featured": false, "visibility": 3, "is_taxable": true, "tax_classes": [], "size": { "weight": "0", "width": "0", "height": "0", "length": "0" }, "attributes": [], "attribute_order": null, "attachments": [], "categories": [ { "id": 70, "name": "Fox Box", "slug": "fox-box", "link": "https:\/\/fox-box.co.uk\/product-category\/fox-box\/" } ], "tags": [], "link": "https:\/\/fox-box.co.uk\/product\/api_test\/", "cross_sells": [], "up_sells": [], "regular_price": 0, "stock": { "manage": true, "status": 1, "allow_backorders": "no", "stock": 1 }, "sale": { "enabled": false, "price": "", "from": { "timestamp": 1528156800, "date": "2018-06-05" }, "to": { "timestamp": 1528156800, "date": "2018-06-05" } } } }
If I then issue a PUT command to update the stock:
{"jigoshop_product":{"stock_stock":3} }
The returned value is:
{ "success": true, "data": { "id": 7354, "type": "simple", "name": "API_test", "description": "", "sku": "", "brand": "", "gtin": "", "mpn": "", "featured": false, "visibility": 3, "is_taxable": true, "tax_classes": [], "size": { "weight": "0", "width": "0", "height": "0", "length": "0" }, "attributes": [], "attribute_order": null, "attachments": [], "categories": [ { "id": 35, "name": "Big Gunz", "slug": "orc-big-gunz", "link": "https:\/\/fox-box.co.uk\/product-category\/orc-big-gunz\/" }, { "id": 106, "name": "Clergy", "slug": "clergy", "link": "https:\/\/fox-box.co.uk\/product-category\/clergy\/" }, { "id": 105, "name": "Crusaders", "slug": "crusaders", "link": "https:\/\/fox-box.co.uk\/product-category\/crusaders\/" }, { "id": 107, "name": "Familiars", "slug": "familiars", "link": "https:\/\/fox-box.co.uk\/product-category\/familiars\/" }, { "id": 70, "name": "Fox Box", "slug": "fox-box", "link": "https:\/\/fox-box.co.uk\/product-category\/fox-box\/" }, { "id": 37, "name": "Greenskin Accessories", "slug": "greenskin-accessories", "link": "https:\/\/fox-box.co.uk\/product-category\/greenskin-accessories\/" }, { "id": 21, "name": "Greenskin Arms", "slug": "orc-arms", "link": "https:\/\/fox-box.co.uk\/product-category\/orc-arms\/" }, { "id": 4, "name": "Greenskin Heads", "slug": "orc-heads", "link": "https:\/\/fox-box.co.uk\/product-category\/orc-heads\/" }, { "id": 22, "name": "Greenskin Left Arms", "slug": "orc-left-arms", "link": "https:\/\/fox-box.co.uk\/product-category\/orc-left-arms\/" }, { "id": 19, "name": "Greenskin Legs", "slug": "orc-legs", "link": "https:\/\/fox-box.co.uk\/product-category\/orc-legs\/" }, { "id": 23, "name": "Greenskin Right Arms", "slug": "orc-right-arms", "link": "https:\/\/fox-box.co.uk\/product-category\/orc-right-arms\/" }, { "id": 18, "name": "Greenskin Torsos", "slug": "orc-torsos", "link": "https:\/\/fox-box.co.uk\/product-category\/orc-torsos\/" }, { "id": 53, "name": "Greenskin Vehicles", "slug": "greenskin-vehicles", "link": "https:\/\/fox-box.co.uk\/product-category\/greenskin-vehicles\/" }, { "id": 5, "name": "Greenskins", "slug": "orcs", "link": "https:\/\/fox-box.co.uk\/product-category\/orcs\/" }, { "id": 39, "name": "Grots & Goblins", "slug": "grots", "link": "https:\/\/fox-box.co.uk\/product-category\/grots\/" }, { "id": 33, "name": "Gunz", "slug": "gunz", "link": "https:\/\/fox-box.co.uk\/product-category\/gunz\/" }, { "id": 34, "name": "H2H", "slug": "orc-h2h", "link": "https:\/\/fox-box.co.uk\/product-category\/orc-h2h\/" }, { "id": 91, "name": "Kitbasherz' Korner", "slug": "kitbashing", "link": "https:\/\/fox-box.co.uk\/product-category\/kitbashing\/" }, { "id": 62, "name": "Kromlech", "slug": "kromlech", "link": "https:\/\/fox-box.co.uk\/product-category\/kromlech\/" }, { "id": 89, "name": "LavaTurbine", "slug": "lavaturbine", "link": "https:\/\/fox-box.co.uk\/product-category\/lavaturbine\/" }, { "id": 79, "name": "Opposing Forces", "slug": "op-for", "link": "https:\/\/fox-box.co.uk\/product-category\/op-for\/" }, { "id": 104, "name": "Sororitas Arcanum", "slug": "sororitas-arcanum", "link": "https:\/\/fox-box.co.uk\/product-category\/sororitas-arcanum\/" }, { "id": 87, "name": "Terrain", "slug": "terrain", "link": "https:\/\/fox-box.co.uk\/product-category\/terrain\/" }, { "id": 54, "name": "Vehicle Accessories", "slug": "vehicle-accessories", "link": "https:\/\/fox-box.co.uk\/product-category\/vehicle-accessories\/" }, { "id": 38, "name": "Vehicle Crew", "slug": "vehicle-crew", "link": "https:\/\/fox-box.co.uk\/product-category\/vehicle-crew\/" }, { "id": 36, "name": "Vehicle Parts", "slug": "vehicle-parts", "link": "https:\/\/fox-box.co.uk\/product-category\/vehicle-parts\/" }, { "id": 32, "name": "Weapons", "slug": "orc-weapons", "link": "https:\/\/fox-box.co.uk\/product-category\/orc-weapons\/" } ], "tags": [ { "id": 90, "name": "acrylic", "slug": "acrylic", "link": "https:\/\/fox-box.co.uk\/product-tag\/acrylic\/" }, { "id": 43, "name": "Basicks", "slug": "basicks", "link": "https:\/\/fox-box.co.uk\/product-tag\/basicks\/" }, { "id": 57, "name": "bike", "slug": "bike", "link": "https:\/\/fox-box.co.uk\/product-tag\/bike\/" }, { "id": 42, "name": "bionic", "slug": "bionic", "link": "https:\/\/fox-box.co.uk\/product-tag\/bionic\/" }, { "id": 41, "name": "bionik", "slug": "bionik", "link": "https:\/\/fox-box.co.uk\/product-tag\/bionik\/" }, { "id": 109, "name": "Blackthumb", "slug": "blackthumb", "link": "https:\/\/fox-box.co.uk\/product-tag\/blackthumb\/" }, { "id": 108, "name": "Familiars", "slug": "familiars", "link": "https:\/\/fox-box.co.uk\/product-tag\/familiars\/" }, { "id": 86, "name": "Fox Box", "slug": "fox-box", "link": "https:\/\/fox-box.co.uk\/product-tag\/fox-box\/" }, { "id": 110, "name": "full kit", "slug": "full-kit", "link": "https:\/\/fox-box.co.uk\/product-tag\/full-kit\/" }, { "id": 111, "name": "full sculpt", "slug": "full-sculpt", "link": "https:\/\/fox-box.co.uk\/product-tag\/full-sculpt\/" }, { "id": 24, "name": "gloves", "slug": "gloves", "link": "https:\/\/fox-box.co.uk\/product-tag\/gloves\/" }, { "id": 60, "name": "glyph", "slug": "glyph", "link": "https:\/\/fox-box.co.uk\/product-tag\/glyph\/" }, { "id": 49, "name": "Goblin", "slug": "goblin", "link": "https:\/\/fox-box.co.uk\/product-tag\/goblin\/" }, { "id": 51, "name": "Gretchin", "slug": "gretchin", "link": "https:\/\/fox-box.co.uk\/product-tag\/gretchin\/" }, { "id": 50, "name": "Grot", "slug": "grot", "link": "https:\/\/fox-box.co.uk\/product-tag\/grot\/" }, { "id": 59, "name": "gubbinz", "slug": "gubbinz", "link": "https:\/\/fox-box.co.uk\/product-tag\/gubbinz\/" }, { "id": 46, "name": "GW", "slug": "gw", "link": "https:\/\/fox-box.co.uk\/product-tag\/gw\/" }, { "id": 29, "name": "Hard Plastic", "slug": "hard-plastic", "link": "https:\/\/fox-box.co.uk\/product-tag\/hard-plastic\/" }, { "id": 47, "name": "headwear", "slug": "headwear", "link": "https:\/\/fox-box.co.uk\/product-tag\/headwear\/" }, { "id": 25, "name": "helmet", "slug": "helmet", "link": "https:\/\/fox-box.co.uk\/product-tag\/helmet\/" }, { "id": 103, "name": "hobby accessories", "slug": "hobby-accessories", "link": "https:\/\/fox-box.co.uk\/product-tag\/hobby-accessories\/" }, { "id": 84, "name": "Kromlech", "slug": "kromlech", "link": "https:\/\/fox-box.co.uk\/product-tag\/kromlech\/" }, { "id": 102, "name": "LavaTurbine", "slug": "lavaturbine", "link": "https:\/\/fox-box.co.uk\/product-tag\/lavaturbine\/" }, { "id": 74, "name": "Mek'z Speshul", "slug": "mekz-speshul", "link": "https:\/\/fox-box.co.uk\/product-tag\/mekz-speshul\/" }, { "id": 48, "name": "Metal", "slug": "metal", "link": "https:\/\/fox-box.co.uk\/product-tag\/metal\/" }, { "id": 44, "name": "Orc", "slug": "orc", "link": "https:\/\/fox-box.co.uk\/product-tag\/orc\/" }, { "id": 72, "name": "Orc Boyz", "slug": "orc-boyz", "link": "https:\/\/fox-box.co.uk\/product-tag\/orc-boyz\/" }, { "id": 69, "name": "Ork Battlewagon", "slug": "ork-battlewagon", "link": "https:\/\/fox-box.co.uk\/product-tag\/ork-battlewagon\/" }, { "id": 78, "name": "Ork Bommer", "slug": "ork-bommer", "link": "https:\/\/fox-box.co.uk\/product-tag\/ork-bommer\/" }, { "id": 27, "name": "Ork Boyz", "slug": "ork-boyz", "link": "https:\/\/fox-box.co.uk\/product-tag\/ork-boyz\/" }, { "id": 67, "name": "Ork Gretchin", "slug": "ork-gretchin", "link": "https:\/\/fox-box.co.uk\/product-tag\/ork-gretchin\/" }, { "id": 64, "name": "Ork Lootas & Burnas", "slug": "ork-lootas-burnas", "link": "https:\/\/fox-box.co.uk\/product-tag\/ork-lootas-burnas\/" }, { "id": 40, "name": "Ork Nobz", "slug": "ork-nobz", "link": "https:\/\/fox-box.co.uk\/product-tag\/ork-nobz\/" }, { "id": 68, "name": "Ork Stormboyz", "slug": "ork-stormboyz", "link": "https:\/\/fox-box.co.uk\/product-tag\/ork-stormboyz\/" }, { "id": 58, "name": "Ork Trukk", "slug": "ork-trukk", "link": "https:\/\/fox-box.co.uk\/product-tag\/ork-trukk\/" }, { "id": 55, "name": "Ork Warbikers", "slug": "ork-warbikers", "link": "https:\/\/fox-box.co.uk\/product-tag\/ork-warbikers\/" }, { "id": 63, "name": "OW2", "slug": "ow2", "link": "https:\/\/fox-box.co.uk\/product-tag\/ow2\/" }, { "id": 31, "name": "Resin", "slug": "resin", "link": "https:\/\/fox-box.co.uk\/product-tag\/resin\/" }, { "id": 80, "name": "Sororitas Arcanum", "slug": "sororitas-arcanum", "link": "https:\/\/fox-box.co.uk\/product-tag\/sororitas-arcanum\/" }, { "id": 92, "name": "Special!", "slug": "special", "link": "https:\/\/fox-box.co.uk\/product-tag\/special\/" }, { "id": 66, "name": "Terrain", "slug": "terrain", "link": "https:\/\/fox-box.co.uk\/product-tag\/terrain\/" }, { "id": 56, "name": "vehicle", "slug": "vehicle", "link": "https:\/\/fox-box.co.uk\/product-tag\/vehicle\/" } ], "link": "https:\/\/fox-box.co.uk\/product\/api_test\/", "cross_sells": [], "up_sells": [], "regular_price": 0, "stock": { "manage": true, "status": 1, "allow_backorders": "no", "stock": 3 }, "sale": { "enabled": false, "price": "", "from": { "timestamp": 1528156800, "date": "2018-06-05" }, "to": { "timestamp": 1528156800, "date": "2018-06-05" } } } }
Has it actually enabled all the categories? Let’s issue the same GET command again:
{ "success": true, "data": { "id": 7354, "type": "simple", "name": "API_test", "description": "", "sku": "", "brand": "", "gtin": "", "mpn": "", "featured": false, "visibility": 3, "is_taxable": true, "tax_classes": [], "size": { "weight": "0", "width": "0", "height": "0", "length": "0" }, "attributes": [], "attribute_order": null, "attachments": [], "categories": [ { "id": 70, "name": "Fox Box", "slug": "fox-box", "link": "https:\/\/fox-box.co.uk\/product-category\/fox-box\/" } ], "tags": [], "link": "https:\/\/fox-box.co.uk\/product\/api_test\/", "cross_sells": [], "up_sells": [], "regular_price": 0, "stock": { "manage": true, "status": 1, "allow_backorders": "no", "stock": 1 }, "sale": { "enabled": false, "price": "", "from": { "timestamp": 1528156800, "date": "2018-06-05" }, "to": { "timestamp": 1528156800, "date": "2018-06-05" } } } }
Nope. Weird.
Not exactly a high priority but something that might be worth a quick look. Thanks for fixing the functionality that matters though!
Forum: Plugins
In reply to: [Jigoshop eCommerce] Syntax for API PUT operations? [Potential Bug]Fair enough, as long as it lets me update stock values from a list of product IDs I’ll be happy!
Forum: Plugins
In reply to: [Jigoshop eCommerce] Syntax for API PUT operations? [Potential Bug]In that case I’m glad I could help with the bug-stomping effort!
Would it make more sense to use a PATCH command rather than a PUT one though?
Forum: Plugins
In reply to: [Jigoshop eCommerce] Syntax for API PUT operations? [Potential Bug]It’s now been well over two weeks and I still have boxes of stock sitting on my living room floor because I can’t store them with the existing stock.
I used to have a fairly simple SQL query I could run to update stock quantities (bearing in mind that I have to modify hundreds of records). Since moving to Jigoshop 2.x that’s not been an option. I was hoping that by using the API things could be done properly and avoid issues that an SQL workaround might cause (such as stock visibility problems).
Could I please have an answer on the correct way to use the API to update a product’s quantities?
Forum: Plugins
In reply to: [Jigoshop eCommerce] Syntax for API PUT operations? [Potential Bug]I’m using the latest version, 2.1.12 at the time of writing. Interestingly the Jigoshop system information page doesn’t list a database version number. The field is just blank.
I thought I’d gone through and refreshed every in stock item to ensure that the entries were up to date (after the change to how Jigoshop detects whether an item is visible or not). Perhaps the items were still subject to that but it’s hard to say – my catalogue is too big for me to remember.
With regards to PUT operations a friend of mine asked why PATCH isn’t an option instead of PUT. After all – I only want to amend a single value, not change the entire product.
Forum: Plugins
In reply to: [Jigoshop eCommerce] Syntax for API PUT operations? [Potential Bug]Related question: if I update stock this way will it prevent the “-1 units in stock” bug?
That is to say the stock tracking system seems to get confused when an order is marked as complete if only one unit is in stock. It then lists items as having negative units in stock…
As far as I know, no. There’s a sale on items at the moment based on percentages though – could that be the issue?