Skip to content

Commit

Permalink
Fixing hyyan#299
Browse files Browse the repository at this point in the history
  • Loading branch information
tii committed Jan 23, 2018
1 parent c7f3db8 commit d42005a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
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

0 comments on commit d42005a

Please sign in to comment.