Skip to content

Commit 6b3f276

Browse files
committed
version 0.2.1
1 parent 8554b4b commit 6b3f276

File tree

5 files changed

+59
-223
lines changed

5 files changed

+59
-223
lines changed

.gitignore

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# CRAFT ENVIRONMENT
2+
.env.php
3+
.env.sh
4+
.env
5+
6+
# COMPOSER
7+
/vendor
8+
9+
# BUILD FILES
10+
/bower_components/*
11+
/node_modules/*
12+
/build/*
13+
/yarn-error.log
14+
15+
# MISC FILES
16+
.cache
17+
.DS_Store
18+
.idea
19+
.project
20+
.settings
21+
*.esproj
22+
*.sublime-workspace
23+
*.sublime-project
24+
*.tmproj
25+
*.tmproject
26+
.vscode/*
27+
!.vscode/settings.json
28+
!.vscode/tasks.json
29+
!.vscode/launch.json
30+
!.vscode/extensions.json

README.md

Lines changed: 15 additions & 175 deletions
Original file line numberDiff line numberDiff line change
@@ -1,187 +1,27 @@
1-
# MultiAdd
1+
>
2+
> ### Multi Add has a new home with the fine folks at Verbb. Read about it in our [blog post](https://verbb.io/blog/welcome-to-verbb).
3+
>
24
3-
Provides an alternative controller to assist in adding multiple items to your Craft Commerce cart at once.
4-
5-
Also provides some handy twig tags for adding items, removing a line item, and clearing the cart directly in your templates.
6-
7-
## Adding Multiple Items To Your Cart
8-
9-
Use the following code in your product template to make use of this new controller.
10-
11-
Notes:
12-
13-
* The array *must* be named `items` and you must supply at least a `purchasableId` and a `qty`.
14-
* Attributes are grouped together by a key in the form `items[key][attribute]` where key can be any value but must be the same for each of the attributes. `loop.index` is an obvious choice for this if iterative over products or variations in a loop.
15-
* You can also POST an optional `note` per line item
16-
* You can also POST arbitrary options, e.g. `[options][color]`
17-
* Items with a zero `qty` are simply skipped and not added to the cart.
18-
19-
Here's some example code to get you started - if you get stuck, just ask on the Craft CMS Slack #craftcommerce channel for help.
20-
21-
This code displays all your products in one form:
22-
23-
```
24-
<form method="POST" id="addToCart">
25-
<input type="hidden" name="action" value="multiAdd/multiAdd">
26-
<input type="hidden" name="redirect" value="/cart">
27-
{{ getCsrfInput() }}
28-
29-
{% for product in craft.commerce.products.find() %}
30-
<input type="hidden" name="items[{{ loop.index }}][purchasableId]" value="{{ product.defaultVariant.id }}">
31-
<input type="hidden" name="items[{{ loop.index }}][qty]" value="1">
32-
<input type="text" name="items[{{ loop.index }}][note]">
33-
34-
<select name="items[{{ loop.index }}][options][color]">
35-
<option value="blue">Blue</option>
36-
<option value="white">White</option>
37-
<option value="red">Red</option>
38-
</select>
39-
{% endfor %}
40-
</form>
41-
```
42-
43-
Or say you want to list the variants of a particular product out:
44-
45-
```
46-
<form method="POST" id="addToCart">
47-
<input type="hidden" name="action" value="multiAdd/multiAdd">
48-
<input type="hidden" name="redirect" value="/cart">
49-
{{ getCsrfInput() }}
50-
51-
{% set product = craft.commerce.products.slug('your-product') %}
52-
53-
{% for variant in product.variants %}
54-
<input type="hidden" name="items[{{ loop.index }}][purchasableId]" value="{{ variant.id }}">
55-
<input type="hidden" name="items[{{ loop.index }}][qty]" value="1">
56-
<input type="text" name="items[{{ loop.index }}][note]">
57-
{% endfor %}
58-
</form>
59-
```
60-
61-
Alternatively, submit via Ajax & get a JSON response, which (on success) includes a comprehensive cart object with all the data you should need.
62-
63-
```
64-
$("#addToCart").submit(function(e) {
65-
e.preventDefault();
66-
67-
var data = $(this).serialize();
68-
data[window.csrfTokenName] = window.csrfTokenValue;
69-
70-
$.post('/actions/' + $('input[name=action]').val(), data, function(response) {
71-
if (response.success) {
72-
$("#addToCartButton").val("Added!");
73-
cart.update( response.cart );
74-
} else {
75-
$("#addToCartButton").val("Error!");
76-
}
77-
});
78-
});
79-
```
80-
81-
## Updating Multiple Items In Your Cart
82-
83-
When viewing your cart, it's currently not possible to update all your line items at once - instead it must be done for each line item as a separate event. This controller let's you update multiple line items at once. This might be desirable when a user has multiple line items in their cart, and wants to update quantities all at once by clicking an 'Update Cart' button.
5+
# Multi Add Plugin for Craft CMS
846

85-
To achieve this, create your cart template using the following guide:
7+
<img width="500" src="https://verbb.io/uploads/plugins/multi-add/_800x455_crop_center-center/multi-add-social-card.png">
868

87-
```
88-
<form method="POST">
89-
<input type="hidden" name="action" value="multiAdd/updateCart">
90-
<input type="hidden" name="redirect" value="/cart">
91-
{{ getCsrfInput() }}
92-
93-
{% for item in cart.lineItems %}
94-
<input type="text" size="4" name="items[{{ item.id }}][qty]" value="{{ item.qty }}">
95-
{% endfor %}
96-
97-
<button type="submit">Update Cart</button>
98-
</form>
99-
```
100-
101-
102-
## Events
103-
104-
This plugin raises two events, much like normal the Commerce add to cart, which you can listen for in the same way. They are:
105-
106-
`onBeforeMultiAddToCart` and `onMultiAddToCart`
107-
108-
In each case the event parameters are:
109-
110-
`order` (Commerce_OrderModel)
111-
`lineItems` (an array of Commerce_LineItemModel)
112-
113-
```
114-
craft()->on('multiAdd_cart.onBeforeMultiAddToCart', function($event) {
115-
$order = $event->params['order'];
116-
$lineItems = $event->params['lineItems'];
117-
$event->performAction = false;
118-
});
119-
120-
```
121-
122-
## Twig Tags
123-
124-
MultiAdd also provides a few extra useful twig tags that you can use to perform cart operations directly in your templates.
125-
126-
Example - Setup:
127-
128-
```
129-
{% set cart = craft.commerce.cart %}
130-
{% set items = [] %}
131-
132-
{% set items = items|merge([{"purchasableId":1385,"qty":1, "note":"Test note"}]) %}
133-
{% set items = items|merge([{"purchasableId":854,"qty":2, "options": {"colour":"green"} }]) %}
134-
```
135-
136-
Items is an array, and now holds:
137-
138-
```
139-
array(2) {
140-
[0]=>
141-
array(3) {
142-
["purchasableId"]=>
143-
int(1385)
144-
["qty"]=>
145-
int(1)
146-
["note"]=>
147-
string(9) "Test note"
148-
}
149-
[1]=>
150-
array(3) {
151-
["purchasableId"]=>
152-
int(854)
153-
["qty"]=>
154-
int(2)
155-
["options"]=>
156-
array(1) {
157-
["colour"]=>
158-
string(9) "green"
159-
}
160-
}
161-
}
162-
```
163-
164-
Example Twig Operations:
9+
Provides an alternative controller to assist in adding multiple items to your Craft Commerce cart at once.
16510

166-
```
167-
# add items to cart
168-
{{ craft.multiAdd.multiAddToCart(cart, items) }}
11+
Also provides some handy twig tags for adding items, removing a line item, and clearing the cart directly in your templates.
16912

170-
# remove the first line item
171-
{{ craft.multiAdd.removeLineItem(cart, cart.lineItems[0].id ) }}
13+
## Documentation
17214

173-
# clear the cart
174-
{{ craft.multiAdd.removeAllLineItems(cart) }}
175-
```
15+
Visit the [Multi Add Plugin page](https://verbb.io/craft-plugins/multi-add) for all documentation, guides, pricing and developer resources.
17616

177-
## Compatibility
17+
## Support
17818

179-
This plugin has been tested with Craft 2.5 and Craft Commerce 1.0.1187 and above. It's in use daily on production systems.
19+
Get in touch with us via the [Multi Add Support page](https://verbb.io/craft-plugins/multi-add/support) or by [creating a Github issue](/verbb/multi-add/issues)
18020

181-
## Changelog
21+
<h2></h2>
18222

183-
See [releases.json](https://raw.githubusercontent.com/engram-design/MultiAdd/master/releases.json)
23+
<a href="https://verbb.io" target="_blank">
24+
<img width="100" src="https://verbb.io/assets/img/verbb-pill.svg">
25+
</a>
18426

185-
## Credits
18627

187-
By [Josh Crawford](https://github.com/engram-design) (of S. Group) (@crawf on Craft CMS Slack) and [Jeremy Daalder](https://github.com/bossanova808) (@jeremydaalder), with thanks to [Luke Holder](https://github.com/lukeholder) (@lukeholder).

multiadd/MultiAddPlugin.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public function getName()
1616

1717
public function getVersion()
1818
{
19-
return '0.2.0';
19+
return '0.2.1';
2020
}
2121

2222
public function getSchemaVersion()
@@ -26,17 +26,17 @@ public function getSchemaVersion()
2626

2727
public function getDeveloper()
2828
{
29-
return 'S. Group';
29+
return 'Verbb';
3030
}
3131

3232
public function getDeveloperUrl()
3333
{
34-
return 'http://sgroup.com.au';
34+
return 'https://verbb.io';
3535
}
3636

3737
public function getDocumentationUrl()
3838
{
39-
return 'https://github.com/engram-design/MultiAdd';
39+
return 'https://github.com/verbb/multi-add';
4040
}
4141

4242
public function getDescription()
@@ -46,7 +46,7 @@ public function getDescription()
4646

4747
public function getReleaseFeedUrl()
4848
{
49-
return 'https://raw.githubusercontent.com/engram-design/MultiAdd/master/releases.json';
49+
return 'https://raw.githubusercontent.com/verbb/multi-add/master/releases.json';
5050
}
5151

5252
public function hasSettings()

multiadd/resources/icon.svg

Lines changed: 1 addition & 43 deletions
Loading

releases.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
[
2+
{
3+
"version": "0.2.1",
4+
"downloadUrl": "https://github.com/engram-design/MultiAdd/archive/0.2.1.zip",
5+
"date": "2017-10-18T00:00:00+10:00",
6+
"notes": [
7+
"[Added] Verbb marketing (new plugin icon, readme, etc)."
8+
]
9+
},
210
{
311
"version": "0.1.9",
412
"downloadUrl": "https://github.com/engram-design/MultiAdd/archive/0.1.9.zip",

0 commit comments

Comments
 (0)