9
votes
How do I apply taxes to subscriptions with Stripe plugin?
I realise this is a bit of an old question, but I was faced with the same problem recently so I thought I'd document my solution here for anyone in the future that comes along needing to apply tax to ...
- 1,344
6
votes
Accepted
Commerce: what is the purpose of a line item's snapshot?
The snapshot is there so that the key details of an order are forever more available on the order record.
Imagine living with Commerce for a long time - you will of course most likely add, change and/...
- 7,547
5
votes
Accepted
User-determined price for a product variant?
Here's how you could accomplish this.
1) Create a product variant called 'custom amount' with a zero price.
2) Get the ID of that variant
3) When submitting/adding/updating the item to the cart ...
- 6,712
5
votes
Accepted
302 redirect when updating the cart via Ajax using Craft Commerce 2
The function contains this
if ($request->getAcceptsJson()) {
Thus you'll need to set the dataType in your ajax request to json or text/json in order to not get redirected. If you didn't set it ...
- 19.6k
5
votes
Accepted
Exposing current Commerce2 Cart via the Element API
The cart is not baked into \Craft, but craft\commerce\Plugin.
Try the following:
$cart = craft\commerce\Plugin::getInstance()->getCarts()->getCart();
Uses the following function:
/**
* Get ...
- 165
5
votes
How to display payment gateway error message only
When submitting a payment form to the commerce/payments/pay controller action there are three potential sources of error messages.
If you are submitting via a normal form submission (not ajax) you ...
- 820
5
votes
Accepted
Setting Quantity Field on Subscriptions
I realize that this is an older question, but I have found the answer for it after much searching, and want to leave this answer for others who might be coming from a search engine.
The way I have ...
- 76
4
votes
Accepted
Commerce 2 Subscription Prices
Stripe stores the amount in cents. If you want to format it from the subscriptionPlanData.plan.amount variable in your template you would need to divide by 100 first.
{{ (subscriptionPlanData.plan....
- 712
4
votes
Accepted
Is it possible to import orders into Craft Commerce?
Sprout Import supports importing Craft Commerce Orders on Craft 3.
I can't speak to which fields are required off of the top of my head but importing to custom fields, variants, and even custom ...
- 13.3k
4
votes
Accepted
Craft Commerce 2 - get order data for plugin
$order = \craft\commerce\elements\Order::find()->id($id)->one();
if($order)
{
foreach ($order->getLineItems() as $item) {
// $item->description
// $item->qty
}
$...
- 6,712
4
votes
Accepted
(How) can I fill a visitor's cart by using a link?
There is currently no way to populate a cart from a link as a standard feature of Commerce 2.
But you could accomplish this in 2 ways.
1) With a smart template to add all items from the order to the ...
- 6,712
4
votes
Accepted
Frontend form to change Craft Commerce user's password?
The code you are currently using is for the Set Password form that is used when a user forgets their password and you send them a Password reset email as documented at https://docs.craftcms.com/v3/dev/...
- 1,226
4
votes
Craft Commerce 2.0.2 Shipping Rule Names & Descriptions—How?
You have to can loop through the shipping rules for the shipping method.
{% for handle, method in cart.availableShippingMethods %}
{% if method.shippingRules|length %}
{% for shippingRule in ...
4
votes
Accepted
Craft Commerce 2.0.2 Shipping Rule Names & Descriptions—How?
calling
{% set methods = cart.availableShippingMethods %}
which is the same as calling:
{% set methods = craft.commerce.shippingMethods.getAvailableShippingMethods(cart) %}
the above returns an ...
- 6,712
4
votes
Accepted
How to display Craft Commerce subscription description from a linked entry
I found the answer by viewing the source code in CP. To display the content of the related entry:
{{ plan.information.<fieldHandleInTheRelatedEntry> }}
- 393
4
votes
Customizing Stripe payment form for Craft Commerce 2
The following code allows the customisation of the fields using Stripe Elements. This code will replace the payment form with gateway.getPaymentFormHtml({}).
The thing to note here is this is ...
- 820
4
votes
Accepted
How can I change variant price in Craft Commerce 2 form
It's not possible to send the price to the cart in this way.
You will need to send that price as a custom option on the item and then use a custom module or plugin to update the line item's price.
...
- 2,009
4
votes
Accepted
Payment currency not allowed
Solution from Craft:
In your Control Panel, click on Commerce then on the vertical subnav (where you have All Orders, New, Shipped....) you will have Active and Inactive carts, this is what Luke ...
- 458
3
votes
Accepted
Demo repo for an Adjuster module for Commerce 2?
I've created a stub/reference Adjuster module, here.
This demonstrates how to register two Adjusters via a custom module—one that creates a 5% discount on each line item, and one that creates a 10% ...
- 3,044
3
votes
Accepted
Get Commerce 2's Stripe subscription planData as object
A subscription's planData is currently only stored as JSON. You can use that JSON in your template but you'll need to decode it first. Marion Newlevant’s Twig Perversion plugin adds a json_decode ...
- 712
3
votes
Programmatically create a product using Craft Commerce 2?
You probably have it figured by now, but for anyone wondering, here's a complete working example.
use craft\commerce\elements\Product;
use craft\commerce\elements\Variant;
// Create product
$product ...
- 604
3
votes
Accepted
Commerce 2 Stripe gateway seems to be working correctly, but order remains unpaid
The processing transaction status is used when a gateway returns from offsite correctly (the user has done everything they can to make payment on the order) but since we didn't get a definitive answer ...
- 6,712
3
votes
Accepted
How to debug a payment gateway error
On the Transactions tab of the order, there should be a payment attempt with a failed status. There's a small information icon which returns the gateway response.
- 46
3
votes
Accepted
Getting Commerce Products using Element API in Craft 3
You're so close! Just one change (see the elementType key, and the added comment)…
use craft\commerce\elements\Product;
return [
'endpoints' => [
'api/search' => [
'...
- 3,044
3
votes
Accepted
Possible to paginate product variants in Craft Commerce 2?
product.variants returns the variants for the product as an array only. It is not like a element relationship field which returns an element query.
If you want to use a element query of variants for ...
- 6,712
3
votes
Accepted
Accessing Commerce product variant dimensions in the template
Dimensions are set and accessed individually:
{% set variant = product.defaultVariant %}
{{ variant.width }}
{{ variant.height }}
{{ variant.length }}
{{ variant.weight }}
- 867
3
votes
Accepted
Getting started with Craft Commerce 2 subscriptions using Stripe
I was barking up the wrong tree for the whole time. The template code was fine. It turned out that jQuery was missing. I’ve had a console error telling me ReferenceError: Can't find variable: $ in ...
- 949
3
votes
Delete commerce line item with Ajax
Issue resolved. Having checked with Yii debug bar i could see that there was no $_post data with the request. It seems axios sends the data as JSON and not usual post data. Switching to vue-resource ...
- 303
3
votes
Commerce 2 Adding tax to custom adjuster
Having slept on it i thought it could be something to do with the order of the adjusters. Maybe Tax was applying to the price before my custom adjuster. So in the event i did the following:
var_dump($...
- 303
3
votes
Craft Commerce > 2.2: How can you order line items?
I am posting the answer of Craft Commerce Support in case somebody stumbles over the same thing:
It is possible to order them differently if required. The code example below shows how to order them ...
- 565
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
plugin-craftcommerce2 × 164craft3 × 71
plugin-craftcommerce × 40
plugin-development × 19
ecommerce × 11
modules × 7
stripe × 5
variants × 5
templating × 4
php × 4
plugin-elementapi × 4
migration × 4
payment × 4
plugin-commerce-stripe × 4
shipping × 3
products × 3
plugin-digitalproducts × 3
cart × 3
relations × 2
elementcriteriamodel × 2
events × 2
query × 2
mysql × 2
craft-pro × 2
array × 2