Skip to content

Commit

Permalink
Backorders support (#494)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jade-GG authored May 21, 2024
1 parent 89635ee commit 01c5858
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
11 changes: 11 additions & 0 deletions resources/views/cart/overview.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@
@lang('Remove')
</button>
</div>
<div v-if="item.backorder_count" class="flex gap-2">
<x-heroicon-o-exclamation-circle class="mt-px w-5" />
<span>
<template v-if="item.backorder_count == item.qty">
@lang(':count of the requested quantity will be backordered', ['count' => '@{{ item.backorder_count }}'])
</template>
<template v-else>
@lang('This product will be backordered')
</template>
</span>
</div>
</div>
<div class="flex items-center justify-between gap-5">
@{{ item.price | price }}
Expand Down
10 changes: 9 additions & 1 deletion resources/views/product/partials/addtocart.blade.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<add-to-cart :default-qty="{{ $product->min_sale_qty > $product->qty_increments ? $product->min_sale_qty : $product->qty_increments }}">
<form slot-scope="{ _renderProxy: addToCartSlotProps, options, customOptions, error, add, disabledOptions, simpleProduct, adding, added, price, specialPrice, setCustomOptionFile }" v-on:submit.prevent="add">
<h1 class="mb-3 text-3xl font-bold" itemprop="name">{{ $product->name }}</h1>
@if (!$product->in_stock)
@if (!$product->in_stock && $product->backorder_type == 0)
<p class="text-red-600">@lang('Sorry! This product is currently out of stock.')</p>
@else
<div v-cloak v-for="(superAttribute, superAttributeId) in config.product.super_attributes">
Expand All @@ -18,6 +18,14 @@
</div>

@include('rapidez::product.partials.options')

@if ($product->qty <= 0 && $product->backorder_type == 2)
<div class="flex gap-2">
<x-heroicon-o-exclamation-circle class="mt-px w-5" />
<span>@lang('This product will be backordered')</span>
</div>
@endif

<div class="mt-5 flex flex-wrap items-center gap-3" v-blur>
<div>
<div class="text-2xl font-bold text-neutral" v-text="$options.filters.price(specialPrice || price)">
Expand Down
7 changes: 5 additions & 2 deletions src/Models/Quote.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Rapidez\Core\Actions\DecodeJwt;
use Rapidez\Core\Casts\CommaSeparatedToIntegerArray;
use Rapidez\Core\Casts\QuoteItems;
use Rapidez\Core\Facades\Rapidez;
use Rapidez\Core\Models\Scopes\IsActiveScope;
use TorMorten\Eventy\Facades\Eventy;

Expand All @@ -26,6 +27,7 @@ protected static function booting()
{
static::addGlobalScope(new IsActiveScope);
static::addGlobalScope('with-all-information', function (Builder $builder) {
$configBackorder = Rapidez::config('cataloginventory/item_options/backorders', 0);
$builder
->addSelect($builder->qualifyColumns([
'entity_id',
Expand Down Expand Up @@ -62,8 +64,9 @@ protected static function booting()
"total_excl_tax", quote_item.row_total,
"attributes", quote_item_option.value,
"type", quote_item.product_type
QUERY) . '
)), "$.null__") AS items')
QUERY
. '"backorder_count", IF(IF(stock.use_config_backorders, ' . $configBackorder . ', stock.backorders) = 2, GREATEST(0, quote_item.qty - stock.qty), 0)'
) . ')), "$.null__") AS items')
->leftJoin('quote_id_mask', 'quote_id_mask.quote_id', '=', $builder->getModel()->getQualifiedKeyName())
->leftJoin('oauth_token', 'oauth_token.customer_id', '=', $builder->qualifyColumn('customer_id'))
->leftJoin('quote_address', function ($join) use ($builder) {
Expand Down
4 changes: 4 additions & 0 deletions src/Models/Scopes/Product/WithProductStockScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Scope;
use Rapidez\Core\Facades\Rapidez;

class WithProductStockScope implements Scope
{
Expand All @@ -14,7 +15,10 @@ public function apply(Builder $builder, Model $model)
$builder->selectRaw('ANY_VALUE(cataloginventory_stock_item.qty) AS qty');
}

$configBackorder = Rapidez::config('cataloginventory/item_options/backorders', 0);

$builder
->selectRaw('ANY_VALUE(IF(cataloginventory_stock_item.use_config_backorders, ' . $configBackorder . ', cataloginventory_stock_item.backorders)) as backorder_type')
->selectRaw('ANY_VALUE(cataloginventory_stock_item.manage_stock) as manage_stock')
->selectRaw('ANY_VALUE(cataloginventory_stock_item.min_sale_qty) as min_sale_qty')
->selectRaw('ANY_VALUE(cataloginventory_stock_item.is_in_stock) AS in_stock')
Expand Down

0 comments on commit 01c5858

Please sign in to comment.