Skip to content
This repository has been archived by the owner on Mar 17, 2022. It is now read-only.

Fixing #299 #300

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -3,3 +3,4 @@
.php_cs.cache
*.gif
*.gif
.idea
20 changes: 12 additions & 8 deletions src/Hyyan/WPI/Product/Stock.php
Expand Up @@ -88,10 +88,14 @@ public function increaseStock($change)
*/
protected function change(\WC_Order_Item_Product $item, $action = self::STOCK_REDUCE_ACTION)
{
$productID = Utilities::get_order_item_productid($item);
$productObject = wc_get_product($productID);
/* Proper way to get to object so it works with IPN calls */
$productObject = $item->get_product();
$productID = $productObject->get_id();

//$productLang = pll_get_post_language($productID); //#184
$orderLang = pll_get_post_language($item->get_order_id());

/* TODO check if variations are also subject to IPN problem issue #299 */
$variationID = Utilities::get_order_item_variationid($item);

/* Handle Products */
Expand All @@ -113,15 +117,15 @@ protected function change(\WC_Order_Item_Product $item, $action = self::STOCK_RE
$isManageStock = $productObject->managing_stock();
$isVariation = $variationID && $variationID > 0;

//in 3.0.8 at least, current lang item must not be removed from array if is variable
if ($isManageStock && (!$isVariation)) {
/* Remove the current product from translation array */
unset($translations[$orderLang]);
}

/* Sync stock for all translation */
foreach ($translations as $ID) {

//in 3.0.8 at least, current lang item must not be removed from array if is variable
if ($isManageStock && (!$isVariation)) {
/* Skip the current product */
if ($ID == $productID) continue;
}

/* Only if product is managing stock
* including variation with stock managed at product level*/
if ($isManageStock) {
Expand Down