Продолжение приложения А
$carts[$id] = 1;
}
}else{
$carts = array($id => 1);
}
$q->addInCondition('id', array_keys($carts));
$items = Catalog::model()->findAll($q);
$summary = 0;
foreach($items as $item){
$summary += $item->price * $carts[$item->id];
}
$data['summary'] = $summary;
$data['count'] = count($carts);
Yii::app()->session['summary'] = $summary;
Yii::app()->session['count'] = $data['count'];
Yii::app()->session['carts'] = $carts;
echo json_encode($data);
}
public function actionBasketCart()
{
$data = array();
if (Yii::app()->session['carts']) {
$carts = Yii::app()->session['carts'];
$q = new CDbCriteria();
$q->addInCondition('id', array_keys($carts));
$data['items']=Catalog::model()->findAll($q);
$data['count_items'] = $carts;
}
$data['relat_items'] = Catalog::model()->findAll(array('condition'=>'`isVisible`=1','limit'=>4));
$this->render('basket', $data);
}
public function actionDeleted($id)
{
$q = new CDbCriteria();
$carts=Yii::app()->session['carts'];
unset($carts[$id]);
$q->addInCondition('id', array_keys($carts));
$items = Catalog::model()->findAll($q);
$summary = 0;
foreach($items as $item){
$summary += $item->price * $carts[$item->id];
}
$data['id'] = $id;
Yii::app()->session['summary'] = $summary;
Yii::app()->session['count'] = count($items);
Yii::app()->session['carts'] = $carts;
echo json_encode($data);
}
public function actionChangeCart($id, $count)
{
$q = new CDbCriteria();
$carts=Yii::app()->session['carts'];
$carts[$id] = $count;
$q->addInCondition('id', array_keys($carts));
100
Продолжение приложения А
$q->index = 'id';
$items = Catalog::model()->findAll($q);
$summary = 0;
foreach($items as $item){
if ($item->id==$id) {
$data['summary_item'] = $item->price * $carts[$item->id];
}
$summary += $item->price * $carts[$item->id];
}
$data['id'] = $id;
$data['summary'] = $summary;
Yii::app()->session['summary'] = $summary;
Yii::app()->session['count'] = count($items);
Yii::app()->session['carts'] = $carts;
echo json_encode($data);
}
public function actionCheckBasket()
{
$data = array();
if ($carts=Yii::app()->session['carts']) {
if ($order = Yii::app()->getRequest()->getPost('order')) {
$record = new Orders();
$record->attributes = $order;
$record->date = time();
if (!$record->validate()) {
$data['errors']=$record->getErrors();
$data['order'] = $order;
$this->render('checkBasket',$data);
} else {
$record->save(false);
$items = '';
foreach($carts as $key=>$value){
$record_item = new OrdersItem();
$record_item->id_order = $record->id;
$record_item->id_item = $key;
$record_item->count = $value;
$record_item->save();
$item = Catalog::model()->findByPk($key);
$items .= "
{$item->name} |
{$item->price} |
{$value} |
";
}
/* получатели */
$to = "@";
/* тема/subject */
$subject = "Новый заказ на сайте shopkl.kz";
$summary = Yii::app()->session['summary'];
$phone = $order['phone'];
$adress = $order['adress'];
$mail = $order['mail'];
$name = $order['name'];
/* сообщение */
$message = "
101
Продолжение приложения А
Новый заказ
Имя:{$name}
Почта:{$mail}
Адресс:{$adress}
Телефон:{$phone}
Сумма заказа:{$summary}
Название | Цена | Количество |
{$items}
Магазин
Электроники
Звоните:
8(775)1450457
Адрес:
Тынышбаева 23 а
Достарыңызбен бөлісу: |