Exemplo n.º 1
0
 // Clear, and turn off output buffering
 // Disable apache output buffering/compression
 if (function_exists('apache_setenv')) {
     apache_setenv('no-gzip', '1');
     apache_setenv('dont-vary', '1');
 }
 // Set RPC response headers
 header("Content-Type: application/json");
 header("Content-Encoding: UTF-8");
 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
 header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
 header("Cache-Control: no-store, no-cache, must-revalidate");
 header("Cache-Control: post-check=0, pre-check=0", false);
 header("Pragma: no-cache");
 if (isset($_POST['action'])) {
     $hash = EshopHelper::getHashForSql();
     // Promocode
     if ($_POST['action'] == 'a') {
         $promocode = trim($_POST['promocode']);
         $response = ['status' => 0];
         if ($promocode != '') {
             if (Yii::$app->db->createCommand("UPDATE promocode SET isused = 1 WHERE id = " . Yii::$app->db->quoteValue($promocode))->execute()) {
                 Yii::$app->db->createCommand("INSERT INTO promocode_hash (promocode_id, cart_hash) VALUES (" . Yii::$app->db->quoteValue($promocode) . ", {$hash})")->execute();
                 $response = ['status' => 1];
             } elseif (Yii::$app->db->createCommand("SELECT COUNT(promocode_id) FROM promocode_hash WHERE promocode_id = " . Yii::$app->db->quoteValue($promocode) . " AND cart_hash = {$hash} LIMIT 1")->queryScalar() > 0) {
                 $response = ['status' => 1];
             }
         }
     } elseif ($_POST['action'] == 'b') {
         $item_id = (int) $_POST['item_id'];
         $size = $_POST['size'];