Skip to content

Commit

Permalink
Merge pull request #2318 from magento-honey-badgers/MAGETWO-89292-SDL
Browse files Browse the repository at this point in the history
[honey] GraphQL sprint 10
  • Loading branch information
cpartica authored Apr 6, 2018
2 parents 286b00f + 7e7ad98 commit eb09566
Show file tree
Hide file tree
Showing 372 changed files with 22,710 additions and 7,192 deletions.
23 changes: 21 additions & 2 deletions app/code/Magento/Bundle/Model/ResourceModel/Option/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\Ab
*/
protected $_selectionsAppended = false;

/**
* @var int[]
*/
private $productIds = [];

/**
* Init model and resource model
*
Expand Down Expand Up @@ -94,20 +99,34 @@ public function joinValues($storeId)
*/
public function setProductIdFilter($productId)
{
$this->productIds[] = $productId;

$productTable = $this->getTable('catalog_product_entity');
$linkField = $this->getConnection()->getAutoIncrementField($productTable);
$this->getSelect()->join(
['cpe' => $productTable],
'cpe.'.$linkField.' = main_table.parent_id',
[]
)->where(
"cpe.entity_id = ?",
$productId
"cpe.entity_id = (?)",
$this->productIds
);

return $this;
}

/**
* Clear product id's after load to insure valid future usage of collection.
*
* @return $this
*/
protected function _afterLoad()
{
$this->productIds = [];

return parent::_afterLoad();
}

/**
* Set product link filter
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\BundleGraphQl\Model;

use Magento\Framework\GraphQl\Config\Data\TypeResolverInterface;
use Magento\Framework\GraphQl\Query\Resolver\TypeResolverInterface;

/**
* {@inheritdoc}
Expand All @@ -16,10 +17,11 @@ class BundleProductTypeResolver implements TypeResolverInterface
/**
* {@inheritdoc}
*/
public function resolveType(array $data)
public function resolveType(array $data) : string
{
if (isset($data['type_id']) && $data['type_id'] == 'bundle') {
return 'BundleProduct';
}
return '';
}
}

This file was deleted.

62 changes: 62 additions & 0 deletions app/code/Magento/BundleGraphQl/Model/Resolver/BundleItemLinks.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\BundleGraphQl\Model\Resolver;

use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
use Magento\BundleGraphQl\Model\Resolver\Links\Collection;
use Magento\Framework\GraphQl\Config\Element\Field;
use Magento\Framework\GraphQl\Query\Resolver\Value;
use Magento\Framework\GraphQl\Query\Resolver\ValueFactory;
use Magento\Framework\GraphQl\Query\ResolverInterface;

/**
* {@inheritdoc}
*/
class BundleItemLinks implements ResolverInterface
{
/**
* @var Collection
*/
private $linkCollection;

/**
* @var ValueFactory
*/
private $valueFactory;

/**
* @param Collection $linkCollection
* @param ValueFactory $valueFactory
*/
public function __construct(
Collection $linkCollection,
ValueFactory $valueFactory
) {
$this->linkCollection = $linkCollection;
$this->valueFactory = $valueFactory;
}

/**
* {@inheritDoc}
*/
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null) : Value
{
if (!isset($value['option_id']) || !isset($value['parent_id'])) {
$result = function () {
return null;
};
return $this->valueFactory->create($result);
}
$this->linkCollection->addIdFilters((int)$value['option_id'], (int)$value['parent_id']);
$result = function () use ($value) {
return $this->linkCollection->getLinksForOptionId((int)$value['option_id']);
};

return $this->valueFactory->create($result);
}
}
85 changes: 85 additions & 0 deletions app/code/Magento/BundleGraphQl/Model/Resolver/BundleItems.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\BundleGraphQl\Model\Resolver;

use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
use Magento\Bundle\Model\Product\Type;
use Magento\BundleGraphQl\Model\Resolver\Options\Collection;
use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Framework\EntityManager\MetadataPool;
use Magento\Framework\GraphQl\Config\Element\Field;
use Magento\Framework\GraphQl\Query\Resolver\Value;
use Magento\Framework\GraphQl\Query\Resolver\ValueFactory;
use Magento\Framework\GraphQl\Query\ResolverInterface;

/**
* {@inheritdoc}
*/
class BundleItems implements ResolverInterface
{
/**
* @var Collection
*/
private $bundleOptionCollection;

/**
* @var ValueFactory
*/
private $valueFactory;

/**
* @var MetadataPool
*/
private $metdataPool;

/**
* @param Collection $bundleOptionCollection
* @param ValueFactory $valueFactory
* @param MetadataPool $metdataPool
*/
public function __construct(
Collection $bundleOptionCollection,
ValueFactory $valueFactory,
MetadataPool $metdataPool
) {
$this->bundleOptionCollection = $bundleOptionCollection;
$this->valueFactory = $valueFactory;
$this->metdataPool = $metdataPool;
}

/**
* Fetch and format bundle option items.
*
* {@inheritDoc}
*/
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null) : Value
{
$linkField = $this->metdataPool->getMetadata(ProductInterface::class)->getLinkField();
if ($value['type_id'] !== Type::TYPE_CODE
|| !isset($value[$linkField])
|| !isset($value[ProductInterface::SKU])
) {
$result = function () {
return null;
};
return $this->valueFactory->create($result);
}

$this->bundleOptionCollection->addParentFilterData(
(int)$value[$linkField],
(int)$value['entity_id'],
$value[ProductInterface::SKU]
);

$result = function () use ($value, $linkField) {
return $this->bundleOptionCollection->getOptionsByParentId((int)$value[$linkField]);
};

return $this->valueFactory->create($result);
}
}
Loading

0 comments on commit eb09566

Please sign in to comment.