Skip to content

Commit

Permalink
Add to cart by ajax
Browse files Browse the repository at this point in the history
  • Loading branch information
tafid committed Feb 5, 2016
1 parent 875d88f commit 27172b8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/views/domain/_checkDomainLine.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ class="domain-zone muted">.<?= $line['zone'] ?></span>
<?= Html::a('<i class="fa fa-cart-plus fa-lg"></i>&nbsp; ' . Yii::t('app', 'Add to cart'), ['add-to-cart-registration', 'name' => $line['full_domain_name']], [
'data-pjax' => 0,
'class' => 'btn btn-flat bg-olive add-to-cart-button',
'data-loading-text' => Yii::t('hipanel/domain', 'Loading') . '...',
'data-complete-text' => '<i class="fa fa-check"></i>&nbsp;&nbsp;' . Yii::t('hipanel/domain', 'In cart'),
'data-loading-text' => '<i class="fa fa-circle-o-notch fa-spin fa-lg"></i>&nbsp;&nbsp;' . Yii::t('hipanel/domain', 'Loading') . '...',
'data-complete-text' => '<i class="fa fa-check fa-lg"></i>&nbsp;&nbsp;' . Yii::t('hipanel/domain', 'In cart'),
'data-domain-url' => Url::to(['add-to-cart-registration', 'name' => $line['full_domain_name']]),
]) ?>
<?php elseif ($state === 'unavailable') : ?>
Expand Down
14 changes: 5 additions & 9 deletions src/views/domain/checkDomain.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@

DomainCheckPluginAsset::register($this);
hipanel\frontend\assets\IsotopeAsset::register($this);
\hipanel\frontend\assets\HipanelAsset::register($this);

Yii::$app->assetManager->forceCopy = true;
//Yii::$app->assetManager->forceCopy = true; // todo: remove this line

$this->title = Yii::t('hipanel/domain', 'Domain check');
$this->breadcrumbs->setItems([
Expand All @@ -24,19 +25,14 @@
');
if (!empty($results)) {
$this->registerJs(<<<'JS'
$(document).on('click', 'a.add-to-cart-button', function(event) {
event.preventDefault();
var addToCartElem = $(this);
addToCartElem.button('loading');
$.post(addToCartElem.data('domain-url'), function() {
$('.dropdown.notifications-menu a.dropdown-toggle').html('<i class="fa fa-refresh fa-spin fa-lg"></i>');
}).done(function() {
addToCartElem.button('complete');
$.get("/cart/cart/topcart", function(data) {
$("li.dropdown.notifications-menu").replaceWith( data );
}).done(function() {
addToCartElem.addClass('disabled');
Hipanel.updateCart(function() {
addToCartElem.button('complete');
setTimeout(function () {addToCartElem.addClass('disabled')}, 0);
});
});
Expand Down

0 comments on commit 27172b8

Please sign in to comment.