Skip to content
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
2 changes: 1 addition & 1 deletion docs/core/reference/carts.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ CartSession::add($purchasable, $quantity);
```php
CartSession::addLines([
[
'id' => 1,
'purchasable' => \Lunar\Models\ProductVariant::find(123),
'quantity' => 25,
'meta' => ['foo' => 'bar'],
],
Expand Down
1 change: 1 addition & 0 deletions docs/package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"type": "module",
"devDependencies": {
"vitepress": "^1.0.0-rc.31"
},
Expand Down
1 change: 0 additions & 1 deletion packages/admin/resources/lang/en/partials.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@
'discounts.limitations.limitation' => 'Limitation',
'discounts.limitations.exclusion' => 'Exclusion',
/**

* Product Collections.
*/
'products.collections.heading' => 'Collections',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public function getPreviewHtmlProperty()
{
$mailer = $this->availableMailers[$this->previewTemplate] ?? null;

if (!$mailer) {
if (! $mailer) {
return 'Unable to load preview';
}

Expand Down Expand Up @@ -169,7 +169,7 @@ public function updateStatus()

if (method_exists($mailable, 'render')) {
}
$storedPath = 'orders/activity/' . Str::random() . '.html';
$storedPath = 'orders/activity/'.Str::random().'.html';

$storedMailer = Storage::put(
$storedPath,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,15 @@ public function create()
$handle = Str::handle("{$this->typeHandle}_{$this->attributeGroup->translate('name')}");
$this->attributeGroup->handle = $handle;

$uniquenessConstraint = 'unique:' . get_class($this->attributeGroup) . ',handle';
$uniquenessConstraint = 'unique:'.get_class($this->attributeGroup).',handle';
if ($this->attributeGroup->id) {
$uniquenessConstraint .= ',' . $this->attributeGroup->id;
$uniquenessConstraint .= ','.$this->attributeGroup->id;
}

$this->validate([
'attributeGroup.handle' => $uniquenessConstraint,
]);


if ($this->attributeGroup->id) {
$this->attributeGroup->save();
$this->emit('attribute-group-edit.updated', $this->attributeGroup->id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function can_mount_component()
'currency_code' => Currency::getDefault()->code,
'meta' => [
'foo' => 'bar',
]
],
]);

$this->assertCount(0, $order->lines);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,34 @@

class ProductOptionCreateTest extends TestCase
{
use RefreshDatabase;

public function setUp(): void
{
parent::setUp();

Language::factory()->create([
'default' => true,
'code' => 'en',
]);
}

/**
* @test
* */
public function can_populate_product_option_data()
{
$staff = Staff::factory()->create([
'admin' => true,
]);

LiveWire::actingAs($staff, 'staff')
->test(OptionsIndex::class)
->set('newProductOption.name.' . Language::getDefault()->code, 'Size')
->call('createOption');

$this->assertDatabaseHas((new ProductOption())->getTable(), [
'name' => json_encode([Language::getDefault()->code => 'Size']),
]);
}
use RefreshDatabase;

public function setUp(): void
{
parent::setUp();

Language::factory()->create([
'default' => true,
'code' => 'en',
]);
}

/**
* @test
* */
public function can_populate_product_option_data()
{
$staff = Staff::factory()->create([
'admin' => true,
]);

LiveWire::actingAs($staff, 'staff')
->test(OptionsIndex::class)
->set('newProductOption.name.'.Language::getDefault()->code, 'Size')
->call('createOption');

$this->assertDatabaseHas((new ProductOption())->getTable(), [
'name' => json_encode([Language::getDefault()->code => 'Size']),
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ public function can_populate_product_option_data()

LiveWire::actingAs($staff, 'staff')
->test(OptionEdit::class, ['productOption' => $option])
->set('newProductOptionValue.name.' . Language::getDefault()->code, 'Size')
->set('newProductOptionValue.name.'.Language::getDefault()->code, 'Size')
->call('createOptionValue');

$this->assertDatabaseHas((new ProductOptionValue())->getTable(), [
'product_option_id' => $option->id,
'name' => json_encode([Language::getDefault()->code => 'Size'])
'name' => json_encode([Language::getDefault()->code => 'Size']),
]);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ public function down()
{
Schema::table($this->prefix.'brand_discount', function ($table) {
$table->dropColumn('type');
});
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ public function down()
{
Schema::table($this->prefix.'collection_discount', function ($table) {
$table->dropColumn('type');
});
});
}
}
8 changes: 3 additions & 5 deletions packages/core/database/state/ConvertTaxbreakdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ public function prepare()
public function run()
{
DB::usingConnection(config('lunar.database.connection') ?: DB::getDefaultConnection(), function () {

$prefix = config('lunar.database.table_prefix');
$updateTime = now();

if ($this->canRunOnOrders()) {
DB::table("{$prefix}orders")
->whereJsonContainsKey("{$prefix}orders.tax_breakdown->[0]->total")
Expand All @@ -42,7 +41,7 @@ public function run()
}
});
}

if ($this->canRunOnOrderLines()) {
DB::table("{$prefix}order_lines")
->whereJsonContainsKey("{$prefix}order_lines.tax_breakdown->[0]->total")
Expand All @@ -57,7 +56,7 @@ public function run()
DB::transaction(function () use ($prefix, $updateTime, $rows) {
foreach ($rows as $row) {
$originalBreakdown = json_decode($row->tax_breakdown, true);

DB::table("{$prefix}order_lines")->where('id', '=', $row->id)->update([
'tax_breakdown' => collect($originalBreakdown)->map(function ($breakdown) use ($row) {
return [
Expand All @@ -74,7 +73,6 @@ public function run()
});
});
}

});
}

Expand Down
3 changes: 1 addition & 2 deletions packages/core/src/Actions/Taxes/GetTaxZoneCountry.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@ public function execute($countryId)
return $taxZone;
}

if (!$taxZone) {
if (! $taxZone) {
return null;
}
}

/**
* Return the zone or zones which match this country.
*
* @param int $countryId
* @return TaxZoneCountry|null
*/
protected function getZone(int $countryId)
Expand Down
9 changes: 5 additions & 4 deletions packages/core/src/Base/Casts/TaxBreakdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ public function get($model, $key, $value, $attributes)

$breakdown->amounts = collect(
json_decode($value, false)
)->mapWithKeys(function ($amount, $key) use ($model) {
)->mapWithKeys(function ($amount, $key) {
$currency = BlinkFacade::once("currency_{$amount->currency_code}", function () use ($amount) {
return Currency::whereCode($amount->currency_code)->first();
return Currency::whereCode($amount->currency_code)->first();
});

return [
Expand All @@ -51,8 +51,9 @@ public function get($model, $key, $value, $attributes)
* @param string $key
* @param Price $value
* @param array $attributes
* @throws \Exception
* @return array
*
* @throws \Exception
*/
public function set($model, $key, $value, $attributes)
{
Expand Down Expand Up @@ -82,7 +83,7 @@ public function set($model, $key, $value, $attributes)
*
* @param \Illuminate\Database\Eloquent\Model $model
* @param string $key
* @param mixed $value
* @param mixed $value
* @param array<string, mixed> $attributes
*/
public function serialize($model, $key, $value, $attributes)
Expand Down
25 changes: 23 additions & 2 deletions packages/core/src/Base/Traits/LogsActivity.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

namespace Lunar\Base\Traits;

use Illuminate\Support\Arr;
use Spatie\Activitylog\LogOptions;
use Spatie\Activitylog\Traits\LogsActivity as SpatieLogsActivity;

trait LogsActivity
{
use SpatieLogsActivity;

public static array $logExcept = [];

/**
* Get the log options for the activity log.
*/
Expand All @@ -17,7 +20,25 @@ public function getActivitylogOptions(): LogOptions
return LogOptions::defaults()
->useLogName('lunar')
->logAll()
->dontSubmitEmptyLogs()
->logExcept(['updated_at']);
->logExcept(array_merge(['updated_at'], static::getActivitylogExcept()))
->logOnlyDirty()
->dontSubmitEmptyLogs();
}

public static function addActivitylogExcept(array|string $fields)
{
$fields = Arr::wrap($fields);

static::$logExcept = array_merge(static::$logExcept, $fields);
}

public static function getDefaultLogExcept(): array
{
return [];
}

public static function getActivitylogExcept(): array
{
return array_merge(static::getDefaultLogExcept(), static::$logExcept);
}
}
22 changes: 11 additions & 11 deletions packages/core/src/DiscountTypes/AmountOff.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,28 +110,28 @@ private function applyFixedValue(array $values, Cart $cart): Cart
$lines->filter(function ($line) {
return $line->subTotalDiscounted->value > 0;
})
->each(function($line) use ($affectedLines, $cart, &$remaining) {
->each(function ($line) use ($affectedLines, $cart, &$remaining) {
if ($remaining <= 0) {
return;
}

$amountAvailable = min($line->subTotalDiscounted->value, $remaining);
$remaining -= $amountAvailable;

$newDiscountTotal = $line->discountTotal->value + $amountAvailable;

$line->discountTotal = new Price(
$newDiscountTotal,
$cart->currency,
1
);

$line->subTotalDiscounted = new Price(
$line->subTotal->value - $newDiscountTotal,
$cart->currency,
1
);

if (! $affectedLines->first(function ($breakdownLine) use ($line) {
return $breakdownLine->line == $line;
})) {
Expand Down Expand Up @@ -165,14 +165,14 @@ protected function getEligibleLines(Cart $cart): \Illuminate\Support\Collection
{
$collectionIds = $this->discount->collections->where('pivot.type', 'limitation')->pluck('id');
$collectionExclusionIds = $this->discount->collections->where('pivot.type', 'exclusion')->pluck('id');

$brandIds = $this->discount->brands->where('pivot.type', 'limitation')->pluck('id');
$brandExclusionIds = $this->discount->brands->where('pivot.type', 'exclusion')->pluck('id');

$productIds = $this->discount->purchasableLimitations
->reject(fn ($limitation) => ! $limitation->purchasable)
->map(fn ($limitation) => get_class($limitation->purchasable).'::'.$limitation->purchasable->id);

$productExclusionIds = $this->discount->purchasableExclusions
->reject(fn ($limitation) => ! $limitation->purchasable)
->map(fn ($limitation) => get_class($limitation->purchasable).'::'.$limitation->purchasable->id);
Expand All @@ -186,7 +186,7 @@ protected function getEligibleLines(Cart $cart): \Illuminate\Support\Collection
})->exists();
});
}

if ($collectionExclusionIds->count()) {
$lines = $lines->reject(function ($line) use ($collectionExclusionIds) {
return $line->purchasable->product()->whereHas('collections', function ($query) use ($collectionExclusionIds) {
Expand All @@ -200,7 +200,7 @@ protected function getEligibleLines(Cart $cart): \Illuminate\Support\Collection
return ! $brandIds->contains($line->purchasable->product->brand_id);
});
}

if ($brandExclusionIds->count()) {
$lines = $lines->reject(function ($line) use ($brandExclusionIds) {
return $brandExclusionIds->contains($line->purchasable->product->brand_id);
Expand All @@ -212,7 +212,7 @@ protected function getEligibleLines(Cart $cart): \Illuminate\Support\Collection
return $productIds->contains(get_class($line->purchasable).'::'.$line->purchasable->id) || $productIds->contains(get_class($line->purchasable->product).'::'.$line->purchasable->product->id);
});
}

if ($productExclusionIds->count()) {
$lines = $lines->reject(function ($line) use ($productExclusionIds) {
return $productExclusionIds->contains(get_class($line->purchasable).'::'.$line->purchasable->id) || $productExclusionIds->contains(get_class($line->purchasable->product).'::'.$line->purchasable->product->id);
Expand Down
Loading