8

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 a subscription in Craft Commerce. There are two problems here: Subscriptions aren't purchasables in Commerce at the moment, so they can't be added to a cart ...


5

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 make sure to post an 'amount' line item option. For docs on that see: https://docs.craftcms.com/commerce/v2/adding-to-and-updating-the-cart.html#line-item-options-...


5

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 found that you would do this is with the Stripe Payments plugin. The documentation for it can be found at https://github.com/craftcms/commerce-stripe. From ...


4

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.amount / 100)|currency }}


4

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 fields like Matrix on Variant Layouts is possible. Any required fields you don't include will throw an error and tell you they are needed. An example of the Orders ...


4

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 correctly Craft will treat it as a normal post request instead of an ajax request


4

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 current cart. Create a template that takes an order number param like so: cart/start-order?number=5bnuy8843nuy48bdy48u3bd84 In that template you would do ...


4

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 the current cart for this session. * * @param bool $forceSave Force the cart to save when requesting it. * @return Order * @throws Exception * @throws \...


4

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 provided unsupported as it is custom code and does not use the payment form template or javascript file that is in the Commerce Stripe plugin. This also means that it ...


4

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. You can just alter the line item price directly if desired but it may be more appropriate to create an adjuster to do it. So your add to cart form might look ...


4

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 suggested you clear. Essentially, it looks like existing carts may exist which are still using the old currency. Therefore these must be cleared before changing ...


4

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/or remove products (or variations) as time goes by. You might simply disable ones you remove, or you might delete them. If Commerce did not have line item ...


3

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 from the gateway that the card has been charged, we put the transaction into a 'processing' status. This status means we complete the order as there is ...


3

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% discount on the entire order. These adjusters have their logic hard-coded, which is to say: in order to modify the behavior/value of the adjustments, you have ...


3

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/examples/set-password-form.html. Here is what I'm using to allow users to change their passwords on demand. It is based on the User Profile Form documented at ...


3

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 filter among other helpful capabilities to Twig. With that plugin installed, set planData to a variable with the json_decode filter applied to it then you can ...


3

$order = \craft\commerce\elements\Order::find()->id($id)->one(); if($order) { foreach ($order->getLineItems() as $item) { // $item->description // $item->qty } $billingAddress = $order->getBillingAddress(); $shippingAddress = $order->getShippingAddress(); }


3

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.


3

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 a particular product you can do: craft.variants.product(product).all


3

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 method.shippingRules %} {{ shippingRule.name }} {{ shippingRule.description }} {% endfor %} {% endif %} {% endfor %}


3

calling {% set methods = cart.availableShippingMethods %} which is the same as calling: {% set methods = craft.commerce.shippingMethods.getAvailableShippingMethods(cart) %} the above returns an array of shipping method models, keyed by the shipping method handle. to get the matching rule for each available method {% for method in methods %} {% set ...


3

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 will be able to get access to the errors in the following manner from your template. General Errors {% set flashError = craft.app.session.getFlash('error') %} ...


3

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($event->types) This told me that my custom adjuster was going to the bottom of this array. To resolve this i used the php function array_unshift to push it ...


3

Quick answer. Yes you can use Apple Pay with Craft Commerce and the first-party Stripe Gateway Plugin. In order to do that, you need to customise your template and add the functionality for the Payment Request button. What this does is more or less generating a charge promise token for Stripe (same way it does for card). Charging the token is then handled ...


2

According to the Commerce 2 docs, the only first-party gateway that currently supports subscriptions is Stripe. Again, according to the Commerce 2 docs, the Stripe plugin is available for free on the plugin store.


2

The Craft support helped me to figure this out. The problem was, that the CSRF wasn't properly disabled. So in my config/general.php I have the following: if ( !function_exists('isApiRequest') ) { function isApiRequest () { $path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH); $query = parse_url($_SERVER['REQUEST_URI'], ...


2

the adjuster had the wrong namespace, changing it to: namespace hendrikeng\friendsdiscount\adjusters fixed the issue


2

I could be wrong here as I've not used subscriptions with Commerce yet, but using the filter |currency worked perfectly for me when outputting the correct format after having tried |replace and |number.


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 = new Product(); $product->title = 'Hello world'; $product->typeId = 2; $product->enabled = true; // Create variant $variant = new Variant(); $...


2

An adjustment will take a snapshot of the source object that contained the rule for its application. So the following is an array of a discounts attribute if you have a discount adjustment {{ adjustment.sourceSnapshot }} You could get the coupon code with {{ adjustment.sourceSnapshot.code }}


Only top voted, non community-wiki answers of a minimum length are eligible