Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add backorders to rapidez 2.0 #516

Merged
merged 3 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions resources/views/cart/item.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ class="mx-auto"
</template>
</div>
@include('rapidez::cart.item.remove')
<div v-if="item.qty_backordered" class="flex gap-2">
<x-heroicon-o-exclamation-circle class="mt-px w-5" />
<span>
<template v-if="item.qty_backordered < item.qty">
@lang(':count of the requested quantity will be backordered', ['count' => '@{{ item.qty_backordered }}'])
</template>
<template v-else>
@lang('This product will be backordered')
</template>
</span>
</div>

</div>
</td>
<td class="justify-center text-right max-md:flex max-md:w-full">
Expand Down
3 changes: 3 additions & 0 deletions resources/views/cart/queries/cart.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ total_quantity
items {
id
quantity
@if (Rapidez::checkCompadreVersion('0.0.2'))
qty_backordered
@endif
product {
@foreach(collect([
'id',
Expand Down
9 changes: 8 additions & 1 deletion resources/views/product/partials/addtocart.blade.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
<add-to-cart :default-qty="{{ $product->min_sale_qty > $product->qty_increments ? $product->min_sale_qty : $product->qty_increments }}" v-slot="addToCart">
<form v-on:submit.prevent="addToCart.add" class="flex flex-col gap-5">
<h1 class="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
@include('rapidez::product.partials.super_attributes')
@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="flex flex-wrap items-center gap-3">
<div>
<div class="text-2xl font-bold text-neutral" v-text="$options.filters.price(addToCart.specialPrice || addToCart.price)">
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
Loading