Permalink
Browse files

MAGETWO-46472: Prepare pull request

  • Loading branch information...
Michael Logvin
Michael Logvin committed Dec 7, 2015
1 parent bf4e733 commit 0f0063045b50e1dafa260b97a1a00bf9fa92e74b
Showing 372 changed files with 13,250 additions and 6,684 deletions.
@@ -95,6 +95,7 @@ class AdvancedPricing extends \Magento\CatalogImportExport\Model\Export\Product
* @param \Magento\CatalogImportExport\Model\Export\Product\Type\Factory $_typeFactory
* @param \Magento\Catalog\Model\Product\LinkTypeProvider $linkTypeProvider
* @param \Magento\CatalogImportExport\Model\Export\RowCustomizerInterface $rowCustomizer
* @param \Magento\Framework\Model\Entity\MetadataPool $metadataPool
* @param ImportProduct\StoreResolver $storeResolver
* @param \Magento\Customer\Api\GroupRepositoryInterface $groupRepository
* @throws \Magento\Framework\Exception\LocalizedException
@@ -117,6 +118,7 @@ public function __construct(
\Magento\CatalogImportExport\Model\Export\Product\Type\Factory $_typeFactory,
\Magento\Catalog\Model\Product\LinkTypeProvider $linkTypeProvider,
\Magento\CatalogImportExport\Model\Export\RowCustomizerInterface $rowCustomizer,
\Magento\Framework\Model\Entity\MetadataPool $metadataPool,
\Magento\CatalogImportExport\Model\Import\Product\StoreResolver $storeResolver,
\Magento\Customer\Api\GroupRepositoryInterface $groupRepository
) {
@@ -139,7 +141,8 @@ public function __construct(
$attributeColFactory,
$_typeFactory,
$linkTypeProvider,
$rowCustomizer
$rowCustomizer,
$metadataPool
);
}
@@ -107,6 +107,11 @@ class AdvancedPricingTest extends \PHPUnit_Framework_TestCase
*/
protected $groupRepository;
/**
* @var \Magento\Framework\Model\Entity\MetadataPool|\PHPUnit_Framework_MockObject_MockObject
*/
protected $metadataPool;
/**
* @var \Magento\ImportExport\Model\Export\Adapter\AbstractAdapter| \PHPUnit_Framework_MockObject_MockObject
*/
@@ -285,6 +290,13 @@ protected function setUp()
'',
false
);
$this->metadataPool = $this->getMock(
'\Magento\Framework\Model\Entity\MetadataPool',
[],
[],
'',
false
);
$this->writer = $this->getMock(
'Magento\ImportExport\Model\Export\Adapter\AbstractAdapter',
[
@@ -344,7 +356,8 @@ protected function setUp()
$this->linkTypeProvider,
$this->rowCustomizer,
$this->storeResolver,
$this->groupRepository
$this->groupRepository,
$this->metadataPool
);
}
@@ -5,19 +5,59 @@
*/
namespace Magento\Bundle\Controller\Adminhtml\Product\Initialization\Helper\Plugin;
use \Magento\Bundle\Api\Data\OptionInterfaceFactory as OptionFactory;
use \Magento\Bundle\Api\Data\LinkInterfaceFactory as LinkFactory;
use Magento\Catalog\Api\ProductRepositoryInterface as ProductRepository;
use Magento\Store\Model\StoreManagerInterface as StoreManager;
use Magento\Framework\App\RequestInterface;
class Bundle
{
/**
* @var \Magento\Framework\App\RequestInterface
* @var RequestInterface
*/
protected $request;
/**
* @param \Magento\Framework\App\RequestInterface $request
* @var OptionFactory
*/
protected $optionFactory;
/**
* @var LinkFactory
*/
protected $linkFactory;
/**
* @var ProductRepository
*/
protected $productRepository;
/**
* @var StoreManager
*/
protected $storeManager;
/**
* @param RequestInterface $request
* @param OptionFactory $optionFactory
* @param LinkFactory $linkFactory
* @param ProductRepository $productRepository
* @param StoreManager $storeManager
*/
public function __construct(\Magento\Framework\App\RequestInterface $request)
{
public function __construct(
RequestInterface $request,
OptionFactory $optionFactory,
LinkFactory $linkFactory,
ProductRepository $productRepository,
StoreManager $storeManager
) {
$this->request = $request;
$this->optionFactory = $optionFactory;
$this->linkFactory = $linkFactory;
$this->productRepository = $productRepository;
$this->storeManager =$storeManager;
}
/**
@@ -34,15 +74,47 @@ public function afterInitialize(
\Magento\Catalog\Controller\Adminhtml\Product\Initialization\Helper $subject,
\Magento\Catalog\Model\Product $product
) {
if (($selections = $this->request->getPost('bundle_selections')) && !$product->getCompositeReadonly()) {
$product->setBundleSelectionsData($selections);
}
if (($items = $this->request->getPost('bundle_options')) && !$product->getCompositeReadonly()) {
$product->setBundleOptionsData($items);
}
if (($selections = $this->request->getPost('bundle_selections')) && !$product->getCompositeReadonly()) {
$product->setBundleSelectionsData($selections);
if ($product->getBundleOptionsData()) {
$options = [];
foreach ($product->getBundleOptionsData() as $key => $optionData) {
if (!(bool)$optionData['delete']) {
$option = $this->optionFactory->create(['data' => $optionData]);
$option->setSku($product->getSku());
$option->setOptionId(null);
$links = [];
$bundleLinks = $product->getBundleSelectionsData();
if (!empty($bundleLinks[$key])) {
foreach ($bundleLinks[$key] as $linkData) {
if (!(bool)$linkData['delete']) {
$link = $this->linkFactory->create(['data' => $linkData]);
$linkProduct = $this->productRepository->getById($linkData['product_id']);
$link->setSku($linkProduct->getSku());
$link->setQty($linkData['selection_qty']);
$links[] = $link;
}
}
$option->setProductLinks($links);
$options[] = $option;
}
}
}
$extension = $product->getExtensionAttributes();
$extension->setBundleProductOptions($options);
$product->setExtensionAttributes($extension);
}
if ($product->getPriceType() == '0' && !$product->getOptionsReadonly()) {
if (
$product->getPriceType() === \Magento\Bundle\Model\Product\Price::PRICE_TYPE_DYNAMIC
&& !$product->getOptionsReadonly()
) {
$product->setCanSaveCustomOptions(true);
if ($customOptions = $product->getProductOptions()) {
foreach (array_keys($customOptions) as $key) {
@@ -55,7 +127,6 @@ public function afterInitialize(
$product->setCanSaveBundleSelections(
(bool)$this->request->getPost('affect_bundle_product_selections') && !$product->getCompositeReadonly()
);
return $product;
}
}
@@ -60,6 +60,11 @@ class OptionRepository implements \Magento\Bundle\Api\ProductOptionRepositoryInt
*/
protected $dataObjectHelper;
/**
* @var \Magento\Framework\Model\Entity\MetadataPool
*/
protected $metadataPool;
/**
* @param \Magento\Catalog\Api\ProductRepositoryInterface $productRepository
* @param Product\Type $type
@@ -80,8 +85,10 @@ public function __construct(
\Magento\Bundle\Api\ProductLinkManagementInterface $linkManagement,
\Magento\Bundle\Model\Product\OptionList $productOptionList,
\Magento\Bundle\Model\Product\LinksList $linkList,
\Magento\Framework\Api\DataObjectHelper $dataObjectHelper
\Magento\Framework\Api\DataObjectHelper $dataObjectHelper,
\Magento\Framework\Model\Entity\MetadataPool $metadataPool
) {
$this->metadataPool = $metadataPool;
$this->productRepository = $productRepository;
$this->type = $type;
$this->optionFactory = $optionFactory;
@@ -166,8 +173,12 @@ public function save(
\Magento\Catalog\Api\Data\ProductInterface $product,
\Magento\Bundle\Api\Data\OptionInterface $option
) {
$option->setStoreId($this->storeManager->getStore()->getId());
$option->setParentId($product->getId());
$option->getResource()->removeOptionSelections($option->getOptionId());
$metadata = $this->metadataPool->getMetadata(\Magento\Catalog\Api\Data\ProductInterface::class);
$option->setStoreId($product->getStoreId());
$option->setParentId($product->getData($metadata->getLinkField()));
$optionId = $option->getOptionId();
if (!$optionId) {

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit 0f00630

Please sign in to comment.