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

GraphQl Example of adding product to cart with customizable options #4150

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,8 @@

/_site/

/.*
!/.github
!/.github/**

/*.yml
!/_config.yml
!/_config.prod.yml
!/_config.checks.yml
!/_config.stage.yml
_config.local.yml
.jekyll-metadata

*.bat
/tmp/
Expand Down
26 changes: 26 additions & 0 deletions Docfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
content_map:
-
directory: guides/v2.0
repository: magento/devdocs
branch: 2.0
filter: false
-
directory: guides/m1x
repository: magento/devdocs-m1
branch: master
filter: false
-
directory: mbi
repository: magento/devdocs-mbi
branch: master
filter: true
-
directory: mftf
repository: magento/magento2-functional-testing-framework
branch: develop
filter: true
-
directory: page-builder
repository: magento-devdocs/magento2-page-builder
branch: develop
filter: true
1 change: 1 addition & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ require 'colorator'
require_relative 'rakelib/lib/link-checker.rb'
require_relative 'rakelib/lib/converter.rb'
require_relative 'rakelib/lib/double-slash-check.rb'
require_relative 'rakelib/lib/doc-config.rb'

desc "Same as 'rake', 'rake preview'"
task default: %w[preview]
Expand Down
4 changes: 2 additions & 2 deletions guides/v2.1/javascript-dev-guide/javascript/js_init.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ redirect_from:

This topic describes different ways to call and initialize JavaScript in Magento 2:

- Insert a [JavaScript component]({{ site.gdeurl }}javascript-dev-guide/bk-javascript-dev-guide.html#js_terms) in `.phtml` page templates.
- Insert a [JavaScript component]({{ page.baseurl }}/javascript-dev-guide/bk-javascript-dev-guide.html#js_terms) in `.phtml` page templates.
- Call Javascript components that require initialization in Javascript (`.js`) files.

We strongly recommend that you use the described approaches and do not add inline {% glossarytooltip 312b4baf-15f7-4968-944e-c814d53de218 %}JavaScript{% endglossarytooltip %}.
Expand Down Expand Up @@ -128,7 +128,7 @@ require([

## Calling JS components requiring initialization in JS files {#js_widget_init}

To call a widget in JS code, use a notation similar to the following ([accordion]({{ site.gdeurl }}frontend-dev-guide/javascript/widget_accordion.html) widget is intiialized on the `[data-role=example]` element as illustration):
To call a widget in JS code, use a notation similar to the following ([accordion]({{ page.baseurl }}/javascript-dev-guide/widgets/widget_accordion.html) widget is intiialized on the `[data-role=example]` element as illustration):

```javascript
$('[data-role=example]').accordion();
Expand Down
76 changes: 76 additions & 0 deletions guides/v2.3/graphql/reference/quote.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,82 @@ mutation {
}
```

### Adding simple product with customizable options to a cart

If a product has a customizable option, the option's value can be specified in the add to cart request.

**Request**

``` text
mutation {
addSimpleProductsToCart (input: {
cart_id: "nu31JXR9DaqbdVqFDGnqjrMJmUnT3mzB"
cartItems: {
data: {
sku:"simple"
qty:1
},
customizable_options: [
{
id: 121
value: "field value"
}
]
}
}) {
cart {
items {
product {
name
}
qty

... on SimpleCartItem {
customizable_options {
label
values {
value
}
}
}
}
}
}
}
```

**Response**

```text
{
"data": {
"addSimpleProductsToCart": {
"cart": {
"items": [
{
"product": {
"name": "simple"
},
"qty": 2,
"customizable_options": [
{
"label": "Field Option",
"values": [
{
"value": "field value"
}
]
}
]
}
]
}
}
}
}
```


### Updating billing and shipping information
{:.no_toc}

Expand Down
11 changes: 11 additions & 0 deletions rakelib/lib/doc-config.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Read Docfile file and get configuration data for adding subrepositories
class DocConfig
attr_reader :config
def initialize(config_file = 'Docfile.yml')
@config = YAML.load_file(config_file)
end

def content_map
@config['content_map']
end
end
21 changes: 13 additions & 8 deletions rakelib/multirepo.rake
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
namespace :multirepo do
desc 'Add content from external repositories'
desc 'Create a file tree for devdocs website and get all required content'
task :init do
sh './scripts/docs-from-code.sh mbi [email protected]:magento/devdocs-mbi.git master'
sh './scripts/docs-from-code.sh page-builder [email protected]:magento-devdocs/magento2-page-builder.git develop'
sh './scripts/docs-from-code.sh mftf [email protected]:magento/magento2-functional-testing-framework.git develop'
ssh = '[email protected]:'
https = 'https://${token}@github.com/'
protocol =
if ENV['token']
https
else
ssh
end

# The last argument 'false' disables content filtering by sparse checkout.
# It covers cases when we need entire repository, not only the '/docs/' directory.
sh './scripts/docs-from-code.sh guides/m1x [email protected]:magento/devdocs-m1.git master false'
sh './scripts/docs-from-code.sh guides/v2.0 [email protected]:magento/devdocs.git 2.0 false'
content_map = DocConfig.new.content_map
content_map.each do |subrepo|
sh "./scripts/docs-from-code.sh #{subrepo['directory']} #{protocol}#{subrepo['repository']}.git #{subrepo['branch']} #{subrepo['filter']}"
end
end

desc 'Add multirepo docs providing shell arguments "dir=<directory where to init a repo>", "repo=<SSH URL>", "branch=<branch to checkout>", "filter=<true/false>" ("true" by default) to 1) filter content if "true" or 2) add content from the entire repository if "false".'
Expand Down