Last active
August 6, 2024 03:08
-
-
Save cave2006/dd8af587634b59f49990b2cdeaa24845 to your computer and use it in GitHub Desktop.
Change the default behavior of the "Add to Cart" button to custom
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.not-empty-cart { | |
opacity: 1; | |
background-color: #CC5134; | |
padding: 7px 15px; | |
color: white; | |
border-radius: 500px; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Добавляем своё поведение для кнопки "В корзину" в карточке товаров | |
document.addEventListener('onRadicalMartCartAfterUpdateDisplayData', event => { | |
if (!event.detail.error) { | |
document.querySelectorAll('[card-add-buttons]'). forEach(function (container) { | |
let key = container.getAttribute('card-add-buttons'), | |
addButton = container.querySelector('.empty-cart'), | |
addQuantityButtons = container.querySelector('.not-empty-cart'), | |
addRemoveButton = container.querySelector('[radicalmart-cart="remove"]'), | |
addMinusButton = container.querySelector('[radicalmart-cart="quantity_minus"]'); | |
if (!event.detail.products || !event.detail.products[key]) { // в корзине товаров нет | |
addButton.removeAttribute('hidden'); | |
addQuantityButtons.setAttribute('hidden',''); | |
} else { | |
let product = event.detail.products[key]; | |
if (product.order.quantity > 1) { // в корзине больше одного товара | |
addButton.setAttribute('hidden',''); | |
addQuantityButtons.removeAttribute('hidden'); | |
addRemoveButton.setAttribute('hidden',''); | |
addMinusButton.removeAttribute('hidden'); | |
} else { // в корзине один товар | |
addRemoveButton.removeAttribute('hidden'); | |
addMinusButton.setAttribute('hidden',''); | |
addButton.setAttribute('hidden',''); | |
addQuantityButtons.removeAttribute('hidden'); | |
} | |
} | |
}); | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php if (!$hidePrice && $mode === 'shop' && (int) $product->state === 1): ?> | |
<div radicalmart-cart="product" | |
data-id="<?php echo $product->id; ?>" | |
class="uk-margin tm-buttons-incart" | |
data-cart-product="1" | |
data-remove-action="skip" | |
card-add-buttons="p<?php echo $product->id; ?>"> | |
<div class="uk-child-width-auto uk-flex-middle"> | |
<div class="uk-flex uk-flex-middle uk-flex-between not-empty-cart" hidden=""> | |
<div> | |
<span class="uk-link uk-margin-small-right uk-icon uk-light" | |
uk-icon="icon: minus-circle; ratio: 1.3" | |
radicalmart-cart="remove"></span> | |
<span class="uk-link uk-margin-small-right uk-icon uk-light" | |
uk-icon="icon: minus-circle; ratio: 1.3" | |
radicalmart-cart="quantity_minus"></span> | |
</div> | |
<div class="uk-display-inline-block uk-text-center"> | |
<div class="uk-text-center"> | |
<div radicalmart-cart-display="products.p<?php echo $product->id; ?>.order.quantity" | |
id="in-cart">0</div> | |
<div class="uk-hidden@s uk-text-small" style="margin-top:-4px"><?php echo Text::_('TPL_YOOTHEME_BALJIN_IN_CART'); ?></div> | |
<input radicalmart-cart="quantity" type="text" name="quantity" data-set="1" | |
class="uk-input uk-form-width-xsmall uk-text-center uk-hidden" | |
step="1" min="1" max="<?php echo $stock->all; ?>" value="1"/> | |
</div> | |
</div> | |
<div> | |
<span class="uk-link uk-link-reset uk-margin-small-left uk-icon uk-light" | |
uk-icon="icon: plus-circle; ratio: 1.3" | |
radicalmart-cart="quantity_plus"> | |
</span> | |
</div> | |
</div> | |
<div class="empty-cart"> | |
<span radicalmart-cart="add" class="uk-button uk-button-primary"> | |
<span class="uk-icon uk-margin-small-right" uk-icon="icon: cart; ratio: 1.2"></span> | |
<?php echo Text::_('COM_RADICALMART_CART_ADD'); ?> | |
</span> | |
</div> | |
</div> | |
</div> | |
<?php endif; ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment