{"id":13409237,"date":"2020-09-15T15:14:53","date_gmt":"2020-09-15T15:14:53","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/strange-stock-reduction-issue\/"},"modified":"2020-09-15T15:14:53","modified_gmt":"2020-09-15T15:14:53","slug":"strange-stock-reduction-issue","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/strange-stock-reduction-issue\/","title":{"rendered":"Strange Stock Reduction Issue"},"content":{"rendered":"<p>Hi,<\/p>\n<p>We have two stock locations, both set to auto allocate. Location A has 70 in stock, Location B has 64 in stock for a particular product. When the user completes the order, we log into the admin order view and we can see the location select but both locations have a quantity of 0 inputted, which appears to be that location stock was not deducated. After some digging i found out that in the source code, both locations were set with allocated_quantity = line_item_quantity. Which means it was trying to deduct from both locations, but since you have some logic which prevents that (see below) the stock is never reduced.<br \/>\nfile:  helper-slw-order-item.php<\/p>\n<pre><code> if (array_sum($locationStockMap) !== $lineItem-&gt;get_quantity()) {\n                    continue;\n                }\n<\/code><\/pre>\n<p>The offending code appears to be here: <code>$stockAllocation = array_merge($userStockLocation, $stockAllocation);<\/code> file: class-slw-order-item.php<\/p>\n<p>$userStockLocation contains the user selected stock location, but then since we merge we also have $stockAllocation which has the other location. So the final <code>$stockAllocation<\/code> contains both locations, which results in trying to deduct from 2 locations. <\/p>\n<p>Any idea what is going on here? When i change the line above to just be: <code>$stockAllocation = $userStockLocation;<\/code> it successfully deducts the correct stock from the single location.<\/p>\n<p>Thanks<\/p>\n","protected":false},"template":"","class_list":["post-13409237","topic","type-topic","status-publish","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/13409237","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/13409237\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=13409237"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}