Skip to content

Commit

Permalink
Merge pull request #46 from daanstokhof/PLUG-65
Browse files Browse the repository at this point in the history
Add unique product id's for "configurable products"
  • Loading branch information
max-geraci authored Nov 13, 2019
2 parents f035200 + 24f4077 commit b59d716
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Model/Paymentmethod/PaymentMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

namespace Paynl\Payment\Model\Paymentmethod;

use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
use Magento\Framework\Api\AttributeValueFactory;
use Magento\Framework\Api\ExtensionAttributesFactory;
use Magento\Framework\App\Config\ScopeConfigInterface;
Expand Down Expand Up @@ -309,13 +310,26 @@ protected function doStartTransaction(Order $order)
$taxAmount = $arrItem['base_price_incl_tax'] - $arrItem['base_price'];
$price = $arrItem['base_price_incl_tax'];
}

$product = array(
'id' => $arrItem['product_id'],
'name' => $arrItem['name'],
'price' => $price,
'qty' => $arrItem['qty_ordered'],
'tax' => $taxAmount,
);

# Product id's must be unique. Combinations of a "Configurable products" share the same product id.
# Each combination of a "configurable product" can be represented by a "simple product".
# The first and only child of the "configurable product" is the "simple product", or combination, chosen by the customer.
# Grab it and replace the product id to guarantee product id uniqueness.
if (isset($arrItem['product_type']) && $arrItem['product_type'] === Configurable::TYPE_CODE) {
$children = $item->getChildrenItems();
$child = array_shift($children);

$product['id'] = $child->getProductId();
}

$arrProducts[] = $product;
}
}
Expand Down

0 comments on commit b59d716

Please sign in to comment.