Skip to content
This repository was archived by the owner on Dec 19, 2019. It is now read-only.

Conversation

VoronoyAlexandr
Copy link
Contributor

Description (*)

PR For issue #198 Products: access to related/up-sell/cross-sell product fields
This PR added functionality for query/response with related products.

Manual testing scenarios (*)

Sample request

{
  products(filter: { sku: { eq: "product_dynamic_8" } }) {
    items {
      id
      name
      url_key
      categories {
        id
      }
      crosssell_products {
        items {
          name
          sku
          url_key
          canonical_url
          image {
            url
          }
          price {
            regularPrice {
              amount {
                value
              }
            }
            minimalPrice {
              amount {
                value
              }
            }
            maximalPrice {
              amount {
                value
              }
            }
          }
        }
      }
      upsell_products {
        items {
          name
          sku
          url_key
          canonical_url
          image {
            url
          }
          price {
            regularPrice {
              amount {
                value
              }
            }
            minimalPrice {
              amount {
                value
              }
            }
            maximalPrice {
              amount {
                value
              }
            }
          }
        }
      }
      related_products {
        items {
          name
          sku
          url_key
          canonical_url
          image {
            url
            label
          }
          price {
            regularPrice {
              amount {
                value
                currency
              }
              adjustments {
                amount {
                  value
                  currency
                }
                code
                description
              }
            }
            maximalPrice {
              amount {
                value
                currency
              }
              adjustments {
                amount {
                  value
                  currency
                }
                code
                description
              }
            }
            minimalPrice {
              amount {
                value
                currency
              }
              adjustments {
                amount {
                  value
                  currency
                }
                code
                description
              }
            }
          }
        }
      }
    }
  }
}

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds on Travis CI are green)

/**
* Attribute to select fields
*/
public const FIELDS = ['sku', 'name', 'price', 'image', 'url_path', 'url_key'];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should take this data from request

@@ -0,0 +1,43 @@
<?php
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pls, add declare(strict_types=1); to all of new files
And check code style of all of files

* @throws \Exception
* @return mixed|Value
*/
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use inheritdoc


$count = 0;
$data = [];
foreach ($collection as $item) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

foreach ($data as $key => $value)


namespace Magento\CatalogGraphQl\Model\Resolver\Products\DataProvider\Related;

abstract class AbstractDataProvider
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pls, don't use supertypes only for code reusing (if a relation is not like type A is subtype of B)

*/
protected function prepareCollection($product): void
{
$this->collection = $product->getCrossSellProductCollection();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like proxy on another method

@@ -271,6 +271,9 @@ interface ProductInterface @typeResolver(class: "Magento\\CatalogGraphQl\\Model\
websites: [Website] @doc(description: "An array of websites in which the product is available") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\Websites")
product_links: [ProductLinksInterface] @doc(description: "An array of ProductLinks objects") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\ProductLinks")
media_gallery_entries: [MediaGalleryEntry] @doc(description: "An array of MediaGalleryEntry objects") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\MediaGalleryEntries")
related_products: RelatedProduct @doc(description: "RelatedProduct") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\Related")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like resolver should be Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\Related\\RelatedProducts
Why do we need one more layer?
The same for another types of related products

@naydav
Copy link
Contributor

naydav commented Jan 23, 2019

Hello @VoronoyAlexandr,
We still need some changes to finish the PR, will you continue progress?
Thank you

Please let me know if you need any assistance.

@VitaliyBoyko
Copy link
Contributor

Closing due to inactivity.

@ghost
Copy link

ghost commented Feb 13, 2019

Hi @VoronoyAlexandr, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants