Gentics Portal.Node PHP API
 All Classes Namespaces Functions Variables Pages
Public Member Functions | Public Attributes | Protected Member Functions | List of all members
ShoppingCartWidget Class Reference
Inheritance diagram for ShoppingCartWidget:
BaseJuiWidget

Public Member Functions

 init ()
 run ()
 csrfProtect ()
- Public Member Functions inherited from BaseJuiWidget
 getViewFile ($viewName)

Public Attributes

 $items
 $order
 $user
 $step
 $class
 $shipping_info
 $payment_info
 $layout = "ShoppingCartWidget"
 $link_items_to_page = false
 $thankyoupage

Protected Member Functions

 onOrdered ($order)
 performAjaxValidation ($model)

Detailed Description

Gentics Portal.Node PHP Author & Copyright (c) by Gentics Software GmbH sales.nosp@m.@gen.nosp@m.tics..nosp@m.com http://www.gentics.com Licenses can be found in the LICENSE.txt file in the root-folder of this installation You must not use this software without a valid license agreement.

Widget for view shoppingcart steps

Definition at line 12 of file ShoppingCartWidget.php.

Member Function Documentation

ShoppingCartWidget::csrfProtect ( )

Function checks matches the csrf tokens

Returns
boolean returns true if the tokens are matched

Definition at line 316 of file ShoppingCartWidget.php.

Referenced by init().

{
if(Yii::app()->request->isPostRequest && Yii::app()->request->enableCsrfValidation){
if(strcmp($_POST['YII_CSRF_TOKEN'], Yii::app()->request->getCsrfToken()) !== 0 ){
throw new CHttpException(403);
return false;
}
}
return true;
}
ShoppingCartWidget::init ( )

The function initialises widget fields which belongs to current session

Returns
void

Definition at line 66 of file ShoppingCartWidget.php.

References csrfProtect(), EncryptHelper\decrypt(), EncryptHelper\encrypt(), Item\model(), and performAjaxValidation().

{
$this->csrfProtect();
$itemsCount = count(Order::getOrder()->items);
if(!isset($this->shoppingcart_link)){
$this->shoppingcart_link = substr($_SERVER['REDIRECT_URL'],1);
}
if(!isset($this->thankyoupage)
&& isset(Yii::app()->getModule('shoppingcart')->thankyoupage[Yii::app()->language])){
$this->thankyoupage = Yii::app()->getModule('shoppingcart')->thankyoupage[Yii::app()->language];
}
if(isset($this->thankyoupage)){
Yii::app()->user->setState('thankyoupage',$this->thankyoupage);
}
$this->step = isset($_REQUEST['step']) ? $_REQUEST['step'] : 1;
$data = array();
switch($this->step){
case 1:
$order_id = Order::getOrder(true);
$items = Item::model()->findAll('order_id=:order_id',array(':order_id'=>$order_id));
if(isset($_POST['Item']))
{
$valid=true;
foreach($items as $i=>$item)
{
if(isset($_POST['Item'][$i]) && is_numeric($_POST['Item'][$i]['quantity']) && $_POST['Item'][$i]['quantity'] > 0)
$item->quantity = $_POST['Item'][$i]['quantity'];
$valid = $item->validate(array('quantity'))
&& is_numeric($_POST['Item'][$i]['quantity'])
&& $_POST['Item'][$i]['quantity'] > 0
&& $valid;
}
if($valid){
foreach($items as $item){
$item->save();
}
Yii::app()->user->setState('step_1', true);
$this->step++;
}
}
break;
case 2:
$model = Order::getUser();
$this->performAjaxValidation($model);
if(isset($_POST['TmpUser']))
{
$model->attributes=$_POST['TmpUser'];
if($model->validate() && $model->unsetExistFields()->save(false)){
Yii::app()->user->setState('step_2', true);
$this->step++;
}else{
$this->user = $model;
}
}
break;
case 3:
$model = Order::getOrder();
if(isset($_POST['Order']))
{
$model->shipping_info = EncryptHelper::decrypt($_POST['Order']['shipping_info']);
$model->payment_info = EncryptHelper::decrypt($_POST['Order']['payment_info']);
if(md5($model->shipping_info.$model->payment_info) == $_POST['checksum']){
if($model->save(false)){
Yii::app()->user->setState('step_3', true);
$this->step++;
}
}
}
break;
case 4:
$model = Order::getOrder();
$this->performAjaxValidation($model);
if(isset($_POST['Order'])){
$model->verifyCode = $_POST['Order']['verifyCode'];
if(!Yii::app()->user->getState('step_1')){
Yii::app()->controller->redirect(Yii::app()->createUrl($this->shoppingcart_link));
}else
if(!Yii::app()->user->getState('step_2')){
Yii::app()->controller->redirect(Yii::app()->createUrl($this->shoppingcart_link , array('step'=>2)));
}else
if(!Yii::app()->user->getState('step_3')){
Yii::app()->controller->redirect(Yii::app()->createUrl($this->shoppingcart_link , array('step'=>3)));
}
if($model->validate(array('verifyCode'))){
$model->ordered = Order::ORDERED;
$this->onOrdered($model);
if($model->save(false)){
$items = $model->items;
$referrer = $items[count($items)-1]->referrer;
Yii::app()->user->setState('step_1', null);
Yii::app()->user->setState('step_2', null);
Yii::app()->user->setState('step_3', null);
// redirect to thankyoupage if set
if(isset($this->thankyoupage) && !empty($this->thankyoupage)){
Yii::app()->controller->redirect($this->thankyoupage);
}else{
Yii::app()->controller->redirect($referrer);
}
}
}else{
$this->order = $model;
}
}
break;
}
//Extend the lifespan of cookie
if(!headers_sent()){
$cookie = new CHttpCookie('user_id', Order::getUser(true));
$cookie->expire = time()+60 * Yii::app()->getModule('shoppingcart')->max_lifetime;
if(isset(Yii::app()->getModule('shoppingcart')->cookie_domain)){
$cookie->domain = Yii::app()->getModule('shoppingcart')->cookie_domain;
}
Yii::app()->request->cookies['user_id'] = $cookie;
}
if(!isset($this->order)){
$this->order = Order::getOrder();
}
$this->order->shipping_info = EncryptHelper::encrypt($this->shipping_info);
$this->order->payment_info = EncryptHelper::encrypt($this->payment_info);
if(!isset($this->user)){
$this->user = Order::getUser()->implementFromSession();
}
if(!isset($this->items)){
$this->items = Item::model()->findAll('order_id=:order_id',array(':order_id'=>$this->order->id));
}
}
ShoppingCartWidget::performAjaxValidation (   $model)
protected

Performs the AJAX validation.

Parameters
CModelthe model to be validated

Definition at line 301 of file ShoppingCartWidget.php.

Referenced by init().

{
if(isset($_POST['ajax']))
{
ob_clean();
echo CActiveForm::validate($model);
Yii::app()->end();
}
}
ShoppingCartWidget::run ( )

Render ShoppingCartWidget view. In this function can be assign some variables depends of step

Returns
void

Definition at line 223 of file ShoppingCartWidget.php.

{
$params = array();
switch($this->step){
case 1:
break;
case 2:
break;
case 3:
$params['checksum'] = md5($this->shipping_info.$this->payment_info);
break;
case 4;
break;
}
$widgetName = "_shoppingStep_".$this->step;
$content = $this->render($widgetName, $params, true);
$params['content'] = $content;
$this->render($this->layout, $params);
}

The documentation for this class was generated from the following file: