1

I have sellerProducts Query and SellerProducts type has product interface. When i call SellerProducts query it returns configurable_options and variants are null for configurable products in custom product collection.

type Query { 

    sellerProducts(
        input: SellerInput @doc(description: "Getting seller products details.")
        ): SellerProducts @resolver(class:"Custom\\MpGraphQl\\Model\\Resolver\\SellerProducts") @doc(description: "Return query of marketplace sellers products")

}
input SellerInput @doc(description: "Filters to fetch Seller") {
    seller_id: String @doc(description: "Seller Id")
}
type SellerProducts  @doc(description: "") {
    details: [Details] @doc(description: "")
    products: [ProductInterface]
}

Seller product resolver code.

$sellerProducts = $this->getSellerProducts($sellerId);
        foreach ($sellerProducts as $product) {
            $productData[] = [
                'name' => $product->getName(),
                'type_id' => $product->getTypeId(),
                'sku' => $product->getSku(),
                'url_key' => $product->getUrlKey(),
                'model' => $product
            ];
        }

   return [
            'products' => $productData,
        ];



public function getSellerProducts($sellerId)
{
    $collection = $this->productCollectionFactory->create()
        ->addAttributeToSelect('*')
        ->addAttributeToFilter('status', 1)
        ->addAttributeToFilter('visibility', ['in' => [2, 4]])
        ->addAttributeToSort('created_at', 'desc')
        ->addStoreFilter(1);
    return $collection;
}

Graphql payload

{
  sellerProducts(input: { seller_id: "115921" }) {
    products {
        name
        sku
        image {
          url
          label
        }
        ... on ConfigurableProduct {
        configurable_options {
          id
          attribute_id
          label
          position
          use_default
          attribute_code
        
          values {
            value_index
            label
            swatch_data{
              value
            }
          }
          product_id
  
        }
        variants {
          product {
            id
            name
            sku
            attribute_set_id
            ... on PhysicalProductInterface {
              weight
            }
            media_gallery{
              url
              position
            }
            price_range{
              minimum_price{
                regular_price{
                  value
                  currency
                }
              }
            }
          }
          attributes {
            uid
            label
            code
            value_index
          }
        }
      }
      }
    
  }
}

Response

enter image description here

1 Answer 1

3

After 2 days of investigation i have found the solution. in product data entity_id is missing. that was the issue. I have passed entity_id in array and it's working fine. hope it help someone .

 $productData[] = [
                'name' => $product->getName(),
                'type_id' => $product->getTypeId(),
                'sku' => $product->getSku(),
                'url_key' => $product->getUrlKey(),
                'model' => $product,
                'entity_id' => $product->getId()
               
            ];

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.