@@ -180,11 +180,11 @@ func UpdateInventory(product string, decrementQuantity int64) {
180180 slog .Error ("Error while searching database for product " + product + err .Error ())
181181 return
182182 }
183- inventory .Quantity -= decrementQuantity
183+ inventory .Quantity = inventory . Quantity - decrementQuantity
184184 if inventory .Quantity > 0 {
185- go ClampAdjustableQty (inventory .SessionLinkIDs , product , inventory .Quantity )
185+ ClampAdjustableQty (inventory .SessionLinkIDs , product , inventory .Quantity )
186186 } else {
187- go RemoveItemFromLink (inventory .SessionLinkIDs , product )
187+ RemoveItemFromLink (inventory .SessionLinkIDs , product )
188188 }
189189
190190 DB .Conn .Save (& inventory )
@@ -199,12 +199,30 @@ func ClampAdjustableQty(links []string, product string, qty int64) {
199199 return
200200 }
201201 for _ , li := range seslink .Params .LineItems {
202- if * li .PriceData .Product == product && * li .AdjustableQuantity .Maximum > qty {
203- li .AdjustableQuantity .Maximum = stripe .Int64 (qty )
202+ price := & models.Price {}
203+ err := DB .Conn .Where (& models.Price {PriceID : * li .Price }).First (price ).Error
204+ if err != nil {
205+ slog .Error ("Error while getting price from DB: " + err .Error ())
206+ return
207+ }
208+ if price .Product == product {
209+ if li .AdjustableQuantity != nil {
210+ if * li .AdjustableQuantity .Maximum > qty {
211+ li .AdjustableQuantity .Maximum = stripe .Int64 (qty )
212+ }
213+ if * li .AdjustableQuantity .Minimum == * li .AdjustableQuantity .Maximum {
214+ li .AdjustableQuantity = nil
215+ }
216+ }
217+
218+ if * li .Quantity > qty {
219+ li .Quantity = stripe .Int64 (qty )
220+ }
204221 break
205222 }
206223
207224 }
225+
208226 DB .Conn .Save (& seslink )
209227 }
210228}
@@ -219,13 +237,19 @@ func RemoveItemFromLink(links []string, product string) {
219237 }
220238 if len (seslink .Params .LineItems ) == 1 {
221239 seslink .Active = false
240+ DB .Conn .Save (& seslink )
222241 continue
223242 }
224243 newLineItems := []* stripe.CheckoutSessionLineItemParams {}
225244 for _ , li := range seslink .Params .LineItems {
226- if * li .PriceData .Product != product {
245+ price := & models.Price {}
246+ err := DB .Conn .Where (& models.Price {PriceID : * li .Price }).First (price ).Error
247+ if err != nil {
248+ slog .Error ("Error while getting price from DB: " + err .Error ())
249+ return
250+ }
251+ if price .Product != product {
227252 newLineItems = append (newLineItems , li )
228- break
229253 }
230254
231255 }
0 commit comments