Prev | Current Page 529 | Next

Emilian Balanescu and Cristian Darie

"Beginning PHP and MySQL E-Commerce: From Novice to Professional, Second Edition"

getElementById('updating').style.visibility = 'hidden';
}
}
CHAPTER 13 ?–  IMPLEMENTING AJAX FEATURES 424
Enhancing the Shopping Cart with AJAX
The enhanced shopping cart will use AJAX for updating the shopping cart. When removing products
from the shopping cart, saving products for buying later, or updating product quantities, the
action will happen in the background. During the asynchronous request, an ???Updating...??? label
shows up to indicate visually that the shopping cart is being updated (see Figure 13-4).
Just like with adding products to cart, the shopping cart is updated in a degradable fashion.
If the visitor disables JavaScript, the features will still work but will use the classical form
submit instead of AJAX.
Follow the steps of this exercise to implement your AJAX shopping cart.
AJAXifying the Shopping Cart
1. Let??™s start by modifying the template file, presentation\templates\cart_details.tpl, to call
JavaScript functions on button clicks. Open the file, and apply the highlighted changes:
{* cart_details.tpl *}
{load_presentation_object filename="cart_details" assign="obj"}
Updating...

{if $obj->mIsCartNowEmpty eq 1}

Your shopping cart is empty!


{else}

These are the products in your shopping cart:


onsubmit="return executeCartAction(this);">








{section name=i loop=$obj->mCartProducts}

Product NamePriceQuantitySubtotal 

value="{$obj->mCartProducts[i].


Pages:
517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541
perfumy fm Anteny satelitarne apartamenty przy plaży online loan for bad credit rekuperatory