Last active
July 31, 2025 13:08
-
-
Save Septdir/99c8074e5cd8eb454e250928214a3c2e to your computer and use it in GitHub Desktop.
RadicalMart 2 Advanced add to cart buttons
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
<div class="footer uk-padding-small"> | |
<div class="uk-grid-small" uk-grid | |
radicalmart-cart="product" data-id="<?php echo $product->id; ?>" | |
data-key="p<?php echo $product->id; ?>" data-cart-product="1" | |
radicalmart-cart_buttons="container"> | |
<div class="uk-flex uk-flex-middle uk-width-1-3@m"> | |
<?php if (!$hidePrice): ?> | |
<?php if ($product->price['discount_enable']): ?> | |
<div class="uk-text-small uk-text-muted"> | |
<s><?php echo $product->price['base_string']; ?></s> | |
</div> | |
<?php endif; ?> | |
<div> | |
<strong><?php echo $product->price['final_string']; ?></strong> | |
</div> | |
<?php elseif (empty($product->in_stock)): ?> | |
<span class="uk-text-danger"> | |
<?php echo Text::_('COM_RADICALMART_NOT_IN_STOCK'); ?> | |
</span> | |
<?php endif; ?> | |
</div> | |
<?php if (!$hidePrice && $mode === 'shop' && (int) $product->state === 1): ?> | |
<div class="uk-width-expand@m" radicalmart-cart_buttons="loading"> | |
<div class="uk-height-1-1 uk-width-1-1 uk-flex uk-flex-middle uk-flex-center uk-padding-small"> | |
<div uk-spinner="ratio: 0.5"></div> | |
</div> | |
</div> | |
<div class="uk-width-expand@m" radicalmart-cart_buttons="in-cart" style="display: none"> | |
<div class="uk-grid-small uk-child-width-auto uk-flex-middle" uk-grid> | |
<div> | |
<span class="uk-link" | |
uk-icon="icon: minus;" | |
radicalmart-cart="quantity_minus"></span> | |
<span class="uk-link " | |
uk-icon="icon: minus;" | |
radicalmart-cart="remove" style="display: none"></span> | |
</div> | |
<div class="uk-width-expand"> | |
<input radicalmart-cart="quantity" type="text" name="quantity" data-set="1" | |
class="uk-input uk-text-center" | |
step="<?php echo $product->quantity['step']; ?>" | |
min="<?php echo $product->quantity['min']; ?>" | |
<?php if (!empty($product->quantity['max'])) | |
{ | |
echo 'max="' . $product->quantity['max'] . '"'; | |
} ?> | |
value="<?php echo $product->quantity['min']; ?>"/> | |
</div> | |
<div> | |
<span class="uk-link" uk-icon="icon: plus;" | |
radicalmart-cart="quantity_plus"></span> | |
</div> | |
</div> | |
</div> | |
<div class="uk-width-expand@m uk-flex-middle uk-flex-center uk-text-center" | |
radicalmart-cart_buttons="not-in-cart" style="display:none"> | |
<button radicalmart-cart="add" type="button" class="uk-button uk-button-primary"> | |
<?php echo Text::_('COM_RADICALMART_CART_ADD'); ?> | |
</button> | |
</div> | |
<?php elseif ($hidePrice || $mode === 'catalog'): ?> | |
<div class="uk-width-expand@m uk-flex-middle uk-flex-center uk-text-center"> | |
<a href="<?php echo $product->link; ?>" | |
class="uk-button uk-button-primary uk-button-small"> | |
<?php echo Text::_('COM_RADICALMART_READMORE'); ?> | |
</a> | |
</div> | |
<?php endif; ?> | |
</div> | |
</div> |
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 (!empty($this->product->in_stock)): ?> | |
<div class="uk-grid-divider uk-grid-small" uk-grid | |
radicalmart-cart="product" data-id="<?php echo $this->product->id; ?>" | |
data-key="p<?php echo $this->product->id; ?>" data-cart-product="1" | |
radicalmart-cart_buttons="container"> | |
<div class="uk-flex-middle uk-width-1-3@m"> | |
<div class="uk-text-meta"><?php echo Text::_('COM_RADICALMART_PRICE'); ?></div> | |
<div class="price"> | |
<?php if ($this->product->price['discount_enable']): ?> | |
<div class="uk-text-small uk-text-muted"> | |
<s><?php echo $this->product->price['base_string']; ?></s> | |
</div> | |
<?php endif; ?> | |
<div class="uk-text-large"> | |
<strong> | |
<?php echo $this->product->price['final_string']; ?> | |
</strong> | |
</div> | |
<?php if ($this->product->price['discount_enable']): ?> | |
<div class="uk-text-small"> | |
<?php | |
echo Text::_('COM_RADICALMART_PRICE_DISCOUNT') . ' ' . $this->product->price['discount_string']; | |
if ($this->product->price['discount_end']) | |
{ | |
echo ' ' . Text::_('COM_RADICALMART_PRICE_DISCOUNT_END') . ' ' | |
. HTMLHelper::date($this->product->price['discount_end'], Text::_('DATE_FORMAT_LC6')); | |
} | |
?> | |
</div> | |
<?php endif; ?> | |
</div> | |
</div> | |
<?php if ((int) $this->product->state === 1 && $this->mode === 'shop'): ?> | |
<div class="uk-width-expand@m" radicalmart-cart_buttons="loading"> | |
<div class="uk-height-1-1 uk-width-1-1 uk-flex uk-flex-middle uk-background-muted uk-flex-center uk-padding-small"> | |
<div uk-spinner="ratio: 0.5"></div> | |
</div> | |
</div> | |
<div class="uk-width-expand@m" radicalmart-cart_buttons="in-cart" style="display: none"> | |
<div class="uk-grid-small uk-child-width-auto uk-flex-middle" uk-grid> | |
<div> | |
<span class="uk-link" | |
uk-icon="icon: minus;" | |
radicalmart-cart="quantity_minus"></span> | |
<span class="uk-link " | |
uk-icon="icon: minus;" | |
radicalmart-cart="remove" style="display: none"></span> | |
</div> | |
<div class="uk-width-expand"> | |
<input radicalmart-cart="quantity" type="text" name="quantity" data-set="1" | |
class="uk-input uk-text-center" | |
step="<?php echo $this->product->quantity['step']; ?>" | |
min="<?php echo $this->product->quantity['min']; ?>" | |
<?php if (!empty($this->product->quantity['max'])) | |
{ | |
echo 'max="' . $this->product->quantity['max'] . '"'; | |
} ?> | |
value="<?php echo $this->product->quantity['min']; ?>"/> | |
</div> | |
<div> | |
<span class="uk-link" | |
uk-icon="icon: plus;" | |
radicalmart-cart="quantity_plus"></span> | |
</div> | |
</div> | |
</div> | |
<div class="uk-width-auto@m uk-flex-middle" radicalmart-cart_buttons="in-cart" style="display: none"> | |
<a href="<?php echo Route::_(RouteHelper::getCartRoute()); ?>" class="uk-button uk-button-primary"> | |
<?php echo Text::_('COM_RADICALMART_CHECKOUT'); ?> | |
</a> | |
</div> | |
<div class="uk-width-expand@m uk-flex-middle uk-flex-center uk-text-center" | |
radicalmart-cart_buttons="not-in-cart" style="display: none"> | |
<button radicalmart-cart="add" type="button" class="uk-button uk-button-primary"> | |
<?php echo Text::_('COM_RADICALMART_CART_ADD'); ?> | |
</button> | |
</div> | |
<?php endif; ?> | |
</div> | |
<?php else: ?> | |
<div class="uk-text-danger"> | |
<?php echo Text::_('COM_RADICALMART_NOT_IN_STOCK'); ?> | |
</div> | |
<?php endif; ?> |
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
let RMCartProductLoaded = {}, | |
RMCartLoaded = false; | |
document.addEventListener('DOMContentLoaded', () => { | |
setTimeout(() => { | |
if (!RMCartLoaded) { | |
RMCartDisplayCartButtons(false); | |
} | |
}, 2000); | |
document.querySelectorAll('[radicalmart-cart_buttons="container"]').forEach((container) => { | |
let quantityField = container.querySelector('[radicalmart-cart="quantity"]'); | |
if (quantityField) { | |
quantityField.addEventListener('change', () => { | |
RMCartDisplayRemove(quantityField, container); | |
}) | |
} | |
}); | |
}); | |
document.addEventListener('onRadicalMartCartAfterUpdateDisplayData', (event) => { | |
if (event.detail.error) { | |
return; | |
} | |
RMCartLoaded = true; | |
RMCartDisplayCartButtons(event.detail); | |
}); | |
function RMCartDisplayCartButtons(cart) { | |
document.querySelectorAll('[radicalmart-cart_buttons="container"]').forEach((container) => { | |
let key = container.getAttribute('data-key'), | |
in_cart = !!(cart && cart.products && cart.products[key] && cart.products[key] !== 'undefined'); | |
let quantityField = container.querySelector('[radicalmart-cart="quantity"]'); | |
if (quantityField) { | |
if (in_cart && !RMCartProductLoaded[key]) { | |
quantityField.value = cart.products[key].order.quantity; | |
RMCartProductLoaded[key] = true; | |
} | |
if (!in_cart && RMCartProductLoaded[key]) { | |
quantityField.value = quantityField.getAttribute('min'); | |
RMCartProductLoaded[key] = false; | |
} | |
RMCartDisplayRemove(quantityField, container); | |
} | |
let loading = container.querySelector('[radicalmart-cart_buttons="loading"]'); | |
if (loading) { | |
loading.style.display = 'none'; | |
} | |
container.querySelectorAll('[radicalmart-cart_buttons="in-cart"]').forEach((element) => { | |
element.style.display = (in_cart) ? '' : 'none'; | |
}) | |
container.querySelectorAll('[radicalmart-cart_buttons="not-in-cart"]').forEach((element) => { | |
element.style.display = (!in_cart) ? '' : 'none'; | |
}) | |
}); | |
} | |
function RMCartDisplayRemove(input, container) { | |
let minus = container.querySelector('[radicalmart-cart="quantity_minus"]'), | |
remove = container.querySelector('[radicalmart-cart="remove"]'); | |
console.log(minus); | |
console.log(remove); | |
if (!minus || !remove) { | |
return; | |
} | |
let min = input.getAttribute('min'), | |
value = input.value; | |
min = (min) ? parseFloat(min) : 1; | |
value = (value) ? parseFloat(value) : min; | |
if (value === min) { | |
minus.style.display = 'none'; | |
remove.style.display = ''; | |
} else { | |
minus.style.display = ''; | |
remove.style.display = 'none'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment