laravel icon indicating copy to clipboard operation
laravel copied to clipboard

added withQuantity method to checkout

Open dcblogdev opened this issue 2 years ago • 5 comments

added option to set quantities on checkout defaults to 1.

This allows usage:

$request->user()->checkout('variant-id')->withQuantity(5)

This added the array key to the payload

['variant_quantities'] = [
    [
         'variant_id' => (int) $this->variant,
          'quantity' => $quantity,
    ],
]

dcblogdev avatar Nov 09 '23 23:11 dcblogdev

I tried this solution, but it didn't work for me. I believe variant_quantities should be an array of objects

Documentation

...
"variant_quantities": [
  {
    "variant_id": 1,
    "quantity": 10
  }
]
...

So, something like that worked.

$this->checkoutData['variant_quantities'] = [
    [
        'variant_id' => (int) $this->variant,
        'quantity' => $quantity,
    ],
];

davidsket avatar Nov 22 '23 19:11 davidsket

@davidsket 's solution works 👍

$this->checkoutData['variant_quantities'] = [
    [
        'variant_id' => (int) $this->variant,
        'quantity' => $quantity,
    ],
];

cwbmuller avatar Nov 26 '23 16:11 cwbmuller

i just came for this feature. how do i use this feature rightnow as main repon don't have this merged?

simpsoncarlos3 avatar Dec 10 '23 11:12 simpsoncarlos3

You can use repository directly in composer, or use overrides for specific class. I wouldn't recommend doing it in production.

davidsket avatar Dec 11 '23 19:12 davidsket

thanks @davidsket updated!

dcblogdev avatar Dec 15 '23 14:12 dcblogdev