Skip to content

Commit

Permalink
MAGETWO-44971: [GITHUB] Configurable product issues after saving #2226
Browse files Browse the repository at this point in the history
  • Loading branch information
Michail Slabko committed Nov 18, 2015
1 parent 7049013 commit d4af71b
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 7 deletions.
13 changes: 10 additions & 3 deletions app/code/Magento/Catalog/Controller/Adminhtml/Product/Save.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ public function execute()
$resultRedirect = $this->resultRedirectFactory->create();

$data = $this->getRequest()->getPostValue();
$productAttributeSetId = $this->getRequest()->getParam('set');
$productTypeId = $this->getRequest()->getParam('type');
if ($data) {
try {
$product = $this->initializationHelper->initialize($this->productBuilder->build($this->getRequest()));
Expand All @@ -82,6 +84,8 @@ public function execute()
$product->save();
$this->handleImageRemoveError($data, $product->getId());
$productId = $product->getId();
$productAttributeSetId = $product->getAttributeSetId();
$productTypeId = $product->getTypeId();

/**
* Do copying data to stores
Expand Down Expand Up @@ -132,18 +136,21 @@ public function execute()
return $resultRedirect;
}

if ($redirectBack === 'new' && isset($product)) {
if ($redirectBack === 'new') {
$resultRedirect->setPath(
'catalog/*/new',
['set' => $product->getAttributeSetId(), 'type' => $product->getTypeId()]
['set' => $productAttributeSetId, 'type' => $productTypeId]
);
} elseif ($redirectBack === 'duplicate' && isset($newProduct)) {
$resultRedirect->setPath(
'catalog/*/edit',
['id' => $newProduct->getId(), 'back' => null, '_current' => true]
);
} elseif ($redirectBack) {
$resultRedirect->setPath('catalog/*/edit', ['id' => $productId, '_current' => true]);
$resultRedirect->setPath(
'catalog/*/edit',
['id' => $productId, '_current' => true, 'set' => $productAttributeSetId]
);
} else {
$resultRedirect->setPath('catalog/*/', ['store' => $storeId]);
}
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Catalog/Model/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -1516,7 +1516,7 @@ public function getMediaGalleryImages()
continue;
}
$image['url'] = $this->getMediaConfig()->getMediaUrl($image['file']);
$image['id'] = $image['value_id'];
$image['id'] = !empty($image['value_id']) ? $image['value_id'] : null;
$image['path'] = $directory->getAbsolutePath($this->getMediaConfig()->getMediaPath($image['file']));
$images->addItem(new \Magento\Framework\Object($image));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,9 @@ public function getAffectedFields($object)
$images = (array)$object->getData($this->getAttribute()->getName());
$tableName = $this->_getResource()->getMainTable();
foreach ($images['images'] as $value) {
if (empty($value['value_id'])) {
continue;
}
$data[$tableName][] = [
'attribute_id' => $this->getAttribute()->getAttributeId(),
'value_id' => $value['value_id'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,16 @@
*/
namespace Magento\ConfigurableProduct\Controller\Adminhtml\Product\Initialization\Helper\Plugin;

use Magento\ConfigurableProduct\Model\Product\Type\Configurable as ConfigurableProduct;

class Configurable
{
/** @var \Magento\Framework\App\RequestInterface */
protected $request;

/** @var \Magento\ConfigurableProduct\Model\Product\Type\Configurable */
protected $productType;

/**
* @param \Magento\ConfigurableProduct\Model\Product\Type\Configurable $productType
* @param \Magento\Framework\App\RequestInterface $request
Expand All @@ -35,10 +43,12 @@ public function afterInitialize(
\Magento\Catalog\Model\Product $product
) {
$attributes = $this->request->getParam('attributes');
if (!empty($attributes)) {
if ($product->getTypeId() == ConfigurableProduct::TYPE_CODE && !empty($attributes)) {
$setId = $this->request->getPost('new-variations-attribute-set-id');
$product->setAttributeSetId($setId);
$this->productType->setUsedProductAttributeIds($attributes, $product);

$product->setNewVariationsAttributeSetId($this->request->getPost('new-variations-attribute-set-id'));
$product->setNewVariationsAttributeSetId($setId);
$associatedProductIds = $this->request->getPost('associated_product_ids', []);
$variationsMatrix = $this->request->getParam('variations-matrix', []);
if (!empty($variationsMatrix)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1175,7 +1175,7 @@ protected function _fillSimpleProductData(
$product->setStoreId(
\Magento\Store\Model\Store::DEFAULT_STORE_ID
)->setTypeId(
$postData['weight'] ? \Magento\Catalog\Model\Product\Type::TYPE_SIMPLE : \Magento\Catalog\Model\Product\Type::TYPE_VIRTUAL
\Magento\Catalog\Model\Product\Type::TYPE_SIMPLE
)->setAttributeSetId(
$parentProduct->getNewVariationsAttributeSetId()
);
Expand Down

0 comments on commit d4af71b

Please sign in to comment.