Merge bagisto/master into admin-backend/keep-search-terms-after-new-page-load

This commit is contained in:
Annika Wolff 2020-06-11 13:26:09 +02:00
commit af15da5433
22 changed files with 614 additions and 35 deletions

View File

@ -53,6 +53,10 @@ class ProductDataGrid extends DataGrid
$queryBuilder->where('channel', $this->channel);
}
if ($currentLocale = app()->getLocale()) {
$queryBuilder->where('product_flat.locale', $currentLocale);
}
$queryBuilder->groupBy('product_flat.product_id');
$this->addFilter('product_id', 'product_flat.product_id');

View File

@ -53,7 +53,7 @@
<div class="control-group" :class="[errors.has('inventory_sources[]') ? 'has-error' : '']">
<label for="inventory_sources" class="required">{{ __('admin::app.settings.channels.inventory_sources') }}</label>
<select v-validate="'required'" class="control" id="inventory_sources" name="inventory_sources[]" data-vv-as="&quot;{{ __('admin::app.settings.channels.inventory_sources') }}&quot;" multiple>
@foreach (app('Webkul\Inventory\Repositories\InventorySourceRepository')->all() as $inventorySource)
@foreach (app('Webkul\Inventory\Repositories\InventorySourceRepository')->findWhere(['status' => 1]) as $inventorySource)
<option value="{{ $inventorySource->id }}" {{ old('inventory_sources') && in_array($inventorySource->id, old('inventory_sources')) ? 'selected' : '' }}>
{{ $inventorySource->name }}
</option>

View File

@ -56,7 +56,7 @@
<label for="inventory_sources" class="required">{{ __('admin::app.settings.channels.inventory_sources') }}</label>
<?php $selectedOptionIds = old('inventory_sources') ?: $channel->inventory_sources->pluck('id')->toArray() ?>
<select v-validate="'required'" class="control" id="inventory_sources" name="inventory_sources[]" data-vv-as="&quot;{{ __('admin::app.settings.channels.inventory_sources') }}&quot;" multiple>
@foreach (app('Webkul\Inventory\Repositories\InventorySourceRepository')->all() as $inventorySource)
@foreach (app('Webkul\Inventory\Repositories\InventorySourceRepository')->findWhere(['status' => 1]) as $inventorySource)
<option value="{{ $inventorySource->id }}" {{ in_array($inventorySource->id, $selectedOptionIds) ? 'selected' : '' }}>
{{ $inventorySource->name }}
</option>

View File

@ -0,0 +1,36 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddSalePricesToBookingProductEventTickets extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('booking_product_event_tickets', function (Blueprint $table) {
$table->decimal('special_price', 12,4)->after('qty')->nullable();
$table->dateTime('special_price_from')->after('special_price')->nullable();
$table->dateTime('special_price_to')->after('special_price_from')->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('booking_product_event_tickets', function (Blueprint $table) {
$table->dropColumn('special_price');
$table->dropColumn('special_price_from');
$table->dropColumn('special_price_to');
});
}
}

View File

@ -47,10 +47,19 @@ class EventTicket extends Booking
public function formatPrice($tickets)
{
foreach ($tickets as $index => $ticket) {
$price = $ticket->price;
if ($this->isInSale($ticket)) {
$price = $ticket->special_price;
$tickets[$index]['original_converted_price'] = core()->convertPrice($ticket->price);
$tickets[$index]['original_formated_price'] = core()->currency($ticket->price);
}
$tickets[$index]['id'] = $ticket->id;
$tickets[$index]['converted_price'] = core()->convertPrice($ticket->price);
$tickets[$index]['formated_price'] = $formatedPrice = core()->currency($ticket->price);
$tickets[$index]['formated_price_text'] = trans('bookingproduct::app.shop.products.per-ticket-price', ['price' => $formatedPrice]);
$tickets[$index]['converted_price'] = core()->convertPrice($price);
$tickets[$index]['formated_price'] = $formatedPrice = core()->currency($price);
$tickets[$index]['formated_price_text'] = __('bookingproduct::app.shop.products.per-ticket-price', ['price' => $formatedPrice]);
}
return $tickets;
@ -102,10 +111,15 @@ class EventTicket extends Booking
$ticket = $bookingProduct->event_tickets()->find($product['additional']['booking']['ticket_id']);
$products[$key]['price'] += core()->convertPrice($ticket->price);
$products[$key]['base_price'] += $ticket->price;
$products[$key]['total'] += (core()->convertPrice($ticket->price) * $products[$key]['quantity']);
$products[$key]['base_total'] += ($ticket->price * $products[$key]['quantity']);
$price = $ticket->price;
if ($this->isInSale($ticket)) {
$price = $ticket->special_price;
}
$products[$key]['price'] += core()->convertPrice($price);
$products[$key]['base_price'] += $price;
$products[$key]['total'] += (core()->convertPrice($price) * $products[$key]['quantity']);
$products[$key]['base_total'] += ($price * $products[$key]['quantity']);
}
return $products;
@ -131,9 +145,13 @@ class EventTicket extends Booking
return true;
}
$price += $ticket->price;
if ($this->isInSale($ticket)) {
$price += $ticket->special_price;
} else {
$price += $ticket->price;
}
if ($price == $item->base_price) {
if ($price === $item->base_price) {
return;
}
@ -145,4 +163,17 @@ class EventTicket extends Booking
$item->save();
}
/**
* Determines whether a single ticket is in Sale, i.e. has a valid sale price
*
* @return bool
*/
public function isInSale($ticket): bool
{
return $ticket->special_price !== null
&& $ticket->special_price > 0.0
&& ($ticket->special_price_from === null || $ticket->special_price_from === '0000-00-00 00:00:00' || $ticket->special_price_from <= Carbon::now())
&& ($ticket->special_price_to === null || $ticket->special_price_to === '0000-00-00 00:00:00' || $ticket->special_price_to > Carbon::now());
}
}

View File

@ -10,10 +10,13 @@ class BookingProductEventTicket extends TranslatableModel implements BookingProd
public $timestamps = false;
public $translatedAttributes = ['name', 'description'];
protected $fillable = [
'price',
'qty',
'special_price',
'special_price_from',
'special_price_to',
'booking_product_id',
];
}

View File

@ -28,6 +28,31 @@ class BookingProductEventTicketRepository extends Repository
if (isset($data['tickets'])) {
foreach ($data['tickets'] as $ticketId => $ticketInputs) {
if (
! array_key_exists('special_price', $ticketInputs)
|| empty($ticketInputs['special_price'])
|| $ticketInputs['special_price'] === '0.0000'
) {
$ticketInputs['special_price'] = null;
}
if (
! array_key_exists('special_price_from', $ticketInputs)
|| empty($ticketInputs['special_price_from'])
|| $ticketInputs['special_price_from'] === '0000-00-00 00:00:00'
) {
$ticketInputs['special_price_from'] = null;
}
if (
! array_key_exists('special_price_to', $ticketInputs)
|| empty($ticketInputs['special_price_to'])
|| $ticketInputs['special_price_to'] === '0000-00-00 00:00:00'
) {
$ticketInputs['special_price_to'] = null;
}
if (Str::contains($ticketId, 'ticket_')) {
$this->create(array_merge([
'booking_product_id' => $bookingProduct->id,

View File

@ -48,6 +48,9 @@ return [
'price' => 'السعر',
'quantity' => 'كمية',
'description' => 'وصف',
'special-price' => 'Special Price',
'special-price-from' => 'Valid From',
'special-price-to' => 'Valid Until',
'charged-per' => 'اتهم لكل',
'guest' => 'زائر',
'table' => 'الطاولة',

View File

@ -48,6 +48,9 @@ return [
'price' => 'Price',
'quantity' => 'Quantity',
'description' => 'Description',
'special-price' => 'Special Price',
'special-price-from' => 'Valid From',
'special-price-to' => 'Valid Until',
'charged-per' => 'Charged Per',
'guest' => 'Guest',
'table' => 'Table',

View File

@ -48,6 +48,9 @@ return [
'price' => 'قیمت',
'quantity' => 'تعداد',
'description' => 'شرح',
'special-price' => 'Special Price',
'special-price-from' => 'Valid From',
'special-price-to' => 'Valid Until',
'charged-per' => 'به اتهام در هر',
'guest' => 'مهمان',
'table' => 'جدول',

View File

@ -48,6 +48,9 @@ return [
'price' => 'Prezzo',
'quantity' => 'Quantità',
'description' => 'Descrizione',
'special-price' => 'Special Price',
'special-price-from' => 'Valid From',
'special-price-to' => 'Valid Until',
'charged-per' => 'Charged Per',
'guest' => 'Ospite',
'table' => 'Tavolo',

View File

@ -48,6 +48,9 @@ return [
'price' => 'Prijs',
'quantity' => 'Aantal stuks',
'description' => 'Beschrijving',
'special-price' => 'Special Price',
'special-price-from' => 'Valid From',
'special-price-to' => 'Valid Until',
'charged-per' => 'In rekening gebracht per',
'guest' => 'Gast',
'table' => 'Tafel',

View File

@ -48,6 +48,9 @@ return [
'price' => 'Preço',
'quantity' => 'Quantidade',
'description' => 'Descrição',
'special-price' => 'Special Price',
'special-price-from' => 'Valid From',
'special-price-to' => 'Valid Until',
'charged-per' => 'Cobrado por',
'guest' => 'Hóspede',
'table' => 'Mesa',

View File

@ -17,7 +17,7 @@
<div class="section-content">
<ticket-list :tickets="tickets"></ticket-list>
</div>
</div>
</div>
@ -26,16 +26,6 @@
<script type="text/x-template" id="ticket-list-template">
<div class="ticket-list table">
<table>
<thead>
<tr>
<th>{{ __('bookingproduct::app.admin.catalog.products.name') }}</th>
<th>{{ __('bookingproduct::app.admin.catalog.products.price') }}</th>
<th>{{ __('bookingproduct::app.admin.catalog.products.quantity') }}</th>
<th>{{ __('bookingproduct::app.admin.catalog.products.description') }}</th>
<th class="actions"></th>
</tr>
</thead>
<tbody>
<ticket-item
v-for="(ticket, index) in tickets"
@ -57,36 +47,65 @@
<tr>
<td>
<div class="control-group" :class="[errors.has(controlName + '[{{$locale}}][name]') ? 'has-error' : '']">
<label class="ticket-label">{{ __('bookingproduct::app.admin.catalog.products.name') }}</label>
<input type="text" v-validate="'required'" :name="controlName + '[{{$locale}}][name]'" v-model="ticketItem.name" class="control" data-vv-as="&quot;{{ __('bookingproduct::app.admin.catalog.products.name') }}&quot;">
<span class="control-error" v-if="errors.has(controlName + '[{{$locale}}][name]')">
@{{ errors.first(controlName + '[{!!$locale!!}][name]') }}
</span>
</div>
<div class="control-group">
<label class="ticket-label">{{ __('bookingproduct::app.admin.catalog.products.special-price') }}</label>
<input type="text" :name="controlName + '[special_price]'" v-model="ticketItem.special_price" class="control">
</div>
</td>
<td>
<div class="control-group" :class="[errors.has(controlName + '[price]') ? 'has-error' : '']">
<label class="ticket-label">{{ __('bookingproduct::app.admin.catalog.products.price') }}</label>
<input type="text" v-validate="'required'" :name="controlName + '[price]'" v-model="ticketItem.price" class="control" data-vv-as="&quot;{{ __('bookingproduct::app.admin.catalog.products.price') }}&quot;">
<span class="control-error" v-if="errors.has(controlName + '[price]')">
@{{ errors.first(controlName + '[price]') }}
</span>
</div>
<div class="control-group date" :class="[errors.has(controlName + '[special_price_from]') ? 'has-error' : '']">
<label class="ticket-label">{{ __('bookingproduct::app.admin.catalog.products.special-price-from') }}</label>
<datetime>
<input type="text" v-validate="'date_format:yyyy-MM-dd HH:mm:ss|after:{{\Carbon\Carbon::yesterday()->format('Y-m-d 23:59:59')}}'" :name="controlName + '[special_price_from]'" v-model="ticketItem.special_price_from" class="control" data-vv-as="&quot;{{ __('bookingproduct::app.admin.catalog.products.special-price-from') }}&quot;" ref="special_price_from" style="width:70%"/>
</datetime>
<span class="control-error" v-if="errors.has(controlName + '[special_price_from]')">@{{ errors.first(controlName + '[special_price_from]') }}</span>
</div>
</td>
<td>
<div class="control-group" :class="[errors.has(controlName + '[qty]') ? 'has-error' : '']">
<label class="ticket-label">{{ __('bookingproduct::app.admin.catalog.products.quantity') }}</label>
<input type="text" v-validate="'required|min_value:0'" :name="controlName + '[qty]'" v-model="ticketItem.qty" class="control" data-vv-as="&quot;{{ __('bookingproduct::app.admin.catalog.products.qty') }}&quot;">
<span class="control-error" v-if="errors.has(controlName + '[qty]')">
@{{ errors.first(controlName + '[qty]') }}
</span>
</div>
<div class="control-group date" :class="[errors.has(controlName + '[special_price_to]') ? 'has-error' : '']">
<label class="ticket-label">{{ __('bookingproduct::app.admin.catalog.products.special-price-to') }}</label>
<datetime>
<input type="text" v-validate="'date_format:yyyy-MM-dd HH:mm:ss|after:special_price_from'" :name="controlName + '[special_price_to]'" v-model="ticketItem.special_price_to" class="control" data-vv-as="&quot;{{ __('bookingproduct::app.admin.catalog.products.special-price-to') }}&quot;" ref="special_price_to" style="width:70%"/>
</datetime>
<span class="control-error" v-if="errors.has(controlName + '[special_price_to]')">@{{ errors.first(controlName + '[special_price_to]') }}</span>
</div>
</td>
<td>
<div class="control-group" :class="[errors.has(controlName + '[{{$locale}}][description]') ? 'has-error' : '']">
<label class="ticket-label">{{ __('bookingproduct::app.admin.catalog.products.description') }}</label>
<textarea type="text" v-validate="'required'" :name="controlName + '[{{$locale}}][description]'" v-model="ticketItem.description" class="control" data-vv-as="&quot;{{ __('bookingproduct::app.admin.catalog.products.description') }}&quot;"></textarea>
<span class="control-error" v-if="errors.has(controlName + '[{{$locale}}][description]')">
@ -129,7 +148,10 @@
'name': '',
'price': '',
'qty': 0,
'description': ''
'description': '',
'special_price': '',
'special_price_from': '',
'special_price_to': '',
});
},
@ -166,4 +188,10 @@
});
</script>
@endpush
<style>
.ticket-label {
font-weight: 700;
margin: 20px 0 10px 0;
}
</style>
@endpush

View File

@ -25,7 +25,11 @@
@{{ ticket.name }}
</div>
<div class="ticket-price">
<div v-if="ticket.original_formated_price" class="ticket-price">
<span class="regular-price">@{{ ticket.original_formated_price }}</span>
<span class="special-price">@{{ ticket.formated_price_text }}</span>
</div>
<div v-else class="ticket-price">
@{{ ticket.formated_price_text }}
</div>
</div>
@ -62,4 +66,15 @@
</script>
<style>
.ticket-price .regular-price{
color: #a5a5a5;
text-decoration: line-through;
margin-right: 5px;
}
.ticket-price .special-price {
color: #ff6472;
font-size: larger;
}
</style>
@endpush

View File

@ -25,7 +25,11 @@
@{{ ticket.name }}
</div>
<div class="ticket-price">
<div v-if="ticket.original_formated_price" class="ticket-price">
<span class="regular-price">@{{ ticket.original_formated_price }}</span>
<span class="special-price">@{{ ticket.formated_price_text }}</span>
</div>
<div v-else class="ticket-price">
@{{ ticket.formated_price_text }}
</div>
</div>
@ -62,4 +66,15 @@
</script>
<style>
.ticket-price .regular-price{
color: #a5a5a5;
text-decoration: line-through;
margin-right: 5px;
}
.ticket-price .special-price {
color: #ff6472;
font-size: larger;
}
</style>
@endpush

View File

@ -2,14 +2,10 @@
namespace Webkul\Customer\Http\Controllers;
use Illuminate\Foundation\Auth\SendsPasswordResetEmails;
use Illuminate\Support\Facades\Password;
class ForgotPasswordController extends Controller
{
use SendsPasswordResetEmails;
/**
* Contains route related configuration
*

View File

@ -175,7 +175,7 @@ class ProductController extends Controller
$categories = $this->categoryRepository->getCategoryTree();
$inventorySources = $this->inventorySourceRepository->all();
$inventorySources = $this->inventorySourceRepository->findWhere(['status' => 1]);
return view($this->_config['view'], compact('product', 'categories', 'inventorySources'));
}
@ -303,7 +303,7 @@ class ProductController extends Controller
/**
* To be manually invoked when data is seeded into products
*
*
* @return \Illuminate\Http\Response
*/
public function sync()

View File

@ -23,7 +23,7 @@
@stop
@section('seo')
<meta name="description" content="{{ trim($product->meta_description) != "" ? $product->meta_description : str_limit(strip_tags($product->description), 120, '') }}"/>
<meta name="description" content="{{ trim($product->meta_description) != "" ? $product->meta_description : \Illuminate\Support\Str::limit(strip_tags($product->description), 120, '') }}"/>
<meta name="keywords" content="{{ $product->meta_keywords }}"/>

View File

@ -20,10 +20,11 @@ modules:
connection_timeout: 60
request_timeout: 60
log_js_errors: true
- Laravel5:
- Webkul\Core\Helpers\Laravel5Helper:
part: ORM
cleanup: false
environment_file: .env
database_seeder_class: DatabaseSeeder
url: http://nginx
step_decorators: ~

View File

@ -0,0 +1,49 @@
<?php
namespace Tests\Acceptance\BookingProduct;
use AcceptanceTester;
use Carbon\Carbon;
use Faker\Factory;
use Webkul\BookingProduct\Models\BookingProduct;
use Webkul\BookingProduct\Models\BookingProductEventTicket;
use Webkul\Core\Helpers\Laravel5Helper;
use Webkul\Product\Models\Product;
class BookingProductEventTicketCest
{
protected $faker;
public function _before(): void
{
$this->faker = Factory::create();
}
public function testSpecialPricesAreShown(AcceptanceTester $I): void
{
$product = $I->haveProduct(Laravel5Helper::VIRTUAL_PRODUCT);
Product::query()->where('id', $product->id)->update(['type' => 'booking']);
$bookingProduct = $I->have(BookingProduct::class, [
'type' => 'event',
'available_to' => Carbon::now()->addMinutes($this->faker->numberBetween(2, 59))->toDateTimeString(),
'product_id' => $product->id,
]);
$scenario['ticket'] = [
'price' => 10,
'special_price' => 5
];
$ticket = $I->have(BookingProductEventTicket::class, array_merge(
['booking_product_id' => $bookingProduct->id], $scenario['ticket'])
);
$I->amOnPage($product->url_key);
$I->see(core()->currency($ticket->price), '//span[@class="regular-price"]');
$I->see(__('bookingproduct::app.shop.products.per-ticket-price', ['price' => core()->currency($ticket->special_price)]),
'//span[@class="special-price"]');
}
}

View File

@ -0,0 +1,358 @@
<?php
use Carbon\Carbon;
use Codeception\Example;
use Webkul\BookingProduct\Helpers\EventTicket;
use Webkul\BookingProduct\Models\BookingProduct;
use Webkul\BookingProduct\Models\BookingProductEventTicket;
use Webkul\Checkout\Models\CartItem;
use Webkul\Core\Helpers\Laravel5Helper;
use Webkul\Product\Models\Product;
class BookingProductEventTicketCest
{
protected $typeHelper, $bookingProduct;
public function _before(UnitTester $I): void
{
$this->typeHelper = app(EventTicket::class);
$product = $I->haveProduct(Laravel5Helper::VIRTUAL_PRODUCT);
Product::query()->where('id', $product->id)->update(['type' => 'booking']);
$availableTo = Carbon::now()->addMinutes($I->fake()->numberBetween(2, 59));
$this->bookingProduct = $I->have(BookingProduct::class, [
'type' => 'event',
'available_to' => $availableTo->toDateTimeString(),
'product_id' => $product->id,
]);
}
/**
* @param UnitTester $I
* @param Example $scenario
*
* @dataProvider getTestDataForFormatPrice
*/
public function testFormatPrice(UnitTester $I, Example $scenario): void
{
$tickets[] = $I->have(BookingProductEventTicket::class, array_merge(
['booking_product_id' => $this->bookingProduct->id], $scenario['ticket'])
);
$formattedTickets = $this->typeHelper->formatPrice($tickets);
foreach ($scenario['expectFields'] as $field) {
$I->assertEquals($scenario['expectFields']['converted_price'], $formattedTickets[0]['converted_price']);
}
}
/**
* @param UnitTester $I
* @param Example $scenario
*
* @dataProvider getTestDataForAddAdditionalPrices
*/
public function testAddAdditionalPrices(UnitTester $I, Example $scenario): void
{
$ticket = $I->have(BookingProductEventTicket::class, array_merge(
['booking_product_id' => $this->bookingProduct->id], $scenario['ticket'])
);
$inputData = $scenario['inputData'];
$inputData['product_id'] = $this->bookingProduct->product_id;
$inputData['additional']['product_id'] = $this->bookingProduct->product_id;
$inputData['additional']['booking']['ticket_id'] = $ticket->id;
$addTicketPrices = $this->typeHelper->addAdditionalPrices([$inputData]);
$I->assertEquals($scenario['expected']['price'], $addTicketPrices[0]['price']);
$I->assertEquals($scenario['expected']['base_price'], $addTicketPrices[0]['base_price']);
$I->assertEquals($scenario['expected']['total'], $addTicketPrices[0]['total']);
$I->assertEquals($scenario['expected']['base_total'], $addTicketPrices[0]['base_total']);
}
/**
* @param UnitTester $I
* @param Example $scenario
*
* @dataProvider getTestDataForValidateCartItem
*/
public function testValidateCartItem(UnitTester $I, Example $scenario): void
{
$ticket = $I->have(BookingProductEventTicket::class, array_merge(
['booking_product_id' => $this->bookingProduct->id], $scenario['ticket'])
);
$product = Product::query()->find($this->bookingProduct->product_id);
$data = [
'is_buy_now' => 0,
'product_id' => $product->id,
'quantity' => $scenario['qty'],
"booking" => [
"qty" => [
$ticket->id => $scenario['qty'],
]
]
];
$cart = cart()->addProduct($product->id, $data);
$I->assertEquals('booking', $cart->items[0]->type);
$product->getTypeInstance()->validateCartItem($cart->items[0]);
$finalPrice = $product->price + $scenario['expected'];
$finalTotal = ($product->price + $scenario['expected']) * $scenario['qty'];
$I->seeRecord(CartItem::class, [
'id' => $cart->items[0]->id,
'price' => core()->convertPrice($finalPrice),
'base_price' => $finalPrice,
'total' => core()->convertPrice($finalTotal),
'base_total' => $finalTotal,
]);
}
/**
* @param UnitTester $I
* @param Example $scenario
*
* @dataProvider getTestDataForHasSalePrice
*/
public function testHasSalePrice(UnitTester $I, Example $scenario): void
{
$ticket = $I->have(BookingProductEventTicket::class, array_merge(
['booking_product_id' => $this->bookingProduct->id], $scenario['ticket'])
);
$I->assertEquals($scenario['expect'], $this->typeHelper->isInSale($ticket));
}
/* Data Providers */
private function getTestDataForFormatPrice(): array
{
return [
[
'ticket' => ['price' => 10],
'expectFields' => [
'converted_price' => 10,
'formated_price' => '$10.00',
'formated_price_text' => '$10.00 Per Ticket'
]
],
[
'ticket' => ['price' => 20, 'special_price' => 10],
'expectFields' => [
'converted_price' => 10,
'formated_price' => '$10.00',
'formated_price_text' => '$10.00 Per Ticket',
'original_converted_price' => 20,
'original_formated_price' => '$20.00',
]
],
[
'ticket' => [
'price' => 20,
'special_price' => 10,
'special_price_from' => '0000-00-00 00:00:00',
'special_price_to' => '0000-00-00 00:00:00',
],
'expectFields' => [
'converted_price' => 10,
'formated_price' => '$10.00',
'formated_price_text' => '$10.00 Per Ticket',
'original_converted_price' => 20,
'original_formated_price' => '$20.00',
]
],
[
'ticket' => [
'price' => 10,
'special_price' => 7,
'special_price_from' => Carbon::yesterday(),
'special_price_to' => Carbon::now(),
],
'expectFields' => [
'converted_price' => 10,
'formated_price' => '$10.00',
'formated_price_text' => '$10.00 Per Ticket',
]
],
];
}
private function getTestDataForAddAdditionalPrices(): array
{
return [
[
'ticket' => ['price' => 5],
'inputData' => [
'quantity' => 1,
'price' => 10.0,
'base_price' => 10.0,
'total' => 10.0,
'base_total' => 10.0,
'additional' => [
'quantity' => 1,
]
],
'expected' => [
'price' => 15.0,
'base_price' => 15.0,
'total' => 15.0,
'base_total' => 15.0,
]
],
[
'ticket' => ['price' => 20, 'special_price' => 10],
'inputData' => [
'quantity' => 1,
'price' => 20.0,
'base_price' => 20.0,
'total' => 20.0,
'base_total' => 20.0,
'additional' => [
'quantity' => 1,
]
],
'expected' => [
'price' => 30.0,
'base_price' => 30.0,
'total' => 30.0,
'base_total' => 30.0,
]
],
[
'ticket' => ['price' => 20, 'special_price' => 10],
'inputData' => [
'quantity' => 2,
'price' => 20.0,
'base_price' => 20.0,
'total' => 20.0,
'base_total' => 20.0,
'additional' => [
'quantity' => 2,
]
],
'expected' => [
'price' => 30.0,
'base_price' => 30.0,
'total' => 40.0,
'base_total' => 40.0,
]
],
];
}
private function getTestDataForValidateCartItem(): array
{
return [
[
'ticket' => ['price' => 10],
'qty' => 1,
'expected' => 10,
],
[
'ticket' => ['price' => 20, 'special_price' => 10],
'qty' => 1,
'expected' => 10,
],
[
'ticket' => ['price' => 20, 'special_price' => 10],
'qty' => 2,
'expected' => 10
],
[
'ticket' => [
'price' => 20,
'special_price' => 10,
'special_price_from' => '0000-00-00 00:00:00',
'special_price_to' => '0000-00-00 00:00:00',
],
'qty' => 2,
'expected' => 10
],
[
'ticket' => [
'price' => 10,
'special_price' => 7,
'special_price_from' => Carbon::yesterday(),
'special_price_to' => Carbon::now(),
],
'qty' => 2,
'expected' => 10
],
];
}
private function getTestDataForHasSalePrice(): array
{
return [
[
'ticket' => [
'price' => '10.0000',
'special_price' => null
],
'expect' => false
],
[
'ticket' => [
'price' => '10.0000',
'special_price' => '5.0000'
],
'expect' => true
],
[
'ticket' => [
'price' => '10.0000',
'special_price' => '5.0000',
'special_price_from' => null,
'special_price_to' => null,
],
'expect' => true
],
[
'ticket' => [
'price' => '10.0000',
'special_price' => '5.0000',
'special_price_from' => '0000-00-00 00:00:00',
'special_price_to' => '0000-00-00 00:00:00',
],
'expect' => true
],
[
'ticket' => [
'price' => '10.0000',
'special_price' => '5.0000',
'special_price_from' => Carbon::yesterday(),
'special_price_to' => Carbon::tomorrow(),
],
'expect' => true
],
[
'ticket' => [
'price' => '10.0000',
'special_price' => '5.0000',
'special_price_from' => Carbon::yesterday(),
'special_price_to' => Carbon::now(),
],
'expect' => false
],
[
'ticket' => [
'price' => '10.0000',
'special_price' => '5.0000',
'special_price_from' => Carbon::now(),
'special_price_to' => Carbon::tomorrow(),
],
'expect' => true
],
];
}
}