Out of Stock where price should be
-
I’ve started listing products on my site and where the price should be they say out of stock. The amazon items are not out of stock though. Does anyone know what I can do to fix this? Thanks in advance.
https://www.ads-software.com/plugins/amazon-product-in-a-post-plugin/
-
Thank you. Was working on a converter that would load the XML data from the database and then convert this to an array. The fact that this is already implemented saves me time.
Quite understandable that you have a release path. The plugin looks beautiful as is, and the beta looks even more impressive. Nice work.
Proceeded with a two-fold approach to solve the sale price listing incorrectly.
From what I can tell the ‘Variations’ responsegroup contains the sale prices for the variations. The other variations responsegroups don’t. So, I will have to use the variations table.
1. It could be nice for a future iteration of the plugin to have an add_filter to replace all the standard groups in the plugin with custom groups. It may allow to overcome the price quirk if this is why the price problem is occuring for some categories.
Something like this (although there may be better ways of doing this):
In functions.php
add_filter('getSingleAmazonProduct_response_group','use_my_own_response_group'); function use_my_own_response_group($rgroups){ $rgroups = "ItemAttributes,Images,Variations"; return $rgroups; } /* add_filter('getSingleAmazonProduct_response_group','add_my_own_response_group'); function add_my_own_response_group($rgroups){ return $rgroups.',VariationImages, VariationMatrix'; } */
Then in amazon-product-in-a-post-functions:
$rgroups = "Large,Reviews,VariationSummary"; $appip_responsegroup = apply_filters('getSingleAmazonProduct_response_group', $rgroups);
2.The following snippet solves the price issue with custom code for purpose made templates. Please keep in mind this is all alfa code and should not be used on a production site, and it won’t work with the plugin interface or shortcodes, it is just code that runs. .
Using the variations table was able to get the sale price for each variation using the following proof of concept code. It is intended to list the different attributes by color (alfa stage and still buggy).
$i = 0; $total_variations = $resultarr2[0]->Variations_TotalVariations; while($i <= $total_variations) { $i++; $variation_size = 'Variations_Item_' . $i . '_ItemAttributes_Size'; $variation_color = 'Variations_Item_' . $i . '_ItemAttributes_Color'; $variation_list_price = 'Variations_Item_' . $i . '_ItemAttributes_ListPrice_FormattedPrice'; $variation_sale_price = 'Variations_Item_' . $i . '_Offers_Offer_OfferListing_Price_FormattedPrice'; // Available sizes by color $variation_array['available_color-' . $resultarr2[0]->$variation_color]['available_size-' . $i] = $resultarr2[0]->$variation_size; // List Price by color $variation_array['available_color-' . $resultarr2[0]->$variation_color]['list_price-' . $i] = $resultarr2[0]->$variation_list_price; // Sale Price color $variation_array['available_color-' . $resultarr2[0]->$variation_color]['sale_price-' . $i] = $resultarr2[0]->$variation_sale_price; } unset($i); print_r($variation_array);
This solves the problem I was running up against. The code still needs improving, but it is a possible approach to fix the problem, but at least now know where the problem was occuring for me. When I get all the bugs ironed out my intention is to publish the finished code here if helps (or the plugin may already solve it by then).
Hope it helps.
@design_dolphin
Thanks for the feedback –
on your number 1 above:It could be nice for a future iteration of the plugin to have an add_filter to replace all the standard groups in the plugin with custom groups. It may allow to overcome the price quirk if this is why the price problem is occuring for some categories.
This is already in the beta you have. The example filer I used just adds to it, but the point of the filter is that you CAN change or filter the response groups – like so:
add_filter('getSingleAmazonProduct_response_group','add_my_own_response_group'); function add_my_own_response_group($rgroups){ $yournewgroups = '[PUT YOURS HERE]'; return $yournewgroups ; }
That will be in place in 3.5.3 when it goes to production.
On number 2. That would be great. I will not be adding the variations to the plugin just yet (except as a ‘between X and Y price used in the Variations Summary), as I think it is more than most people need. When developing a plugin, you have make sure it works for the masses and then address the exceptions when they happen. Having something for other to look at will make it easier if they need to do it themselves.
The only thing I ask, is that you keep is as SIMPLE as possible. Most users of the plugin are not programmers and take everything in a post as truth, but in reality they may not understand how it will affect their site. Keep it simple, hook into the plugin whenever possible, explain your code and what it does (both positive and negative) and don’t try to reinvent the wheel! Thanks again.
Warm regards,
There appears to be a possible workaround/ solution in the virgin beta plugin to solve this double pricing and out of stock quirk. This using the standard Responsegroups that come with the beta plugin, or using the add or replace Responsegroups filter in functions.php
– Uncheck ‘list price’ in the post admin screen under ‘Amazon Product in a Post’ form.
It will now show the ‘starting at’ or ‘from’ price and the stock message when there is no sale price. This instead of the crossed out list price with the sale price being the same. When there is a sale price it showed the sale price below the normal price, as well as the in stock message.
This when ASIN is filled in ‘Amazon Product ASIN (ISBN-10)’, the ‘Product is Active?’ is checked, and the ‘Hook into Content?’ is checked, and ‘Open Product Link in New Window?’ is checked.
Other options like ‘Show Amazon Features?’ seem to work with it as well. (Although there may be option settings that could cause conflict, that would need further testing.)
Is that what you meant with?
Note that you CAN turn off the list price in both the shortcode and the single product (single product has a checkbox to remove the list price, shortcode has a variable). So when that is an issue, I would suggest just turning it off.
Haven’t tested it with AMAZONPRODUCTS or amazon-elements yet.
Hope it helps.
Testing the possible workaround/ solution with:
AMAZONPRODUCTS or amazon-elementsUsing the workaround for AMAZONPRODUCTS or amazon-elements tags doesn’t work completely or not all.
1. AMAZONPRODUCTS will show the lowest price only using:
[AMAZONPRODUCTS asin=”XXXXXXXXXX” listprice=”0″]
So while this solves the double pricing, it does not show sale and list price together when an item is on sale. When using the standard Responsegroups it would show an item in or out of stock correctly. When using the Responsegroups ‘ItemAttributes,Images,Variations’ it would show item as out of stock when it was in stock.
2. The workaround doesn’t seem to work with amazon-elements.
Tested amazon-elements with:
LowestNewPrice (shows 0 regardless whether an item is on sale or not)
ListPrice (Shows list price only)
new-price (Shows nothing).
msg_instock=”in stock” (Shows nothing)
msg_outofstock=”no more left!” (Shows nothing when in stock, which would be correct because it is in stock. Shows nothing when out of stock.)Both 1. and 2. using the standard Responsegroups that come with the beta plugin, or using the add or replace Responsegroups filter in functions.php
While this may not provide a solution at the moment, I do hope it gives some data and does some testing to help solve the bug. Please double check as I may have missed something.
@design_dolphin
Thanks for pointing these out. Most have already been brought up by other testers, so we are working on a fix for the beta. The amazon-elements stock messages are a new bug, so we will add that to the fix list.Thanks for looking so thoroughly.
Warmest regards,
DonHey Don,
My issue was never resolved as this thread kinda went off into other problems.
Example
https://dragonrings.net/2014/04/dragon-eye-ring/I think it may be because of sizing issues but have been unable to figure it out.
Thanks
So the clue may be when adding the Amazon item to look up for the parent asin, but when checking the updates to look up the asin.
Please note this code is for development purposes only, and for illustration. Do not use on a production website or with this plugin as is.
So when adding a new item using the response groups which holds all the data:
public function getItemByAsin($parent_asin) { $parameters = array("Operation" => "ItemLookup", "ItemId" => $parent_asin, "Availability" => 'Available', "ResponseGroup" => "ItemAttributes,OfferFull,Images,EditorialReview,Variations"); $xml_response = $this->queryAmazon($parameters); return $this->verifyXmlResponse($xml_response); }
Then to check any changes in pricing and availability:
public function checkAvailabilityByAsin($asin) { $parameters = array("Operation" => "ItemLookup", "ItemId" => $asin, "Availability" => 'Available', "ResponseGroup" => "ItemAttributes,Offers"); $xml_response = $this->queryAmazon($parameters); return $this->verifyXmlResponse($xml_response); }
This addresses the concern of the amount of data requested when doing look ups.
There are then two possible ways to check for the asins if I understand correctly. Either by making a new call for each asin or putting the asins in a comma seperated row. So: asin, asin, asin, asin. This will mean there is only one call, possibly? As Amazon has a limit on the amount of calls one is allowed to make per hour, from what I understand from the documentation. There might be a problem in doing it that way, as for some I’m getting an XML error, at which point it returns no values for that list. Looking each asin up seperately avoids that, because it checks each asin individually instead of a whole ‘group’.
The result from the asins can then be used to update all items under a parent asin.
My issue was never resolved as this thread kinda went off into other problems.
No offense, but it didn’t actually. Sorry, it appeared to you that way. Trying to figure out what is going wrong. It is not easy by a long shot. Took months for me to just understand the relevant PHP code and Amazon API. Thank you for your understanding. Feel free to jump in and help solve it. ??
To find the parent asin of an item based on a value entered in a form:
/* * Look up the asin, and find the parent asin */ function FindParentAsin() { $asinToLookUp = sanitize_text_field($_POST['asin']); if (!empty($asinToLookUp)) { $obj = new AmazonProductAPI(); try { // Check if the ASIN given is the parent asin, to make sure we get the variants $xmlResult = $obj->checkIfParentAsin($asinToLookUp); } catch (Exception $e) { // Display error message if there is an error with loading the XML echo '<p>There was an error with the XML</p>'; } if (!empty($xmlResult)) { $parentAsin = sanitize_text_field($xmlResult->Items->Item->ParentASIN); if (!empty($parentAsin)) { $asinResult['asin'] = sanitize_text_field($xmlResult->Items->Item->ASIN); $asinResult['parentAsin'] = $parentAsin; return $asinResult; } } } }
Please note this code is for development purposes only, and for illustration. Do not use on a production website or with this plugin as is. One could for example register the URL variable in WordPress using the add_query_vars_filter.
What it is intented to do is it looks up the parent asin whether someone is looking up the asin or the parent asin in a form. There are several variations of how the asins value can be used with Amazon based on the type of item it is for example. Some items may only have a parent asin for example. From what I understand an asin always has a parent asin.
To fully proces the XML result, the code depends on what you want to attain. However using the parent asin one is able to retrieve data from Amazon, including those from the asins, such as whether an item is in stock.
From what I understand Amazon recommends to look for the ‘offerListingId’ to check whether an item is in stock, and not just rely on the availability parameter in the lookup request. Also within the XML tree, availability refers to shipping availability, and not item availability, which can be kind of confusing. See also for more information:
https://docs.aws.amazon.com/AWSECommerceService/latest/DG/CHAP_ReturningPriceAndAvailabilityInformation-itemsearch.html
https://docs.aws.amazon.com/AWSECommerceService/latest/DG/ReturningOnlyAvailableItems.htmlNote that shipping availability only applies to Amazon in the docs, and not to other sellers according to this:
https://docs.aws.amazon.com/AWSECommerceService/latest/DG/AvailabilityValues.html
https://docs.aws.amazon.com/AWSECommerceService/latest/DG/ParameterRestrictionsforAvailability.htmlI don’t know if the same counts for the ‘offerListingId’. It doesn’t say it does in the Docs, but that would have to be tested further, or asked at Amazon.
Hope it helps. ??
Just an quick update:
1. The reason looking up an asin list gave errors was possibly because one can only check a maximum of 10 asins per lookup from what I understand. Given that then it could be better to look up an item per parent asin, as these contain the asins, and thus reduce the amount of calls needed. Whether or not to look up the parent asins in a list to reduce on the number of calls is something to be considered.
See also the following page under ‘ItemId’ description in the table:
https://docs.aws.amazon.com/AWSECommerceService/latest/DG/ItemLookup.html
2. It is possible to look up the asin OfferListingId based on the parent asin. The responsegroup to look up the OfferListingId based on parent asin is Variations. So far I’ve found the ItemAttributes group needed as well so for ResponseGroup in the look up one would use e.g:"ResponseGroup" => "ItemAttributes,Variations"
3. According to this page OfferlistingId is used for all products regardless of merchant:
https://docs.aws.amazon.com/AWSECommerceService/latest/DG/CheckingforanOfferListingID.html4. To check whether the asin looked up when adding a new item is the parent asin, and to return the parent asin, one only needs to use the ItemAttributes response group.
Hope this helps document the process, and helps other solve the issue of updating the information when there are variations.
This code will check the parent asins by batch of 10 per call, and checks the stock of the item variations. This should be a step towards fixing the issue. This code would have to be adapted for the plugin before it works.
Unfortunately it has been quiet around this plugin, and I don’t know how active this plugin is anymore, however considering how many (plugins) are suffering the same issue, hope the code helps working towards a solution.
function CheckAvailability() { $storedAvailableAsinData = AsinsToCheckAvailability(); if (!empty($storedAvailableAsinData)) { foreach ($storedAvailableAsinData as $availableAsinData) { $postId = $availableAsinData['postId']; $parentAsin = $availableAsinData['parentAsin']; if (!empty($parentAsin)) { $asinAvailableDataFromXml[$parentAsin]['postId'] = $postId; $parentAsinList[] = $parentAsin; } } $parentAsinListChunked = array_chunk($parentAsinList, 10); $count = 0; foreach ($parentAsinListChunked as $chunk) { $count++; $parentAsinsToUpdate = implode(',', $chunk); if ($count > 0) { if (!empty($parentAsinsToUpdate)) { $availabilityDataFromAmazon = FindAsinDataForAvailability($parentAsinsToUpdate); sleep(1); if (!empty($availabilityDataFromAmazon)) { $items = $availabilityDataFromAmazon->Items->Item; foreach ($items as $value) { $parentAsin = sanitize_text_field($value->ParentASIN); $asinAvailableDataFromXml[$parentAsin]['detailPageUrl'] = esc_url($value->DetailPageURL); if ($value->Variations->TotalVariations > 0) { $item[$parentAsin] = $value->Variations; } else { $asinAvailableDataFromXml[$parentAsin]['noVariations'] = 'Currently unavailable.'; } } foreach ($item as $parentAsin => $value) { $variations = $value->Item; if (!empty($variations)) { foreach ($variations as $value) { $parentAsin = sanitize_text_field($value->ParentASIN); $asin = sanitize_text_field($value->ASIN); $asinAvailableDataFromXml[$parentAsin]['variation'][$asin]['parentAsin'] = $parentAsin; $asinAvailableDataFromXml[$parentAsin]['variation'][$asin]['asin'] = $asin; $asinAvailableDataFromXml[$parentAsin]['variation'][$asin]['merchant'] = sanitize_text_field($value->Offers->Offer->Merchant->Name); $asinAvailableDataFromXml[$parentAsin]['variation'][$asin]['condition'] = sanitize_text_field($value->Offers->Offer->OfferAttributes->Condition); $asinAvailableDataFromXml[$parentAsin]['variation'][$asin]['offerListingId'] = sanitize_text_field($value->Offers->Offer->OfferListing->OfferListingId); $asinAvailableDataFromXml[$parentAsin]['variation'][$asin]['offerPrice'] = sanitize_text_field($value->Offers->Offer->OfferListing->Price->FormattedPrice); $asinAvailableDataFromXml[$parentAsin]['variation'][$asin]['offerAmountSaved'] = sanitize_text_field($value->Offers->Offer->OfferListing->AmountSaved->FormattedPrice); $asinAvailableDataFromXml[$parentAsin]['variation'][$asin]['shippingAvailability'] = sanitize_text_field($value->Offers->Offer->OfferListing->Availability); } } } } } } } return $asinAvailableDataFromXml; } }
Please note this is development code, and may not work in all use cases, nor should one just copy and paste it to a production site. It may work, or it may still have bugs.
1. The sleep function is there because Amazon has a throttle on calls, depending on the type of account one has, according to the information in the link. From what I gather this is what caused the error previously (there have been no errors since):
https://affiliate-program.amazon.com/gp/advertising/api/detail/faq.html
2. The count function is there for testing. E.g. so it won’t run a whole batch, but allow it to run smaller batches which is easier during testing.
3. The data this function takes coming in is:$storedAvailableAsinData[$postId]['postId'] = $postId; $storedAvailableAsinData[$postId]['parentAsin'] = $parentAsin;
4. The function uses the following responsegroups (although it could be adapted to use other responsegroups):
"ResponseGroup" => "ItemAttributes, VariationOffers");
5. The output processing and how the data is updated depends on the use case.
Feedback is more than welcome.
- The topic ‘Out of Stock where price should be’ is closed to new replies.