Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/hide no image config setting #25

Merged
merged 3 commits into from
Sep 12, 2024
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
14 changes: 14 additions & 0 deletions src/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,20 @@
*/

return [
// Plugin options
'options' => [
// Whether or not to show the "save for later" button
'enableSaveForLater' => false, // true|false

// Whether or not to show the shipping estimator
'enableEstimatedShipping' => false, // true|false

// Whether or not to show the free shipping message
'enableFreeShippingMessage' => false, // true|false

// Whether or not to show the "No Image" placeholder images
'enablePlaceholderImages' => false,
],
// Branding Settings
'branding' => [
// The brand primary custom color in HEX color
Expand Down
7 changes: 7 additions & 0 deletions src/models/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@
*/
class Settings extends Model
{
public array $options = [
'enableSaveForLater' => false,
'enableEstimatedShipping' => false,
'enableFreeShippingMessage' => false,
'enablePlaceholderImages' => false,
];

public array $branding = [
'color' => '#1F2937',
'font' => 'Rubik',
Expand Down
9 changes: 9 additions & 0 deletions src/services/Checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@
*/
class Checkout extends Component
{
/*
* Gets the options settings array
*/
public function options(): array
{
$settings = FosterCheckout::getInstance()->getSettings();
return $settings->options;
}

/*
* Gets the branding settings array
*/
Expand Down
30 changes: 16 additions & 14 deletions src/templates/_components/app/line-item-cart.twig
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,24 @@

<article
v-scope="LineItem({ id: {{ lineItem.id }}, qty: {{ lineItem.qty }}, min: {{ minQty ?? 0 }}, max: {{ maxQty ?? 0 }}, stock: {{ stock }}, unlimitedStock: {{ unlimitedStock }}, lineSubtotal: '{{ lineSubtotal }}', showErrorMaxMessage: false, showErrorMinMessage: false, showErrorStockMessage: false })"
class="flex justify-start items-stretch gap-5 p-5 bg-gray-200 rounded-xl"
class="flex justify-between items-stretch gap-5 p-5 bg-gray-200 rounded-xl"
>

<div class="w-[80px] min-w-[80px] max-w-[80px] md:w-[200px] md:min-w-[200px] md:max-w-[200px] flex-grow">
<figure class="rounded-lg overflow-hidden min-w-full">
<img
src="{{ imageUrl ?? 'https://placehold.co/200x200?text=No+Image' }}"
srcset="{{ imageUrl ? imageSrcSet : '' }}"
sizes="(min-width: 768px) 200px, 80px"
width="200"
height="200"
class="min-w-full"
alt="{{ 'Image of'|t('foster-checkout') ~ ' ' ~ lineItem.description }}"
/>
</figure>
</div>
{% if imageUrl or craft.checkout.options.enablePlaceholderImages %}
<div class="w-[80px] min-w-[80px] max-w-[80px] md:w-[200px] md:min-w-[200px] md:max-w-[200px] flex-grow">
<figure class="rounded-lg overflow-hidden min-w-full">
<img
src="{{ imageUrl ?? ('https://placehold.co/200x200?text=' ~ 'No Image'|t('foster-checkout')|split(' ')|join('+')) }}"
srcset="{{ imageUrl ? imageSrcSet : '' }}"
sizes="(min-width: 768px) 200px, 80px"
width="200"
height="200"
class="min-w-full"
alt="{{ 'Image of'|t('foster-checkout') ~ ' ' ~ lineItem.description }}"
/>
</figure>
</div>
{% endif %}

<div class="flex flex-col justify-between items-stretch gap-10 flex-grow">

Expand Down
26 changes: 14 additions & 12 deletions src/templates/_components/app/line-item-checkout.twig
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,20 @@
{% set imageUrl = previewImage.getUrl(preview) %}
{% endif %}

<article class="flex justify-start items-stretch gap-4 p-4 bg-gray-200 rounded-xl">
<article class="flex justify-between items-stretch gap-4 p-4 bg-gray-200 rounded-xl">

<div class="w-[70px] min-w-[70px]">
<figure class="rounded-lg overflow-hidden">
<img
src="{{ imageUrl ?? 'https://placehold.co/70x70?text=No+Image' }}"
width="70"
height="70"
alt="{{ 'Image of'|t('foster-checkout') ~ ' ' ~ lineItem.description }}"
/>
</figure>
</div>
{% if imageUrl or craft.checkout.options.enablePlaceholderImages %}
<div class="w-[70px] min-w-[70px]">
<figure class="rounded-lg overflow-hidden">
<img
src="{{ imageUrl ?? ('https://placehold.co/70x70?text=' ~ 'No Image'|t('foster-checkout')|split(' ')|join('+')) }}"
width="70"
height="70"
alt="{{ 'Image of'|t('foster-checkout') ~ ' ' ~ lineItem.description }}"
/>
</figure>
</div>
{% endif %}

<div class="flex justify-between items-stretch gap-4 flex-grow">
<div class="flex flex-col justify-between items-start gap-1">
Expand All @@ -32,4 +34,4 @@
<h4 class="font-semibold text-right leading-snug">{{ lineItem.totalAsCurrency() }}</h4>
</div>

</article>
</article>
1 change: 1 addition & 0 deletions src/translations/en/foster-checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,5 @@
'dateFormat' => 'n/j/y',
'Same as shipping address' => 'Same as shipping address',
'Use an address from your address book' => 'Use an address from your address book',
'No Image' => 'No Image',
];