Skip to content

Commit f60eed5

Browse files
fix bug: add to cart and favorite fail
1 parent c67f7c8 commit f60eed5

File tree

8 files changed

+38
-15
lines changed

8 files changed

+38
-15
lines changed

app/appfront/modules/Catalog/controllers/FavoriteproductController.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*/
1818
class FavoriteproductController extends AppfrontController
1919
{
20-
public $enableCsrfValidation = true;
20+
public $enableCsrfValidation = false;
2121
// 增加收藏
2222
public function actionAdd()
2323
{

app/appfront/modules/Checkout/controllers/CartController.php

+9
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@
1919
class CartController extends AppfrontController
2020
{
2121
public $enableCsrfValidation = true;
22+
public $noCsrfActions = ['add'];
23+
24+
public function beforeAction($action)
25+
{
26+
if(in_array($action->id, $this->noCsrfActions)) {
27+
$this->enableCsrfValidation = false;
28+
}
29+
return parent::beforeAction($action);
30+
}
2231

2332
public function actionIndex()
2433
{

app/appfront/modules/Customer/controllers/AjaxController.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ public function actionIndex()
4343
}
4444
if ($product_id) {
4545
// 添加csrf数据
46-
$csrfName = \fec\helpers\CRequest::getCsrfName();
47-
$csrfVal = \fec\helpers\CRequest::getCsrfValue();
48-
$result_arr['csrfName'] = $csrfName;
49-
$result_arr['csrfVal'] = $csrfVal;
46+
//$csrfName = \fec\helpers\CRequest::getCsrfName();
47+
//$csrfVal = \fec\helpers\CRequest::getCsrfValue();
48+
//$result_arr['csrfName'] = $csrfName;
49+
//$result_arr['csrfVal'] = $csrfVal;
5050
$result_arr['product_id'] = $product_id;
5151
}
5252
$cartQty = Yii::$service->cart->getCartItemQty();

app/appfront/theme/base/front/catalog/product/index.php

+6-3
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,9 @@
255255
$data['custom_option'] = custom_option_json;
256256
$data['product_id'] = "<?= $_id ?>";
257257
$data['qty'] = qty;
258-
$data[csrfName] = csrfVal;
258+
if (csrfName && csrfVal) {
259+
$data[csrfName] = csrfVal;
260+
}
259261
jQuery.ajax({
260262
async:true,
261263
timeout: 6000,
@@ -293,7 +295,9 @@
293295
csrfVal = $(".product_csrf").val();
294296
param = {};
295297
param["product_id"] = product_id;
296-
param[csrfName] = csrfVal;
298+
if (csrfName && csrfVal) {
299+
param[csrfName] = csrfVal;
300+
}
297301
doPost(url, param);
298302
}
299303
});
@@ -352,7 +356,6 @@
352356
<?php $this->endBlock(); ?>
353357
<?php $this->registerJs($this->blocks['add_to_cart'],\yii\web\View::POS_END);//将编写的js代码注册到页面底部 ?>
354358

355-
356359
//tab 切换js
357360
<?php $this->beginBlock('product_info_tab') ?>
358361
var navContainer = document.getElementById("nav-container");

app/apphtml5/modules/Catalog/controllers/FavoriteproductController.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*/
1818
class FavoriteproductController extends AppfrontController
1919
{
20-
public $enableCsrfValidation = true;
20+
public $enableCsrfValidation = false;
2121

2222
// 增加收藏
2323
public function actionAdd()
@@ -30,7 +30,7 @@ public function actionAdd()
3030

3131
public function actionLists()
3232
{
33-
$data = $this->getBlock()->getLastData($editForm);
33+
$data = $this->getBlock()->getLastData();
3434

3535
return $this->render($this->action->id, $data);
3636
}

app/apphtml5/modules/Checkout/controllers/CartController.php

+9
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@
1919
class CartController extends AppfrontController
2020
{
2121
public $enableCsrfValidation = true;
22+
public $noCsrfActions = ['add'];
23+
24+
public function beforeAction($action)
25+
{
26+
if(in_array($action->id, $this->noCsrfActions)) {
27+
$this->enableCsrfValidation = false;
28+
}
29+
return parent::beforeAction($action);
30+
}
2231

2332
public function actionIndex()
2433
{

app/apphtml5/modules/Customer/controllers/AjaxController.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ public function actionProduct()
7272
}
7373
if ($product_id) {
7474
// 添加csrf数据
75-
$csrfName = \fec\helpers\CRequest::getCsrfName();
76-
$csrfVal = \fec\helpers\CRequest::getCsrfValue();
77-
$result_arr['csrfName'] = $csrfName;
78-
$result_arr['csrfVal'] = $csrfVal;
75+
//$csrfName = \fec\helpers\CRequest::getCsrfName();
76+
//$csrfVal = \fec\helpers\CRequest::getCsrfValue();
77+
//$result_arr['csrfName'] = $csrfName;
78+
//$result_arr['csrfVal'] = $csrfVal;
7979
$result_arr['product_id'] = $product_id;
8080
}
8181
}

app/apphtml5/theme/base/html5/catalog/product/index.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,9 @@
290290
$data['custom_option'] = custom_option_json;
291291
$data['product_id'] = "<?= $_id ?>";
292292
$data['qty'] = qty;
293-
$data[csrfName] = csrfVal;
293+
if (csrfName && csrfVal) {
294+
$data[csrfName] = csrfVal;
295+
}
294296
$.ajax({
295297
async:true,
296298
timeout: 6000,

0 commit comments

Comments
 (0)