Quantcast
Channel: Yii Framework Forum
Viewing all articles
Browse latest Browse all 18717

Adding To A Shopping Cart Without Redircting The Page

$
0
0
Hello,

BACKGROUND:
I'm very new to Yii, this group, and web development. However, I'm not new to programming (10 years). By the way, I absolutely love Yii. It's fantastic.

I'm building a shopping cart using the Yii 1.1.x framework. I downloaded the shopping-cart-component extension library to assist.

On my header page (../views/layouts/main.php), I have a common cart icon which I want to update with the number of items added to the cart. Dynamically.

PROBLEM:
What I want is that when the user clicks on a 'buy' button next to an item in the shopping page, the cart quantity on the page will increment without leaving that page. My problem is that I don't know how to achieve this. Best I can do now is redirect the page back to where the user was after executing the Model's action code. Which is not the desired effect.


MY CURRENT CODE:
I have a shopping view page (../views/product/detail.php). That page has a CActiveForm. In that form I added a CHtml::submitButton button. When this button is clicked the action is to call my controller actionAdd() function (/product/add) in a POST manner.

MY QUESTION
How do I add that item to my cart and update the basket icon's quantity label without leaving the shopping page? That is, what do I do at the end of my Controller::actionAdd() function?

ProductController::actionAdd:
//...
if(isset($_POST['quantity']))
{
  $qty = $_POST['quantity'];
  Yii::app()->shoppingCart->put($model,$qty);
  // ??? $this->redirect(Yii::app()->request->urlReferrer);
} else {
 // throw new CHttpException('....');
}
//...


Thanks in advance.

John

Viewing all articles
Browse latest Browse all 18717

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>