Skip to content

Commit

Permalink
🍺
Browse files Browse the repository at this point in the history
  • Loading branch information
alecritson committed Jan 31, 2023
1 parent 937d946 commit dcd39cc
Show file tree
Hide file tree
Showing 16 changed files with 34 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ abstract class AbstractDiscount extends Component
* @var array
*/
public Collection $selectedCollections;

/**
* The products to restrict the coupon for.
*
Expand Down Expand Up @@ -127,7 +127,7 @@ public function mount()

$this->selectedBrands = $this->discount->brands->map(fn ($brand) => $this->mapBrandToArray($brand)) ?? collect();
$this->selectedCollections = $this->discount->collections->map(fn ($collection) => $this->mapCollectionToArray($collection)) ?? collect();

$this->selectedConditions = $this->discount->purchasableConditions()
->wherePurchasableType(Product::class)
->pluck('purchasable_id')->values()->toArray();
Expand Down Expand Up @@ -233,7 +233,7 @@ public function selectCollections(array $ids)
? $this->selectedCollections->merge($selectedCollections)
: $selectedCollections;
}

/**
* Select products given an array of IDs
*
Expand Down Expand Up @@ -379,7 +379,7 @@ public function save()
$this->selectedCollections->pluck('id')->toArray()

);

$this->discount->purchasableLimitations()
->whereNotIn('purchasable_id', $this->selectedProducts->pluck('id'))
->delete();
Expand Down Expand Up @@ -488,7 +488,7 @@ private function mapCollectionToArray($collection)
'breadcrumb' => $collection->breadcrumb,
];
}

/**
* Return the data we need from a product
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function mount()

$this->currency = Currency::getDefault();
$this->syncAvailability();

$this->selectedBrands = collect();
$this->selectedCollections = collect();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
use Livewire\Component;
use Livewire\TemporaryUploadedFile;
use Livewire\WithFileUploads;
use Lunar\Hub\Http\Livewire\Traits\CanExtendValidation;
use Lunar\Hub\Http\Livewire\Traits\HasDimensions;
use Lunar\Hub\Http\Livewire\Traits\HasImages;
use Lunar\Hub\Http\Livewire\Traits\HasPrices;
use Lunar\Hub\Http\Livewire\Traits\HasSlots;
use Lunar\Hub\Http\Livewire\Traits\Notifies;
use Lunar\Hub\Http\Livewire\Traits\CanExtendValidation;
use Lunar\Hub\Http\Livewire\Traits\WithAttributes;
use Lunar\Hub\Http\Livewire\Traits\WithLanguages;
use Lunar\Hub\Jobs\Products\GenerateVariants;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Lunar\Hub\Http\Livewire\Components\Settings\Languages;

use Illuminate\Validation\Rule;
use Livewire\Component;
use Lunar\Hub\Http\Livewire\Traits\Notifies;
use Lunar\Models\Language;
Expand Down
8 changes: 4 additions & 4 deletions packages/admin/src/Http/Livewire/Components/Tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function saveTags()
$databaseTags = Tag::whereIn('value', $this->tags)->get();

$newTags = collect($this->tags)->filter(function ($value) use ($databaseTags) {
return !$databaseTags->pluck('value')->contains($value);
return ! $databaseTags->pluck('value')->contains($value);
});

$this->taggable->tags()->sync($databaseTags);
Expand All @@ -94,12 +94,12 @@ public function getAvailableTagsProperty()
{
$tagTable = (new Tag)->getTable();

if (!$this->searchTerm) {
if (! $this->searchTerm) {
return collect();
}

return DB::table(
config('lunar.database.table_prefix') . 'taggables'
config('lunar.database.table_prefix').'taggables'
)->join($tagTable, 'tag_id', '=', "{$tagTable}.id")
->whereTaggableType(
$this->taggable->getMorphClass()
Expand All @@ -108,7 +108,7 @@ public function getAvailableTagsProperty()
->where('value', 'LIKE', "%{$this->searchTerm}%")
->pluck('value')
->filter(function ($value) {
return !in_array($value, $this->tags);
return ! in_array($value, $this->tags);
});
}

Expand Down
1 change: 0 additions & 1 deletion packages/admin/src/Views/Components/Errors.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Lunar\Hub\Views\Components;

use Illuminate\View\Component;
use Lunar\Models\Language;

class Errors extends Component
{
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/Actions/Carts/AddOrUpdatePurchasable.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function execute(
int $quantity = 1,
array $meta = []
): self {
throw_if(!$quantity, InvalidCartLineQuantityException::class);
throw_if(! $quantity, InvalidCartLineQuantityException::class);

$existing = app(GetExistingCartLine::class)->execute(
cart: $cart,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/Actions/Carts/CreateOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public function execute(
$order->addresses()->createMany($addresses->toArray());

$cart->order()->associate($order);

$cart->discounts?->each(function ($discount) {
$discount->markAsUsed()->discount->save();
});
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/DiscountTypes/AbstractDiscountType.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ public function with(Discount $discount): self

return $this;
}

/**
* Mark a discount as used
*
* @return self
*/
public function markAsUsed(): self
{
$this->discount->uses = $this->discount->uses + 1;
$this->discount->uses = $this->discount->uses + 1;

return $this;
}
Expand Down
10 changes: 5 additions & 5 deletions packages/core/src/Managers/DiscountManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ public function __construct()
public function channel(Channel|iterable $channel): self
{
$channels = collect(
!is_iterable($channel) ? [$channel] : $channel
! is_iterable($channel) ? [$channel] : $channel
);

if ($nonChannel = $channels->filter(fn ($channel) => !$channel instanceof Channel)->first()) {
if ($nonChannel = $channels->filter(fn ($channel) => ! $channel instanceof Channel)->first()) {
throw new InvalidArgumentException(
__('lunar::exceptions.discounts.invalid_type', [
'expected' => Channel::class,
Expand All @@ -99,10 +99,10 @@ public function channel(Channel|iterable $channel): self
public function customerGroup(CustomerGroup|iterable $customerGroups): self
{
$customerGroups = collect(
!is_iterable($customerGroups) ? [$customerGroups] : $customerGroups
! is_iterable($customerGroups) ? [$customerGroups] : $customerGroups
);

if ($nonGroup = $customerGroups->filter(fn ($channel) => !$channel instanceof CustomerGroup)->first()) {
if ($nonGroup = $customerGroups->filter(fn ($channel) => ! $channel instanceof CustomerGroup)->first()) {
throw new InvalidArgumentException(
__('lunar::exceptions.discounts.invalid_type', [
'expected' => CustomerGroup::class,
Expand Down Expand Up @@ -206,7 +206,7 @@ public function getApplied(): Collection

public function apply(Cart $cart): Cart
{
if (!$this->discounts) {
if (! $this->discounts) {
$this->discounts = $this->getDiscounts();
}

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/Models/Discount.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function purchasableConditions()
{
return $this->hasMany(DiscountPurchasable::class)->whereType('condition');
}

public function purchasableLimitations()
{
return $this->hasMany(DiscountPurchasable::class)->whereType('limitation');
Expand Down
8 changes: 4 additions & 4 deletions packages/core/tests/Unit/Actions/Carts/CreateOrderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,14 +282,14 @@ public function can_set_tax_breakdown_correctly()
$order->tax_breakdown->first()->percentage
);
}

/** @test */
public function increments_discount_uses()
{
$customerGroup = CustomerGroup::factory()->create([
'default' => true,
]);

$channel = Channel::factory()->create([
'default' => true,
]);
Expand Down Expand Up @@ -374,7 +374,7 @@ public function increments_discount_uses()
]);

$cart->shippingAddress->shippingOption = $shippingOption;

$discount = Discount::factory()->create([
'type' => DiscountTypesDiscount::class,
'name' => 'Test Coupon',
Expand Down Expand Up @@ -404,7 +404,7 @@ public function increments_discount_uses()
$order = $cart->createOrder();

$cart = $cart->refresh();

$discount = $discount->refresh();

$this->assertInstanceOf(Order::class, $cart->order);
Expand Down
9 changes: 4 additions & 5 deletions packages/core/tests/Unit/DiscountTypes/DiscountTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public function will_only_apply_to_lines_with_correct_brand()
$this->assertEquals(100, $cart->discountTotal->value);
$this->assertEquals(2100, $cart->total->value);
}

/** @test */
public function will_only_apply_to_lines_with_correct_product()
{
Expand All @@ -147,11 +147,11 @@ public function will_only_apply_to_lines_with_correct_product()
'currency_id' => $currency->id,
'coupon_code' => '10OFF',
]);

$brandA = Brand::factory()->create([
'name' => 'Brand A',
]);

$productA = Product::factory()->create([
'brand_id' => $brandA->id,
]);
Expand Down Expand Up @@ -225,14 +225,13 @@ public function will_only_apply_to_lines_with_correct_product()
'purchasable_type' => Product::class,
'purchasable_id' => $productA->id,
]);

$cart = $cart->calculate();

$this->assertEquals(100, $cart->discountTotal->value);
$this->assertEquals(2100, $cart->total->value);
}


/**
* @test
* @group thisdiscount
Expand Down
2 changes: 1 addition & 1 deletion packages/core/tests/Unit/Managers/DiscountManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public function can_restrict_discounts_to_customer_group()
]);

$this->assertEmpty($manager->getDiscounts());

$discount->customerGroups()->sync([
$customerGroup->id => [
'enabled' => true,
Expand Down
6 changes: 3 additions & 3 deletions packages/core/tests/Unit/Models/CartTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
use Illuminate\Support\Facades\Config;
use Lunar\DataTypes\Price as DataTypesPrice;
use Lunar\DataTypes\ShippingOption;
use Lunar\DiscountTypes\Discount as DiscountTypesDiscount;
use Lunar\Exceptions\Carts\CartException;
use Lunar\Facades\Discounts;
use Lunar\Facades\ShippingManifest;
use Lunar\Models\Cart;
use Lunar\Models\CartAddress;
Expand All @@ -15,6 +17,7 @@
use Lunar\Models\Country;
use Lunar\Models\Currency;
use Lunar\Models\Customer;
use Lunar\Models\CustomerGroup;
use Lunar\Models\Discount;
use Lunar\Models\Order;
use Lunar\Models\Price;
Expand All @@ -26,9 +29,6 @@
use Lunar\Models\TaxZonePostcode;
use Lunar\Tests\Stubs\User as StubUser;
use Lunar\Tests\TestCase;
use Lunar\DiscountTypes\Discount as DiscountTypesDiscount;
use Lunar\Facades\Discounts;
use Lunar\Models\CustomerGroup;

/**
* @group lunar.carts
Expand Down
2 changes: 1 addition & 1 deletion utils/scout-database-engine/src/DatabaseEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ protected function getSearchQuery(Builder $builder)
$index = $this->getIndexFromBuilder($builder);

return SearchIndex::where('index', '=', $index)
->whereFullText('content', $builder->query . '*', ['mode' => 'boolean']);
->whereFullText('content', $builder->query.'*', ['mode' => 'boolean']);
}

/**
Expand Down

0 comments on commit dcd39cc

Please sign in to comment.