Skip to content

Commit

Permalink
feat: use store-info resource (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
kchung authored Nov 5, 2024
1 parent af3d4ef commit e396063
Show file tree
Hide file tree
Showing 13 changed files with 59 additions and 33 deletions.
7 changes: 5 additions & 2 deletions theme/components/sections/store/item-list.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
{% endif %}
{% set filtersDialogProps = {
id: filterDropdownId ~ '__dialog',
fulfillment_support: square.store.fulfillment_support,
fulfillment_support: store_info.fulfillment_support,
current_value: request.query|default({}),
global_options,
category,
Expand Down Expand Up @@ -168,7 +168,7 @@
{{ include('partials/components/store/filters/buttons/categories', { id: filterDropdownId ~ '__categories', currentValue: (request.query.category_ids|split(','))|default({}), category }) }}
</span>
{% endif %}
{{ include('partials/components/store/filters/buttons/advanced', { id: filterDropdownId ~ '__advanced', chooseLocationTemplateId, currentValue: request.query|default({}), filtersDialogProps, globalOptions: global_options }) }}
{{ include('partials/components/store/filters/buttons/advanced', { id: filterDropdownId ~ '__advanced', storeInfo: store_info, chooseLocationTemplateId, currentValue: request.query|default({}), filtersDialogProps, globalOptions: global_options }) }}
</div>
{{ include('partials/components/store/filters/buttons/sort', { id: filterDropdownId ~ '__sort', sortOptions: sort_options, currentValue: currentSortValue }) }}
</div>
Expand Down Expand Up @@ -216,6 +216,9 @@
"sort_options": {
"type": "array"
},
"store_info": {
"type": "store-info"
},
"global_options": {
"type": "array",
"optional": true
Expand Down
11 changes: 7 additions & 4 deletions theme/components/sections/store/item/main.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
{% if product.subscriptions|length %}
<fieldset>
<legend class="visually-hidden">{{ 'partials.components.store.item.subscriptions.label'|localize }}</legend>
{{ include('partials/form/subscriptions', { subscriptions: product.subscriptions }) }}
{{ include('partials/form/subscriptions', { subscriptions: product.subscriptions, storeInfo: store_info }) }}
</fieldset>
{% endif %}

Expand All @@ -169,9 +169,9 @@
x-data="productFormButtons(Boolean({{ isManualFulfillment }}))"
class="item-page__add-to-buttons"
>
{% set isNotAcceptingOrders = square.store.accepting_orders == false %}
{% set isNotAcceptingOrders = store_info.accepting_orders == false %}
{% set shouldShowAddToCartButton = true %}
{% set shouldShowBuyNowButton = square.store.show_pdp_buy_now_button %}
{% set shouldShowBuyNowButton = store_info.show_pdp_buy_now_button %}
{% set buyNowButtonText = 'shared.buttons.buy_now'|localize %}

{% if productTypes[product.square_online_type] %}
Expand Down Expand Up @@ -250,7 +250,7 @@
{% endif %}

{# Shipping and return policies #}
{{ include('partials/components/store/item/policies') }}
{{ include('partials/components/store/item/policies', { storeInfo: store_info }) }}
</div>
</div>
</div>
Expand All @@ -271,6 +271,9 @@ function setInitialProductStore() {
},
"locations": {
"type": "location-list"
},
"store_info": {
"type": "store-info"
}
}
{% endschema %}
6 changes: 3 additions & 3 deletions theme/layouts/theme.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
{% endblock %}
</head>

{% set defaultFulfillment = (square.store.default_item_fulfillment|split(',')[0])|default('SHIPMENT') %}
{% set defaultFulfillment = (store_info.default_item_fulfillment|split(',')[0])|default('SHIPMENT') %}

{% if config.theme.shouldUseSiteStyles %}
{% set themeContainerWidth = max(square.site.styles.spacing.site_width, 1200) %}
Expand All @@ -65,8 +65,8 @@
>
<script id="global-data" type="application/json">
{{ {
locale: square.store.locale,
currency: square.store.currency,
locale: store_info.locale,
currency: store_info.currency,
defaultFulfillment,
}|json_encode }}
</script>
Expand Down
29 changes: 16 additions & 13 deletions theme/partials/components/mini-cart.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,22 @@
{% for modifier in modifiersWithPrice %}
{% set itemBasePrice = itemBasePrice + modifier.base_price_money.amount %}
{% endfor %}
{% set itemBasePriceFormatted = (itemBasePrice)|format_price({ currency: cart.order.total_money.currency|default(square.store.currency) }) %}
{% set itemBasePriceFormatted = (itemBasePrice)|format_price({ currency: cart.order.total_money.currency|default(store_info.currency) }) %}
{% endif %}

{# Regular and sale price #}
{% set isOnSale = itemBasePrice != item.gross_price_money.amount %}
{% if isOnSale %}
{{ include('partials/ui/price', { price: {
{{ include('partials/ui/price', { price: {
regular_high: {
amount: itemBasePrice,
currency: cart.order.total_money.currency|default(square.store.currency),
formatted: itemBasePrice|format_price({ currency: cart.order.total_money.currency|default(square.store.currency) })
},
currency: cart.order.total_money.currency|default(store_info.currency),
formatted: itemBasePrice|format_price({ currency: cart.order.total_money.currency|default(store_info.currency) })
},
regular_low: {
amount: item.gross_price_money.amount,
currency: cart.order.total_money.currency|default(square.store.currency),
formatted: item.gross_price_money.amount|format_price({ currency: cart.order.total_money.currency|default(square.store.currency) })
currency: cart.order.total_money.currency|default(store_info.currency),
formatted: item.gross_price_money.amount|format_price({ currency: cart.order.total_money.currency|default(store_info.currency) })
},
}, size: 'tiny' }) }}
{% endif %}
Expand Down Expand Up @@ -105,13 +105,13 @@
{{ include('partials/ui/price', { price: {
regular_high: {
amount: itemFinalPrice,
currency: cart.order.total_money.currency|default(square.store.currency),
formatted: itemFinalPrice|format_price({ currency: cart.order.total_money.currency|default(square.store.currency) })
currency: cart.order.total_money.currency|default(store_info.currency),
formatted: itemFinalPrice|format_price({ currency: cart.order.total_money.currency|default(store_info.currency) })
},
regular_low: {
amount: itemFinalPrice,
currency: cart.order.total_money.currency|default(square.store.currency),
formatted: itemFinalPrice|format_price({ currency: cart.order.total_money.currency|default(square.store.currency) })
currency: cart.order.total_money.currency|default(store_info.currency),
formatted: itemFinalPrice|format_price({ currency: cart.order.total_money.currency|default(store_info.currency) })
},
}, size: 'small' }) }}
</div>
Expand Down Expand Up @@ -169,7 +169,7 @@
{% for discount in cart.order.discounts %}
{% set subtotal = subtotal - discount.applied_money.amount %}
{% endfor %}
{% set formattedSubtotal = (subtotal)|format_price({ currency: cart.order.total_money.currency|default(square.store.currency) }) %}
{% set formattedSubtotal = (subtotal)|format_price({ currency: cart.order.total_money.currency|default(store_info.currency) }) %}
{% endif %}

{% embed 'partials/ui/button' with {
Expand Down Expand Up @@ -204,6 +204,9 @@
{
"cart": {
"type": "cart"
},
"store_info": {
"type": "store-info"
}
}
{% endschema %}
{% endschema %}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% if 'PICKUP' in square.store.fulfillment_support %}
{% if 'PICKUP' in storeInfo.fulfillment_support %}
{{ register_asset('css/components/store/item/locations-dialog.css') }}
{{ register_asset('js/components/store/item/locations-dialog.js', { defer: false }) }}
{% endif %}
Expand Down Expand Up @@ -40,7 +40,7 @@

<div class="filters__advanced-options-row">
{# Fulfillments and item status #}
{{ include('partials/components/store/filters/options/fulfillments-and-status', { chooseLocationTemplateId, fulfillmentSupport: square.store.fulfillment_support }) }}
{{ include('partials/components/store/filters/options/fulfillments-and-status', { chooseLocationTemplateId, fulfillmentSupport: storeInfo.fulfillment_support }) }}
</div>

{% if globalOptions|length %}
Expand Down
10 changes: 5 additions & 5 deletions theme/partials/components/store/item/policies.html.twig
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{% set accordions = [] %}
{% set accordionAllowedTags = '<p><strong><em><ul><li><ol><a>' %}
{% if square.store.shipping_policy is not empty %}
{% if storeInfo.shipping_policy is not empty %}
{% set accordions = accordions|merge([{
icon: 'receipt_long',
label: 'partials.components.store.item.policies.shipping.label'|localize,
content: square.store.shipping_policy,
content: storeInfo.shipping_policy,
}]) %}
{% endif %}
{% if square.store.return_policy is not empty %}
{% if storeInfo.return_policy is not empty %}
{% set accordions = accordions|merge([{
icon: 'policy',
label: 'partials.components.store.item.policies.return.label'|localize,
content: square.store.return_policy,
content: storeInfo.return_policy,
}]) %}
{% endif %}
{% if accordions|length > 0 %}
Expand All @@ -20,4 +20,4 @@
{{ include('partials/ui/accordion', { accordionItems: [item], allowedTags: accordionAllowedTags, richTextFormatting: true }) }}
{% endfor %}
</div>
{% endif %}
{% endif %}
6 changes: 3 additions & 3 deletions theme/partials/form/subscriptions.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
{{ {
cadences: SUBSCRIPTION_CADENCES,
subscriptionCards,
currency: square.store.currency,
currency: storeInfo.currency,
translations: {
billingCycleOneDay: 'partials.form.subscriptions.billing_cycle.one_day'|localize,
billingCycleDays: 'partials.form.subscriptions.billing_cycle.days'|localize,
Expand Down Expand Up @@ -179,7 +179,7 @@
{% set discount = defaultPhase.pricing.discounts[0] %}
{% set subscriptionPrice = null %}
{% if defaultPhase.pricing.regular %}
{% set subscriptionPrice = { regular_high: defaultPhase.pricing.regular, regular_low: defaultPhase.pricing.subscription, currency: square.store.currency } %}
{% set subscriptionPrice = { regular_high: defaultPhase.pricing.regular, regular_low: defaultPhase.pricing.subscription, currency: storeInfo.currency } %}
{% endif %}

{% if discount.discount_type == 'FIXED_PERCENTAGE' %}
Expand Down Expand Up @@ -231,4 +231,4 @@
{% endfor %}
{% endblock %}
{% endembed %}
</div>
</div>
4 changes: 3 additions & 1 deletion theme/templates/pages/home.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
{{ section_container(main, 'Main sections') }}
</div>


{% endblock %}

{% schema %}
Expand All @@ -23,6 +22,9 @@
},
"main": {
"type": "section-list"
},
"store_info": {
"type": "store-info"
}
}
{% endschema %}
3 changes: 3 additions & 0 deletions theme/templates/store/category.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@
},
"categories": {
"type": "category-list"
},
"store_info": {
"type": "store-info"
}
}
{% endschema %}
3 changes: 3 additions & 0 deletions theme/templates/store/item.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@
{
"item": {
"type": "item"
},
"store_info": {
"type": "store-info"
}
}
{% endschema %}
3 changes: 3 additions & 0 deletions theme/templates/store/locations.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@
{
"locations": {
"type": "location-list"
},
"store_info": {
"type": "store-info"
}
}
{% endschema %}
3 changes: 3 additions & 0 deletions theme/templates/store/search.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
{
"search_term": {
"type": "string"
},
"store_info": {
"type": "store-info"
}
}
{% endschema %}
3 changes: 3 additions & 0 deletions theme/templates/store/shop.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@
},
"category_hierarchy": {
"type": "category-hierarchy"
},
"store_info": {
"type": "store-info"
}
}
{% endschema %}

0 comments on commit e396063

Please sign in to comment.