Skip to content

Commit 8b0f53a

Browse files
committed
Merge remote-tracking branch 'magento-chaika/MC-20490' into MPI-PR-10012019
2 parents 0e75b77 + c989fcb commit 8b0f53a

File tree

4 files changed

+69
-6
lines changed

4 files changed

+69
-6
lines changed

app/code/Magento/CatalogGraphQl/Model/Resolver/Category/DataProvider/Breadcrumbs.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,11 @@ public function __construct(
2929
}
3030

3131
/**
32+
* Get breadcrumbs data
33+
*
3234
* @param string $categoryPath
3335
* @return array
36+
* @throws \Magento\Framework\Exception\LocalizedException
3437
*/
3538
public function getData(string $categoryPath): array
3639
{
@@ -41,7 +44,7 @@ public function getData(string $categoryPath): array
4144

4245
if (count($parentCategoryIds)) {
4346
$collection = $this->collectionFactory->create();
44-
$collection->addAttributeToSelect(['name', 'url_key']);
47+
$collection->addAttributeToSelect(['name', 'url_key', 'url_path']);
4548
$collection->addAttributeToFilter('entity_id', $parentCategoryIds);
4649

4750
foreach ($collection as $category) {
@@ -50,6 +53,7 @@ public function getData(string $categoryPath): array
5053
'category_name' => $category->getName(),
5154
'category_level' => $category->getLevel(),
5255
'category_url_key' => $category->getUrlKey(),
56+
'category_url_path' => $category->getUrlPath(),
5357
];
5458
}
5559
}

app/code/Magento/CatalogGraphQl/etc/schema.graphqls

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ type Breadcrumb @doc(description: "Breadcrumb item."){
223223
category_name: String @doc(description: "Category name.")
224224
category_level: Int @doc(description: "Category level.")
225225
category_url_key: String @doc(description: "Category URL key.")
226+
category_url_path: String @doc(description: "Category URL path.")
226227
}
227228

228229
type CustomizableRadioOption implements CustomizableOptionInterface @doc(description: "CustomizableRadioOption contains information about a set of radio buttons that are defined as part of a customizable option.") {

app/code/Magento/CatalogWidget/Model/Rule/Condition/Product.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
use Magento\Catalog\Api\Data\ProductInterface;
1313
use Magento\Catalog\Model\ProductCategoryList;
14+
use Magento\Store\Model\Store;
1415

1516
/**
1617
* Class Product
@@ -106,7 +107,7 @@ function ($attribute) {
106107
}
107108

108109
/**
109-
* {@inheritdoc}
110+
* @inheritdoc
110111
*
111112
* @param array &$attributes
112113
* @return void
@@ -164,6 +165,8 @@ public function addToCollection($collection)
164165
}
165166

166167
/**
168+
* Adds Attributes that belong to Global Scope
169+
*
167170
* @param \Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute
168171
* @param \Magento\Catalog\Model\ResourceModel\Product\Collection $collection
169172
* @return $this
@@ -200,6 +203,8 @@ protected function addGlobalAttribute(
200203
}
201204

202205
/**
206+
* Adds Attributes that don't belong to Global Scope
207+
*
203208
* @param \Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute
204209
* @param \Magento\Catalog\Model\ResourceModel\Product\Collection $collection
205210
* @return $this
@@ -208,7 +213,7 @@ protected function addNotGlobalAttribute(
208213
\Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute,
209214
\Magento\Catalog\Model\ResourceModel\Product\Collection $collection
210215
) {
211-
$storeId = $this->storeManager->getStore()->getId();
216+
$storeId = $this->storeManager->getStore()->getId();
212217
$values = $collection->getAllAttributeValues($attribute);
213218
$validEntities = [];
214219
if ($values) {
@@ -218,7 +223,9 @@ protected function addNotGlobalAttribute(
218223
$validEntities[] = $entityId;
219224
}
220225
} else {
221-
if ($this->validateAttribute($storeValues[\Magento\Store\Model\Store::DEFAULT_STORE_ID])) {
226+
if (isset($storeValues[Store::DEFAULT_STORE_ID]) &&
227+
$this->validateAttribute($storeValues[Store::DEFAULT_STORE_ID])
228+
) {
222229
$validEntities[] = $entityId;
223230
}
224231
}
@@ -236,7 +243,7 @@ protected function addNotGlobalAttribute(
236243
}
237244

238245
/**
239-
* {@inheritdoc}
246+
* @inheritdoc
240247
*
241248
* @return string
242249
*/
@@ -257,7 +264,7 @@ public function getMappedSqlField()
257264
}
258265

259266
/**
260-
* {@inheritdoc}
267+
* @inheritdoc
261268
*
262269
* @param \Magento\Catalog\Model\ResourceModel\Product\Collection $productCollection
263270
* @return $this

dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/CategoryTest.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,57 @@ public function testAnchorCategory()
502502
$this->assertEquals($expectedResponse, $response);
503503
}
504504

505+
/**
506+
* @magentoApiDataFixture Magento/Catalog/_files/categories.php
507+
*/
508+
public function testBreadCrumbs()
509+
{
510+
/** @var CategoryCollection $categoryCollection */
511+
$categoryCollection = $this->objectManager->create(CategoryCollection::class);
512+
$categoryCollection->addFieldToFilter('name', 'Category 1.1.1');
513+
/** @var CategoryInterface $category */
514+
$category = $categoryCollection->getFirstItem();
515+
$categoryId = $category->getId();
516+
$this->assertNotEmpty($categoryId, "Preconditions failed: category is not available.");
517+
$query = <<<QUERY
518+
{
519+
category(id: {$categoryId}) {
520+
name
521+
breadcrumbs {
522+
category_id
523+
category_name
524+
category_level
525+
category_url_key
526+
category_url_path
527+
}
528+
}
529+
}
530+
QUERY;
531+
$response = $this->graphQlQuery($query);
532+
$expectedResponse = [
533+
'category' => [
534+
'name' => 'Category 1.1.1',
535+
'breadcrumbs' => [
536+
[
537+
'category_id' => 3,
538+
'category_name' => "Category 1",
539+
'category_level' => 2,
540+
'category_url_key' => "category-1",
541+
'category_url_path' => "category-1"
542+
],
543+
[
544+
'category_id' => 4,
545+
'category_name' => "Category 1.1",
546+
'category_level' => 3,
547+
'category_url_key' => "category-1-1",
548+
'category_url_path' => "category-1/category-1-1"
549+
],
550+
]
551+
]
552+
];
553+
$this->assertEquals($expectedResponse, $response);
554+
}
555+
505556
/**
506557
* @param ProductInterface $product
507558
* @param array $actualResponse

0 commit comments

Comments
 (0)