simple-commerce
simple-commerce copied to clipboard
Stock not decreasing on non-origin entry
Bug Description
If a product is bought on an entry that is not the origin, stock doesn't decrease. I have the issue on a product with variants, not sure if it's also the case for regular products.
Steps to reproduce
- Create a product with variant in EN, set stock
- Create the FR entry of the same product (variants inherited from EN)
- Buy from the EN entry of the product -> stock decreases properly
- Buy from the FR entry of the product -> stock doesn't decrease
Environment
Statamic 3.3.35 Pro Laravel 8.83.23 PHP 8.1.9 4rn0/statamic-v3-image-optimizer 1.0.16 aryehraber/statamic-logbook 2.1.0 doublethreedigital/duplicator 2.3.2 doublethreedigital/guest-entries 1.2.1 doublethreedigital/simple-commerce 3.2.20 optimoapps/statamic-bard-text-align 1.0.2 rias/statamic-redirect 2.4.0 xndbogdan/statamic-bard-text-color 2.4.1
Apologies for the delay in getting back to you! I'll try and take a look at this issue probably near the end of the week.
Released as part of v4.0.2.
Hey Duncan! Just tried the fix: I'm getting an error when trying to buy a variant entry on a non-origin product: https://flareapp.io/share/LPdLl2NP#F47
Hey Duncan! Just tried the fix: I'm getting an error when trying to buy a variant entry on a non-origin product: https://flareapp.io/share/LPdLl2NP#F47
Does the product you're checking out have a stock field in the blueprint?
The product I'm trying to buy doesn't have a stock field but his origin product does:
Blueprint: product_with_variants.yaml
title: 'Product with Variants'
sections:
main:
display: Main
fields:
-
handle: title
field: common.title
config:
required: true
-
import: prose
sale:
display: Sale
fields:
-
handle: product_variants
field:
display: 'Product Variants'
type: product_variants
icon: product_variants
listable: hidden
instructions_position: above
option_fields:
-
handle: stock
field:
display: Stock
type: integer
icon: integer
listable: hidden
instructions_position: above
sidebar:
display: Sidebar
fields:
-
handle: slug
field:
type: slug
required: true
localizable: true
validate:
- required
my-product-fr.md (product I'm trying to buy)
---
id: 332c14ff-1dd8-4d06-82a6-cebb8f6b9512
origin: 859f07ba-5a0f-4adc-8582-f73811d4211c
title: 'Test product FR'
updated_by: e518fccb-04be-499a-a92f-322e6e96a4d2
updated_at: 1665086433
---
my-product-en.md
---
id: 859f07ba-5a0f-4adc-8582-f73811d4211c
blueprint: product_with_variants
title: 'Test product'
max_quantity: 1
clients: all
product_variants:
variants:
-
name: Color
values:
- un
- deux
- trois
options:
-
key: un
variant: un
price: 100
stock: 1
-
key: deux
variant: deux
price: 200
stock: 2
-
key: trois
variant: trois
price: 300
stock: 3
updated_by: e518fccb-04be-499a-a92f-322e6e96a4d2
updated_at: 1665086386
---
Gotcha - I think I know why it’s breaking then. I’ll fix it tomorrow.
Hey Duncan, Just tested now - I don't have the error anymore but the stock issue is still here. I've looked a bit deeper and here's what happens:
Initial state:
- EN product:
product_variantsfield, stock: 3 - FR product: no
product_variantsfield (inherits from EN)
Action: Buy 1 product from the FR site
Current result:
- EN product:
product_variantsfield, stock: 3 - FR product: new
product_variantsfield, stock: 2
Desired result:
- EN product:
product_variantsfield, stock: 2 - FR product: no
product_variantsfield (inherits from EN)
Ah, this fix was only for normal stock fields, not for product variant fields. I'll re-open.
Hey!
I've just had some time to take a look into the issue with a stock field on product variants on a multi-site but I was unable to reproduce it creating a new product_variants field on the localised version of the product entry 🤔
Recorded a quick Loom: https://www.loom.com/share/935781c7b97244fc869acce840eea9f9
(I don't have a 'proper' checkout process for multi-site versions of products so I'm just switching around the product ID in the order to give it the same affect)
Maybe there's something I'm doing wrong?
I'm going to close this issue now since I've been unable to reproduce & it's been left open without comment.
If you're continuing to run into this issue, please open a new issue and I'll take another look.