|
| 1 | +--- |
| 2 | +group: graphql |
| 3 | +title: addProductsToCompareList mutation |
| 4 | +contributor_name: Atwix |
| 5 | +contributor_link: https://www.atwix.com/ |
| 6 | +--- |
| 7 | + |
| 8 | +The `addProductsToCompareList` mutation adds products to the comparison list. |
| 9 | + |
| 10 | +You must specify the unique ID of the compare list as well as a list of product IDs to be added to the comparison list. |
| 11 | + |
| 12 | +## Syntax |
| 13 | + |
| 14 | +```graphql |
| 15 | +mutation { |
| 16 | + addProductsToCompareList( |
| 17 | + input: AddProductsToCompareListInput |
| 18 | + ) { |
| 19 | + CompareList |
| 20 | + } |
| 21 | +} |
| 22 | +``` |
| 23 | + |
| 24 | +## Example usage |
| 25 | + |
| 26 | +The following example shows how to add two products into the existing comparison list with unique ID "sssXyGZkTFksdPnxNoK1ut6OiV4bbchD". |
| 27 | + |
| 28 | +**Request:** |
| 29 | + |
| 30 | +```graphql |
| 31 | +mutation { |
| 32 | + addProductsToCompareList( |
| 33 | + input: { |
| 34 | + uid: "sssXyGZkTFksdPnxNoK1ut6OiV4bbchD", |
| 35 | + products: ["3", "4"] |
| 36 | + } |
| 37 | + ) { |
| 38 | + uid |
| 39 | + item_count |
| 40 | + attributes { |
| 41 | + code |
| 42 | + label |
| 43 | + } |
| 44 | + items { |
| 45 | + uid |
| 46 | + product { |
| 47 | + sku |
| 48 | + name |
| 49 | + description { |
| 50 | + html |
| 51 | + } |
| 52 | + } |
| 53 | + } |
| 54 | + } |
| 55 | +} |
| 56 | +``` |
| 57 | + |
| 58 | +**Response:** |
| 59 | + |
| 60 | +```json |
| 61 | +{ |
| 62 | + "data": { |
| 63 | + "addProductsToCompareList": { |
| 64 | + "uid": "sssXyGZkTFksdPnxNoK1ut6OiV4bbchD", |
| 65 | + "item_count": 4, |
| 66 | + "attributes": [ |
| 67 | + { |
| 68 | + "code": "sku", |
| 69 | + "label": "SKU" |
| 70 | + }, |
| 71 | + { |
| 72 | + "code": "description", |
| 73 | + "label": "Description" |
| 74 | + }, |
| 75 | + { |
| 76 | + "code": "short_description", |
| 77 | + "label": "Short Description" |
| 78 | + }, |
| 79 | + { |
| 80 | + "code": "activity", |
| 81 | + "label": "Activity" |
| 82 | + } |
| 83 | + ], |
| 84 | + "items": [ |
| 85 | + { |
| 86 | + "uid": "1", |
| 87 | + "product": { |
| 88 | + "sku": "24-MB01", |
| 89 | + "name": "Joust Duffle Bag", |
| 90 | + "description": { |
| 91 | + "html": "<p>The sporty Joust Duffle Bag can't be beat - not in the gym, not on the luggage carousel, not anywhere. Big enough to haul a basketball or soccer ball and some sneakers with plenty of room to spare, it's ideal for athletes with places to go.<p>\n<ul>\n<li>Dual top handles.</li>\n<li>Adjustable shoulder strap.</li>\n<li>Full-length zipper.</li>\n<li>L 29\" x W 13\" x H 11\".</li>\n</ul>" |
| 92 | + } |
| 93 | + } |
| 94 | + }, |
| 95 | + { |
| 96 | + "uid": "2", |
| 97 | + "product": { |
| 98 | + "sku": "24-MB04", |
| 99 | + "name": "Strive Shoulder Pack", |
| 100 | + "description": { |
| 101 | + "html": "<p>Convenience is next to nothing when your day is crammed with action. So whether you're heading to class, gym, or the unbeaten path, make sure you've got your Strive Shoulder Pack stuffed with all your essentials, and extras as well.</p>\n<ul>\n<li>Zippered main compartment.</li>\n<li>Front zippered pocket.</li>\n<li>Side mesh pocket.</li>\n<li>Cell phone pocket on strap.</li>\n<li>Adjustable shoulder strap and top carry handle.</li>\n</ul>" |
| 102 | + } |
| 103 | + } |
| 104 | + }, |
| 105 | + { |
| 106 | + "uid": "3", |
| 107 | + "product": { |
| 108 | + "sku": "24-MB03", |
| 109 | + "name": "Crown Summit Backpack", |
| 110 | + "description": { |
| 111 | + "html": "<p>The Crown Summit Backpack is equally at home in a gym locker, study cube or a pup tent, so be sure yours is packed with books, a bag lunch, water bottles, yoga block, laptop, or whatever else you want in hand. Rugged enough for day hikes and camping trips, it has two large zippered compartments and padded, adjustable shoulder straps.</p>\n<ul>\n<li>Top handle.</li>\n<li>Grommet holes.</li>\n<li>Two-way zippers.</li>\n<li>H 20\" x W 14\" x D 12\".</li>\n<li>Weight: 2 lbs, 8 oz. Volume: 29 L.</li>\n<ul>" |
| 112 | + } |
| 113 | + } |
| 114 | + }, |
| 115 | + { |
| 116 | + "uid": "4", |
| 117 | + "product": { |
| 118 | + "sku": "24-MB05", |
| 119 | + "name": "Wayfarer Messenger Bag", |
| 120 | + "description": { |
| 121 | + "html": "<p>Perfect for class, work or the gym, the Wayfarer Messenger Bag is packed with pockets. The dual-buckle flap closure reveals an organizational panel, and the roomy main compartment has spaces for your laptop and a change of clothes. An adjustable shoulder strap and easy-grip handle promise easy carrying.</p>\n<ul>\n<li>Multiple internal zip pockets.</li>\n<li>Made of durable nylon.</li>\n</ul>" |
| 122 | + } |
| 123 | + } |
| 124 | + } |
| 125 | + ] |
| 126 | + } |
| 127 | + } |
| 128 | +} |
| 129 | +``` |
| 130 | + |
| 131 | +## Input attributes |
| 132 | + |
| 133 | +The `AddProductsToCompareListInput` input object defines the product IDs to be compared within an existing comparison list. |
| 134 | + |
| 135 | +### AddProductsToCompareListInput attributes {#addProductsToCompareListInput} |
| 136 | + |
| 137 | +The `AddProductsToCompareListInput` object contains the following attributes: |
| 138 | + |
| 139 | +Attribute | Data Type | Description |
| 140 | +--- | --- | --- |
| 141 | +`products` | [ID]! | An array of product IDs to add to the compare list |
| 142 | +`uid` | ID! | The unique ID of a `CompareList` object |
| 143 | + |
| 144 | +## Output attributes |
| 145 | + |
| 146 | +The `CompareList` output object contains the following attribute: |
| 147 | + |
| 148 | +{% include graphql/compare-list-output.md %} |
| 149 | + |
| 150 | +## Related topics |
| 151 | + |
| 152 | +* [compareList query]({{page.baseurl}}/graphql/queries/compare-list.html) |
| 153 | +* [assignCompareListToCustomer mutation]({{page.baseurl}}/graphql/mutations/assign-compare-list-to-customer.html) |
| 154 | +* [createCompareList mutation]({{page.baseurl}}/graphql/mutations/create-compare-list.html) |
| 155 | +* [deleteCompareList mutation]({{page.baseurl}}/graphql/mutations/delete-compare-list.html) |
| 156 | +* [removeProductsFromCompareList mutation]({{page.baseurl}}/graphql/mutations/remove-products-from-compare-list.html) |
0 commit comments