Skip to content

Commit

Permalink
MAGETWO-46472: Prepare pull request
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Logvin committed Dec 7, 2015
1 parent bf4e733 commit 0f00630
Show file tree
Hide file tree
Showing 372 changed files with 13,250 additions and 6,684 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
) {
Expand All @@ -139,7 +141,8 @@ public function __construct(
$attributeColFactory,
$_typeFactory,
$linkTypeProvider,
$rowCustomizer
$rowCustomizer,
$metadataPool
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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',
[
Expand Down Expand Up @@ -344,7 +356,8 @@ protected function setUp()
$this->linkTypeProvider,
$this->rowCustomizer,
$this->storeResolver,
$this->groupRepository
$this->groupRepository,
$this->metadataPool
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand All @@ -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) {
Expand All @@ -55,7 +127,6 @@ public function afterInitialize(
$product->setCanSaveBundleSelections(
(bool)$this->request->getPost('affect_bundle_product_selections') && !$product->getCompositeReadonly()
);

return $product;
}
}
17 changes: 14 additions & 3 deletions app/code/Magento/Bundle/Model/OptionRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
65 changes: 0 additions & 65 deletions app/code/Magento/Bundle/Model/Plugin/BundleLoadOptions.php

This file was deleted.

82 changes: 0 additions & 82 deletions app/code/Magento/Bundle/Model/Plugin/BundleSaveOptions.php

This file was deleted.

Loading

0 comments on commit 0f00630

Please sign in to comment.