-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #427 from magento-folks/grouped_product
[Folks] Grouped product + bugs
- Loading branch information
Showing
16 changed files
with
384 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
/** | ||
* Copyright © 2016 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Catalog\Model\Product\Link; | ||
|
||
/** | ||
* Class Converter | ||
*/ | ||
class Converter | ||
{ | ||
/** | ||
* Convert product links info to array indexed by sku | ||
* | ||
* @param \Magento\Catalog\Model\Product[] $products | ||
* @return array | ||
*/ | ||
protected function indexBySku(array $products) | ||
{ | ||
$converted = []; | ||
foreach($products as $product) { | ||
$converted[$product->getSku()] = $product; | ||
} | ||
return $converted; | ||
} | ||
|
||
/** | ||
* @param \Magento\Catalog\Model\Product $entity | ||
* @return array | ||
*/ | ||
public function convertLinksToGroupedArray($entity) | ||
{ | ||
$basicData = $entity->getProductLinks(); | ||
$associatedProducts = $entity->getTypeInstance()->getAssociatedProducts($entity); | ||
$associatedProducts = $this->indexBySku($associatedProducts); | ||
|
||
/** @var \Magento\Catalog\Api\Data\ProductLinkInterface $link */ | ||
foreach ($basicData as $link) { | ||
$info = $link->getData(); | ||
if ($link->getLinkType() == 'associated') { | ||
$info['id'] = $associatedProducts[$link->getLinkedProductSku()]->getId(); | ||
} | ||
$info = array_merge($info, $link->getExtensionAttributes()->__toArray()); | ||
$linksAsArray[$link->getLinkType()][] = $info; | ||
} | ||
return $linksAsArray; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
/** | ||
* Copyright © 2016 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Catalog\Model\Product\Link; | ||
|
||
class Resolver | ||
{ | ||
/** | ||
* @var \Magento\Framework\App\RequestInterface | ||
*/ | ||
protected $request; | ||
|
||
/** | ||
* @var null|array | ||
*/ | ||
protected $links = null; | ||
|
||
public function __construct( | ||
\Magento\Framework\App\RequestInterface $request | ||
) { | ||
$this->request = $request; | ||
} | ||
|
||
|
||
/** | ||
* Get stored value. | ||
* Fallback to request if none. | ||
* | ||
* @return array|null | ||
*/ | ||
public function getLinks() | ||
{ | ||
if (null === $this->links) { | ||
$this->links = (array)$this->request->getParam('links', []); | ||
} | ||
return $this->links; | ||
} | ||
|
||
/** | ||
* Override link data from request | ||
* | ||
* @param array|null $links | ||
*/ | ||
public function override($links) | ||
{ | ||
$this->links = $links; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.