Skip to content

Commit

Permalink
Merge pull request #46 from BitBagCommerce/OPSRC-562/flash_message_fix
Browse files Browse the repository at this point in the history
Add page reload to summary
  • Loading branch information
dead-playmod authored Aug 4, 2022
2 parents c784ea4 + 8d2ac6c commit 46915d7
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
File renamed without changes.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@
"sort-packages": true,
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": false,
"phpstan/extension-installer": false
"phpstan/extension-installer": false,
"symfony/thanks": true
}
},
"extra": {
Expand Down
3 changes: 3 additions & 0 deletions src/Resources/assets/shop/js/handleSummary.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export class handleCartWidget {
cartSummaryItemUrl: 'data-url-cart-item',
cartSummaryTotalUrl: 'data-url-cart-total',
cartSummaryActiveUrl: 'data-url-carts-active-cart',
flashMessage: '[data-sylius-flash-message]',
};
this.config = { ...defaults, ...config };
}
Expand Down Expand Up @@ -53,12 +54,14 @@ export class handleCartWidget {
const changeActiveCartUrl = e.currentTarget.getAttribute(
this.config.cartChangeUrl
);
const flashMessage = document.querySelector(this.config.flashMessage)

try {
const res = await fetch(changeActiveCartUrl, { method: 'POST' });

if (res.ok) {
this.config.update();
flashMessage.remove();
} else {
throw new Error('Fetch failed');
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{% if app.session is not null and app.session.started %}
{% for type in ['success', 'error', 'info', 'warning'] %}
{% for flash in app.session.flashbag.get(type) %}
{% if 'error' == type %}
{% set result = 'negative' %}
{% set icon = 'remove' %}
{% endif %}
{% if 'info' == type %}
{% set result = 'info' %}
{% set icon = 'info' %}
{% endif %}
<div class="ui icon {{ result|default('positive') }} message sylius-flash-message" data-sylius-flash-message>
<i class="close icon"></i>
<i class="{{ icon|default('checkmark') }} icon"></i>
<div class="content">
<div class="header">
{% set header = 'sylius.ui.'~type %}
{{ header|trans }}
</div>
<p {{ sylius_test_html_attribute('flash-messages') }}>
{% if flash is iterable %}
{{ flash.message|trans(flash.parameters, 'flashes') }}
{% else %}
{{ flash|trans({}, 'flashes') }}
{% endif %}
</p>
</div>
</div>
{% endfor %}
{% endfor %}
{% endif %}

0 comments on commit 46915d7

Please sign in to comment.