issue #850
This commit is contained in:
parent
e6e12ae601
commit
fc456c785f
|
|
@ -1180,7 +1180,7 @@ class Cart {
|
|||
*
|
||||
* @return response mixed
|
||||
*/
|
||||
public function proceedToBuyNow($id) {
|
||||
public function proceedToBuyNow($id, $quantity) {
|
||||
$product = $this->product->findOneByField('id', $id);
|
||||
|
||||
if ($product->type == 'configurable') {
|
||||
|
|
@ -1195,7 +1195,7 @@ class Cart {
|
|||
|
||||
$data['product'] = $parent->id;
|
||||
$data['selected_configurable_option'] = $simpleOrVariant->id;
|
||||
$data['quantity'] = 1;
|
||||
$data['quantity'] = $quantity;
|
||||
$data['super_attribute'] = 'From Buy Now';
|
||||
|
||||
$result = $this->add($parent->id, $data);
|
||||
|
|
@ -1204,7 +1204,7 @@ class Cart {
|
|||
} else {
|
||||
$data['product'] = $id;
|
||||
$data['is_configurable'] = false;
|
||||
$data['quantity'] = 1;
|
||||
$data['quantity'] = $quantity;
|
||||
|
||||
$result = $this->add($id, $data);
|
||||
|
||||
|
|
|
|||
|
|
@ -209,11 +209,11 @@ class CartController extends Controller
|
|||
return redirect()->route('shop.products.index', $slug);
|
||||
}
|
||||
|
||||
public function buyNow($id)
|
||||
public function buyNow($id, $quantity)
|
||||
{
|
||||
Event::fire('checkout.cart.add.before', $id);
|
||||
|
||||
$result = Cart::proceedToBuyNow($id);
|
||||
$result = Cart::proceedToBuyNow($id, $quantity);
|
||||
|
||||
Event::fire('checkout.cart.add.after', $result);
|
||||
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ Route::group(['middleware' => ['web', 'locale', 'theme', 'currency']], function
|
|||
])->name('shop.checkout.success');
|
||||
|
||||
//Shop buynow button action
|
||||
Route::get('buynow/{id}', 'Webkul\Shop\Http\Controllers\CartController@buyNow')->name('shop.product.buynow');
|
||||
Route::get('buynow/{id}/{quantity}', 'Webkul\Shop\Http\Controllers\CartController@buyNow')->name('shop.product.buynow');
|
||||
|
||||
//Shop buynow button action
|
||||
Route::get('move/wishlist/{id}', 'Webkul\Shop\Http\Controllers\CartController@moveToWishlist')->name('shop.movetowishlist');
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{!! view_render_event('bagisto.shop.products.buy_now.before', ['product' => $product]) !!}
|
||||
|
||||
<button type="submit" data-href="{{ route('shop.product.buynow', $product->product_id)}}" class="btn btn-lg btn-primary buynow" {{ $product->type != 'configurable' && ! $product->haveSufficientQuantity(1) ? 'disabled' : '' }}>
|
||||
<button type="submit" data-href="{{ route('shop.product.buynow', [$product->product_id, 1])}}" class="btn btn-lg btn-primary buynow" {{ $product->type != 'configurable' && ! $product->haveSufficientQuantity(1) ? 'disabled' : '' }}>
|
||||
{{ __('shop::app.products.buy-now') }}
|
||||
</button>
|
||||
|
||||
|
|
|
|||
|
|
@ -204,6 +204,20 @@
|
|||
}
|
||||
}
|
||||
document.getElementById("quantity").value = quantity;
|
||||
|
||||
var buyNowLink = $('.btn.buynow').attr('data-href');
|
||||
var splitted = buyNowLink.split("/");
|
||||
lastItem = splitted[splitted.length - 2];
|
||||
|
||||
splitted.pop();
|
||||
splitted.pop();
|
||||
|
||||
var joined = splitted.join('/');
|
||||
|
||||
var newBuyNowUrl = joined + '/' + lastItem + '/' + quantity;
|
||||
|
||||
$('.btn.buynow').attr('data-href', newBuyNowUrl);
|
||||
|
||||
event.preventDefault();
|
||||
}
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -143,17 +143,19 @@
|
|||
|
||||
//buy now anchor href changer with options
|
||||
var buyNowLink = $('.btn.buynow').attr('data-href');
|
||||
var quantity = document.getElementById('quantity').value;
|
||||
|
||||
if (this.selectedProductId != '') {
|
||||
var splitted = buyNowLink.split("/");
|
||||
|
||||
var lastItem = splitted.pop();
|
||||
splitted.pop();
|
||||
splitted.pop();
|
||||
|
||||
lastItem = this.selectedProductId;
|
||||
|
||||
var joined = splitted.join('/');
|
||||
|
||||
var newBuyNowUrl = joined + '/' + lastItem;
|
||||
var newBuyNowUrl = joined + '/' + lastItem + '/' + quantity;
|
||||
|
||||
$('.btn.buynow').attr('data-href', newBuyNowUrl);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue