Skip to content

Commit 30c5f5f

Browse files
Refactor availability to publisher_availability
1 parent 94bd271 commit 30c5f5f

File tree

4 files changed

+14
-9
lines changed

4 files changed

+14
-9
lines changed

database/factories/BookFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public function definition()
101101
'thumbnail' => $this->getVisual('S'),
102102
'medium' => $this->getVisual('M'),
103103
],
104-
'availability' => $this->faker->numberBetween(1, 8),
104+
'publisher_availability' => $this->faker->numberBetween(1, 8),
105105
'stock' => $this->faker->numberBetween(0, 5),
106106
'editions' => $this->faker->randomElements(
107107
[$this->faker->ean13, $this->faker->ean13, $this->faker->ean13, $this->faker->ean13],

src/Api/Clients/TiteLive/TiteLiveClient.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ private function makeOneBookFromTiteLiveResult(array $result): ?Book
268268
)
269269
->first();
270270

271-
if (! $edition) {
271+
if (!$edition) {
272272
return null;
273273
}
274274

@@ -291,7 +291,7 @@ private function makeAllEditionsFromTiteLiveResult(array $result): Collection
291291

292292
private function mapBookFromApiResult(array $book, array $edition): ?Book
293293
{
294-
if (! isset($edition['prix'])) {
294+
if (!isset($edition['prix'])) {
295295
return null;
296296
}
297297

@@ -319,7 +319,7 @@ private function mapBookFromApiResult(array $book, array $edition): ?Book
319319
'large' => $edition['imagesUrl']['recto'] ?? null,
320320
'medium' => $edition['imagesUrl']['moyen'] ?? null,
321321
],
322-
'availability' => $edition['dispo'] ?? 4,
322+
'publisher_availability' => $edition['dispo'] ?? 4,
323323
'stock' => $edition['stock'] ?? 0,
324324
'editions' => collect($book['article'] ?? [])
325325
->filter(fn (array $otherEdition) => $otherEdition['gencod'] != $edition['gencod'])

src/BookJsonResource.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function toArray($request): array
2222
'formatted_published_date' => $this->published_date
2323
? $this->published_date->isoFormat('Do MMMM YYYY')
2424
: null,
25-
'availability_label' => $this->availability_label,
25+
'publisher_availability_label' => $this->publisher_availability_label,
2626
'short_details' => $this->short_details,
2727
'orderable' => $this->canBeOrdered(),
2828
'url' => $this->url,

src/Models/Book.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ class Book extends Model implements JsonSerializable
2222
protected $casts = [
2323
'id' => 'string',
2424
'published_date' => 'date',
25-
'availability' => BookAvailability::class,
25+
'publisher_availability' => BookAvailability::class,
2626
];
2727

2828
protected static ?string $fallbackVisualUrl = null;
2929

3030
protected static function newFactory()
3131
{
32-
return new BookFactory;
32+
return new BookFactory();
3333
}
3434

3535
protected function url(): Attribute
@@ -59,14 +59,19 @@ public function hasStock(): bool
5959
return $this->stock > 0;
6060
}
6161

62+
public function available(): Attribute
63+
{
64+
return Attribute::make(get: fn () => $this->canBeOrdered());
65+
}
66+
6267
public function canBeOrdered(): bool
6368
{
6469
if (config('titelive-client.shopping_closed')) {
6570
return false;
6671
}
6772

68-
return $this->availability != BookAvailability::Forthcoming
69-
&& ($this->hasStock() || $this->availability == BookAvailability::AvailableOnDemand);
73+
return $this->publisher_availability != BookAvailability::Forthcoming
74+
&& ($this->hasStock() || $this->publisher_availability == BookAvailability::AvailableOnDemand);
7075
}
7176

7277
public function visual(string $size, ?string $fallbackUrl = null): ?string

0 commit comments

Comments
 (0)