Skip to content

Commit

Permalink
scheduleCustomerGroup remove start date null to now() (#1172)
Browse files Browse the repository at this point in the history
currently when schedule product customer group if no start date passed,
the code will set `$start = now()` this behaviour may not be desired and
is not consistent with `scheduleChannel` which does not set to now when
null

also when start date is null the hub will show as "always available"

- ~~Documentation updates~~
- [x] Automated tests
- [x] Changelog entries (core ~~and hub~~)

Co-authored-by: Alec Ritson <[email protected]>
  • Loading branch information
wychoong and alecritson authored Aug 7, 2023
1 parent 9b73bec commit 3c3219c
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 2 deletions.
5 changes: 5 additions & 0 deletions packages/core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [Unreleased]

### Changed
- when `Product->scheduleCustomerGroup($customerGroups, $startDate = null)` when `$startDate` is `null` it will not set to `now()` and always available

## 0.4

### Fixed
Expand Down
2 changes: 0 additions & 2 deletions packages/core/src/Base/Traits/CanScheduleAvailability.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ protected function schedule(
throw new SchedulingException($error);
}

$starts = $starts ?: now();

$relation->syncWithoutDetaching(
$this->getScheduleMapping($models, array_merge([
'starts_at' => $starts,
Expand Down
22 changes: 22 additions & 0 deletions packages/core/tests/Unit/Base/Traits/HasCustomerGroupsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,28 @@ public function can_schedule_using_single_model()
);
}

/** @test */
public function can_schedule_always_available()
{
$product = Product::factory()->create();

$customerGroup = CustomerGroup::factory()->create();

$product->scheduleCustomerGroup($customerGroup);

$this->assertDatabaseHas(
'lunar_customer_group_product',
[
'customer_group_id' => $customerGroup->id,
'enabled' => 1,
'visible' => 1,
'purchasable' => 1,
'starts_at' => null,
'ends_at' => null,
],
);
}

/** @test */
public function can_schedule_using_array_of_models()
{
Expand Down
22 changes: 22 additions & 0 deletions packages/core/tests/Unit/Models/ProductTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,28 @@ public function customer_groups_can_be_enabled()
);
}

/** @test */
public function customer_groups_can_be_scheduled_always_available()
{
$product = Product::factory()->create();

$customerGroup = CustomerGroup::factory()->create();

$product->scheduleCustomerGroup($customerGroup);

$this->assertDatabaseHas(
'lunar_customer_group_product',
[
'customer_group_id' => $customerGroup->id,
'enabled' => 1,
'purchasable' => 1,
'visible' => 1,
'starts_at' => null,
'ends_at' => null,
],
);
}

/** @test */
public function customer_groups_can_be_scheduled_with_start_and_end()
{
Expand Down

1 comment on commit 3c3219c

@vercel
Copy link

@vercel vercel bot commented on 3c3219c Aug 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.