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

GraphQl-143: [Checkout] Add bundled product to Cart #396

Merged
merged 19 commits into from
Nov 1, 2019

Conversation

pmclain
Copy link
Contributor

@pmclain pmclain commented Feb 24, 2019

Description (*)

  • Mutation for adding bundled cart items
  • Resolver for fetching bundled cart item information

Fixed Issues (if relevant)

  1. [Checkout] Add bundled product to Cart #143: [Cart Operations] Add bundled product to Cart

Manual testing scenarios (*)

  1. Create empty quote
mutation {
  createEmptyCart
}
  1. Query for desired bundle product and options
{
  products(filter: {sku: {eq: "little-bobby-bundles"}}) {
    items {
      sku
      ... on BundleProduct {
        price_view
        items {
          option_id
          position
          title
          type
          options {
            id
            can_change_quantity
            is_default
            label
            position
            price
            price_type
            product {
              id
              sku
            }
            qty
          }
        }
      }
    }
  }
}
  1. Add bundled product to cart
mutation addBundlesToCart($cartId: String!) {
  addBundleProductsToCart(input: {
    cart_id: $cartId, 
    cartItems: [
      {
        data: {
          sku: "little-bobby-bundles"
          qty: 1
        }
        bundle_options: [
          {
            id: 1
            quantity: 2
            value: ["2"]
          }
          {
            id: 2
            quantity: 1
            value: ["5", "7"]
          }
        ]
      }
    ]
  }) {
    cart {
      cart_id
      items {
        id
        qty
        product {
          sku
        }
        ... on BundleCartItem {
          bundle_options {
            id
            label
            type
            values {
              id
              label
              price
              quantity
            }
          }
        }
      }
    }
  }
}

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)

This allows product type graphql modules a method for managing how inputs are
mapped when buy requests are created.
Partial resolution for magento/graphlql-ce#143
@TomashKhamlai
Copy link
Contributor

TomashKhamlai commented Feb 28, 2019

Hi, @pmclain. It will be a long-comment).
I have performed some negative scenarios and definitely I found something interesting. It is either Magento Core bug or problem of this PR.

Preconditions:

Have a Registered Customer to be able manipulate with a cart from Storefront and from GraphQL

Steps to reproduce:

  1. Create Simple Product with enough Quantity, Weight > 0 and SKU: simple-product-1

  2. Create Configurable Product among with its options by creating new attribute with Default Label at-001 and 2 options: option1 and option2, leave everything else to their defaults. Price: 9 and Qty: 1000

  3. Create Virtual Product Tax Estimation with SKU virtual-product-tax-estimation, Price 40.00, Qty 100500 and everything else leave by default

  4. Create Bundle product
    Name: Bundle Product 5
    SKU: bundle-product-5
    Dynamic SKU: Yes
    Price: 10
    Dynamic Weight: Yes
    BUNDLE OPTIONS:

    Ship Bundle Items: SEPARATELY

    Option Title: bundle-opt1
    Input Type: Dropdown
    Required: YES
    Is Default: TRUE, Name: Simple Product 1, SKU: simple-product-1, Price: 2.0000, Price Type: Fixed, Default Quantity: 1, User Defined: YES
    Is Default: False, Name: Configurable Product-option2, SKU: configurable-product-option2, Price: 3.0000, Price Type: Fixed, Default Quantity: 1, User Defined: No

    Option Title: bundle-opt2
    Input Type: Radio Buttons
    Required: NO
    Is Default: False, Name: Virtual Product Tax Estimation, SKU: virtual-product-tax-estimation, Price: 5.0000, Price Type: Fixed, Default Quantity: 2, User Defined: No

    CUSTOMIZABLE OPTIONS:
    Option Title: opt
    Option Type: Field
    Required: Yes
    Price: 1.00
    Price Type: Fixed
    SKU: sku-opt
    Max Characters: 5

  5. Know your IDs! :)
    In this step we want to get which bundle IDs we have and which values are valid for these IDs.
    I prefer to add product with everything included and then just execute the query cart

  6. Build mutation addBundleProductsToCart body but use INVALID VALUES, I don't mean random values. I took values from another bundle option...

mutation addBundleAndShowProductLinksInfo(
  $hasBundles: Boolean = true
) {
  addBundleProductsToCart(
    input: {
      cart_id: "B3TXGWgZ3EqQXCSXRDvlYm38xTzo7MsH"
      cartItems: {
        bundle_options: {
          id: 18
          quantity: 2
          value: [
            "47"
          ]
        }
        customizable_options: [
          {
            id: 6
            value: "48"
          }
        ]
        data: {
          sku: "bundle-product-5"
          qty: 2
        }
      }
    }
  ) {
    cart {
      items {
        __typename
        qty
          @include(
            if: $hasBundles
          )
        ... on BundleCartItem {
          bundle_options {
            id
            label
            type
            values {
              id
              label
              price
              quantity
            }
          }
          customizable_options {
            id
            type
            values {
              id
              value
            }
          }
        }
        product {
          __typename
          sku
            @include(
              if: $hasBundles
            )
          ... on BundleProduct {
            product_links {
              __typename
              link_type
              linked_product_sku
              linked_product_type
            }
          }
        }
      }
    }
  }
}
  1. Execute and read the response:
{
  "data": {
    "addBundleProductsToCart": {
      "cart": {
        "items": [
          {
            "__typename": "BundleCartItem",
            "qty": 2,
            "bundle_options": [],
            "customizable_options": [
              {
                "id": 6,
                "type": "field",
                "values": [
                  {
                    "id": 120,
                    "value": "48"
                  }
                ]
              }
            ],
            "product": {
              "__typename": "BundleProduct",
              "sku": "bundle-product-5",
              "product_links": null
            }
          },
          {
            "__typename": "VirtualCartItem",
            "qty": 2,
            "product": {
              "__typename": "VirtualProduct",
              "sku": "virtual-product-tax-estimation"
            }
          }
        ]
      }
    }
  }
}
  1. We already have one problem but lets continue. Open Storefront as Customer and click "View and Edit Cart"
    image
  2. Try to place order.

Expected result:

Validation should work at steps 7) 8) or 9)

Actual result:

Error message without $data provided:

<div role="alert" class="message message-error error">
        <div data-ui-id="checkout-cart-validationmessages-message-error" data-bind="text: $data"></div>
    </div>

image

@galaoleksandr
Copy link

Hello. Cannot reproduce this. Got an error: 1 exception(s):
Exception #0 (GraphQL\Error\Error): Type "CartItemInput" not found in document.

@naydav
Copy link
Contributor

naydav commented Apr 24, 2019

Hello @pmclain ,
Sorry for the delay with the PR processing. This functionality will be one of the main focuses for the next release.
This ticket already included in backlog of 2.3.3 release
Thanks

@naydav naydav changed the title [Cart Operations] Add bundled product to Cart GraphQl-143: [Checkout] Add bundled product to Cart May 2, 2019
@pmclain
Copy link
Contributor Author

pmclain commented May 4, 2019

@naydav No worries. This needs a bit of updating to handle some the recent changes in the QuoteGraphQl schema anyway.

@vpodorozh vpodorozh self-assigned this Jun 12, 2019
@vpodorozh vpodorozh self-requested a review June 12, 2019 19:37
@vpodorozh
Copy link
Contributor

@novikor @swnsma @XxXgeoXxX - please pick up this PR.
I do not have permission any more.
Thx!

@vpodorozh vpodorozh removed their assignment Jun 24, 2019
@vpodorozh vpodorozh removed their request for review June 24, 2019 18:44
@TomashKhamlai TomashKhamlai added the QA in progress We are checking label Jun 27, 2019
@lenaorobei
Copy link
Contributor

@pmclain please add <module name="Magento_QuoteGraphQl"/> to the module.xml.

@pmclain
Copy link
Contributor Author

pmclain commented Jun 27, 2019

@TomashKhamlai Thanks for merging in the latest upstream code. This PR is no longer functional and I'm working on getting it back in order.

@pmclain pmclain force-pushed the feature/bundle-cart branch from e5a573a to 989038c Compare June 28, 2019 01:02
@TomashKhamlai TomashKhamlai added Progress: ready for qa Add this in any case when you need some feedback, even if automated tests are failing and removed QA in progress We are checking labels Jun 29, 2019
@magento-engcom-team
Copy link
Contributor

Hi @lenaorobei, thank you for the review.
ENGCOM-5796 has been created to process this Pull Request
✳️ @lenaorobei, could you please add one of the following labels to the Pull Request?

Label Description
Auto-Tests: Covered All changes in Pull Request is covered by auto-tests
Auto-Tests: Not Covered Changes in Pull Request requires coverage by auto-tests
Auto-Tests: Not Required Changes in Pull Request does not require coverage by auto-tests

@ghost
Copy link

ghost commented Nov 1, 2019

Hi @pmclain, 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.

9 participants