Yii Framework Forum: CGridView & Shopping Cart - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

CGridView & Shopping Cart Rate Topic: -----

#1 User is offline   viglu 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 17
  • Joined: 31-July 10
  • Location:Luxembourg

Posted 22 October 2010 - 04:09 PM

Hello,

I'm faced to a problem. I want to build a page which will display my shopping cart items and then delete or update quantity of the items.

I thought the best way is to use the CGridView. So far no problem I can display all my items. My problem is the quantity. I want an input box and when it changed the CGridView and the total cart price will be updated.
Can anyone give me some tips how to realise that?

Many thanks,
Luc
0

#2 User is offline   blindMoe 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 24
  • Joined: 17-May 10

Posted 27 October 2010 - 12:10 PM

You should be able to do this by simply defining a column that spits out a chtml text box withe the current quantity as well as an 'update' button to update any changes. You could use javascript to enable a CHtml::ajaxButton ones the user has changed the quantity which will use ajax to update the database / session.
0

#3 User is offline   viglu 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 17
  • Joined: 31-July 10
  • Location:Luxembourg

Posted 27 October 2010 - 12:38 PM

Hello,

I have already a problem for deleting an item in my gridview.

I have the following function in my controller which will delete the item in the database. I want to call this function per ajax.

public function actionCartdeleteitem()
        {
                echo "success";
                if (isset($_POST['Item']))
                {
                        $sessionid = app()->session->sessionID;
                        $id = $_POST['id'];
                        $sql = "DELETE FROM tbcart WHERE sessionid = :sessionid AND id=:id;";
                        $cmd = app()->getDb()->createCommand($sql);
                        $cmd->bindParam(':sessionid', $sessionid);
                        $cmd->bindParam(':id', $id);                        
                        $cmd->execute();
                }
            Yii::app()->end();

        }


Here the definition of the column in the gridview
array(
                        'class'         => 'CButtonColumn',
                        'template' => '{deleteitem}',
                        'buttons' => array(
                                'deleteitem' => array(
                                        'label' => 'Delete',
                                        'url'   => 'Yii::app()->controller->createUrl("checkout/cartdeleteitem",array("id"=>$data[\'id\']))',
                                        'click' => 'js:function() {deleteitem_onclick( $(this).attr("href"), 2 ); return false;}',
                                ),
                        ),
                ),


An here the javascript function which is called. But the function will redirect me do another page and I receive never a success from the ajax call. I want to refresh the entire grid on success.

function deleteitem_onclick(url, id) {
        
        var data2post = {
                'Item' : {
                        'id' : id
                }
        };
        
        $.fn.yiiGridView.update('cart-grid', {
                type :'POST',
                url  : url,
                data : data2post,
                success:function(data,status) {
                        $.fn.yiiGridView.update('cart-grid');
                },
                error: function(XMLHttpRequest, textStatus, errorThrown) {
                     alert(XMLHttpRequest.responseText + textStatus + errorThrown);
                 }
        });
}

/*]]>*/


What is wrong with my code?
0

#4 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,359
  • Joined: 12-October 09
  • Location:Croatia

Posted 28 October 2010 - 02:28 AM

View Postviglu, on 27 October 2010 - 12:38 PM, said:

...
But the function will redirect me do another page and I receive never a success from the ajax call.
...


Where does it redirect you? If your action is not called then the problem is in the url parameter...
Find more about me.... btw. Do you know your WAN IP?
0

#5 User is offline   viglu 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 17
  • Joined: 31-July 10
  • Location:Luxembourg

Posted 28 October 2010 - 12:30 PM

I found the error. There was an issue in my javascript

function deleteitem_onclick(url, id) {

        var data2post = {
                'Item' : {
                        'id' : id
                }
        };

        $.ajax({
            url: url,
            cache: false,
            success: function(response, status){
                $.fn.yiiGridView.update('cart-grid');
            }
        });
        

}

0

#6 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,359
  • Joined: 12-October 09
  • Location:Croatia

Posted 28 October 2010 - 01:37 PM

So now you are not sending the data2post variable... so you can delete that part...
Find more about me.... btw. Do you know your WAN IP?
0

#7 User is offline   viglu 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 17
  • Joined: 31-July 10
  • Location:Luxembourg

Posted 28 October 2010 - 01:40 PM

Yes that's right
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users