From d42005a48ae5330f2b45d526c9a8744573b2e628 Mon Sep 17 00:00:00 2001 From: tii Date: Tue, 23 Jan 2018 10:16:40 +0100 Subject: [PATCH] Fixing #299 --- .gitignore | 1 + src/Hyyan/WPI/Product/Stock.php | 20 ++++++++++++-------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index d4c9c26..193232b 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ .php_cs.cache *.gif *.gif +.idea \ No newline at end of file diff --git a/src/Hyyan/WPI/Product/Stock.php b/src/Hyyan/WPI/Product/Stock.php index 63eafe0..d26b407 100644 --- a/src/Hyyan/WPI/Product/Stock.php +++ b/src/Hyyan/WPI/Product/Stock.php @@ -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 */ @@ -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) {