Просмотр исходного кода

Ticket #5097 - Payments: Use only json encoded values for 'customs' fields in cart and pendings.

AntonLV 1 год назад
Родитель
Сommit
2287872914

+ 4 - 6
modules/base/payment/classes/BxBaseModPaymentCart.php

@@ -255,7 +255,7 @@ class BxBaseModPaymentCart extends BxDol
     {                            
         $aCart = $this->_oModule->_oDb->getCartContent($iUserId);
         if(empty($aCart['items']))
-            return array();
+            return [];
 
         $aCartItems = $this->_oModule->_oConfig->descriptorsM2A($aCart['items']);
         if($this->_bSingleSeller)
@@ -266,8 +266,7 @@ class BxBaseModPaymentCart extends BxDol
         if(empty($aCart['customs']))
             return $aResult;
 
-        $aCartCustoms = unserialize($aCart['customs']);
-
+        $aCartCustoms = $aCart['customs'];
         foreach($aResult as $iVendor => $aItems)
             foreach($aItems as $iIndex => $aItem)
                 $aResult[$iVendor][$iIndex]['custom'] = $this->_oModule->_oConfig->pullCustom($aItem, $aCartCustoms);
@@ -279,14 +278,13 @@ class BxBaseModPaymentCart extends BxDol
     {
         $aCart = $this->_oModule->_oDb->getCartContent($iUserId);
         if(empty($aCart['items']))
-            return array();
+            return [];
 
         $aResult = $this->_reparseBy($this->_oModule->_oConfig->descriptorsM2A($aCart['items']), 'module_id');
         if(empty($aCart['customs']))
             return $aResult;
 
-        $aCartCustoms = unserialize($aCart['customs']);
-
+        $aCartCustoms = $aCart['customs'];
         foreach($aResult as $iModule => $aItems)
             foreach($aItems as $iIndex => $aItem)
                 $aResult[$iModule][$iIndex]['custom'] = $this->_oModule->_oConfig->pullCustom($aItem, $aCartCustoms);

+ 5 - 11
modules/boonex/payment/classes/BxPaymentCart.php

@@ -220,10 +220,7 @@ class BxPaymentCart extends BxBaseModPaymentCart
             }
         }
 
-        $aCartCustom = array();
-        if(!empty($aCart['customs']))
-            $aCartCustom = unserialize($aCart['customs']);
-
+        $aCartCustom = $aCart['customs'];
         if(!empty($aCustom) && is_array($aCustom))
             $aCartCustom[$sCiDsc] = !empty($aCartCustom[$sCiDsc]) && is_array($aCartCustom[$sCiDsc]) ? array_merge($aCartCustom[$sCiDsc], $aCustom) : $aCustom;
 
@@ -265,21 +262,18 @@ class BxPaymentCart extends BxBaseModPaymentCart
      */
     public function serviceDeleteFromCart($iSellerId, $iModuleId = 0, $iItemId = 0)
     {
-    	$CNF = &$this->_oModule->_oConfig->CNF;
+        $CNF = &$this->_oModule->_oConfig->CNF;
 
         if($iSellerId == BX_PAYMENT_EMPTY_ID)
             return array('code' => 1, 'message' => _t($CNF['T']['ERR_WRONG_DATA']));
 
-		$iClientId = $this->_oModule->getProfileId();
+        $iClientId = $this->_oModule->getProfileId();
         if(empty($iClientId))
             return array('code' => 2, 'message' => _t($CNF['T']['ERR_REQUIRED_LOGIN']));
 
         $aCart = $this->_oModule->_oDb->getCartContent($iClientId);
 
-        $aCartCustom = array();
-        if(!empty($aCart['customs']))
-            $aCartCustom = unserialize($aCart['customs']);
-
+        $aCartCustom = $aCart['customs'];
         if(!empty($iModuleId) && !empty($iItemId)) {
             $sCiDsc = $this->_oModule->_oConfig->descriptorA2S(array($iSellerId, $iModuleId, $iItemId));
             if(!empty($aCartCustom[$sCiDsc]))
@@ -302,7 +296,7 @@ class BxPaymentCart extends BxBaseModPaymentCart
             'module_id' => $iModuleId,
             'item_id' => $iItemId,
         ));
-        
+
         return array('code' => 0, 'message' => _t($CNF['T']['MSG_ITEM_DELETED']));
     }
 

+ 9 - 4
modules/boonex/payment/classes/BxPaymentConfig.php

@@ -243,14 +243,19 @@ class BxPaymentConfig extends BxBaseModPaymentConfig
         return 0;
     }
 
-    public function a2s($a)
+    public function a2s($a, $bEncodeString = true)
     {
-        return base64_encode(json_encode($a));
+        $s = json_encode($a);
+
+        return $bEncodeString ? base64_encode($s) : $s;
     }
 
-    public function s2a($s)
+    public function s2a($s, $bDecodeString = true)
     {
-        return json_decode(base64_decode($s), true);
+        if($bDecodeString)
+            $s = base64_decode($s);
+
+        return json_decode($s, true);
     }
 
     public function urlEncode($s)

+ 10 - 5
modules/boonex/payment/classes/BxPaymentDb.php

@@ -231,12 +231,17 @@ class BxPaymentDb extends BxBaseModPaymentDb
 
     public function getCartContent($iId)
     {
-        $aCart = $this->getRow("SELECT * FROM `" . $this->_sPrefix . "cart` WHERE `client_id`=:client_id LIMIT 1", array(
+        $aCart = $this->getRow("SELECT * FROM `" . $this->_sPrefix . "cart` WHERE `client_id`=:client_id LIMIT 1", [
             'client_id' => $iId
-        ));
+        ]);
 
         if(empty($aCart) || !is_array($aCart))
-            $aCart = array('items' => '', 'customs' => '');
+            $aCart = ['items' => '', 'customs' => []];
+
+        if(!empty($aCart['customs']))
+            $aCart['customs'] = is_string($aCart['customs']) ? $this->_oConfig->s2a($aCart['customs'], false) : $aCart['customs'];
+        else 
+            $aCart['customs'] = [];
 
         return $aCart;
     }
@@ -252,7 +257,7 @@ class BxPaymentDb extends BxBaseModPaymentDb
         return $this->query("REPLACE INTO `" . $this->_sPrefix . "cart` SET `client_id`=:client_id, `items`=:items, `customs`=:customs", array(
             'client_id' => $iId,
             'items' => $sItems,
-            'customs' => !empty($aCustoms) && is_array($aCustoms) ? serialize($aCustoms) : ''
+            'customs' => !empty($aCustoms) && is_array($aCustoms) ? $this->_oConfig->a2s($aCustoms, false) : ''
         ));
     }
 
@@ -376,7 +381,7 @@ class BxPaymentDb extends BxBaseModPaymentDb
             'type' => $sType, 
             'provider' => $sProvider,
             'items' => trim($sItems, ':'),
-            'customs' => !empty($aCustom) && is_array($aCustom) ? serialize($aCustom) : '',
+            'customs' => !empty($aCustom) && is_array($aCustom) ? $this->_oConfig->a2s($aCustom, false) : '',
             'amount' => $aCartInfo['items_price'],
             'currency' => $sCurrency,
             'data' => !empty($aData) ? serialize($aData) : ''

+ 12 - 17
modules/boonex/payment/classes/BxPaymentModule.php

@@ -512,18 +512,18 @@ class BxPaymentModule extends BxBaseModPaymentModule
      */
     public function actionAddToCart($iSellerId, $iModuleId, $iItemId, $iItemCount, $sCustom = '')
     {
-        if(empty($sCustom) && bx_get('custom') !== false)
-            $sCustom = bx_process_input(bx_get('custom'));
+        if(empty($sCustom) && ($sCustom = bx_get('custom')) !== false)
+            $sCustom = bx_process_input($sCustom);
 
-        $aCustom = array();
+        $aCustom = [];
         if(!empty($sCustom)) {
-            $aCustom = json_decode(base64_decode($sCustom), true);
+            $aCustom = $this->_oConfig->s2a($sCustom);
             if(empty($aCustom) || !is_array($aCustom))
-                $aCustom = array();
+                $aCustom = [];
         }
 
         $aResult = $this->getObjectCart()->serviceAddToCart($iSellerId, $iModuleId, $iItemId, $iItemCount, $aCustom);
-		echoJson($aResult);
+        echoJson($aResult);
     }
 
     /**
@@ -608,9 +608,9 @@ class BxPaymentModule extends BxBaseModPaymentModule
 
         $aCustom = array();
         if(!empty($sCustom)) {
-            $aCustom = json_decode(base64_decode($sCustom), true);
+            $aCustom = $this->_oConfig->s2a($sCustom);
             if(empty($aCustom) || !is_array($aCustom))
-                $aCustom = array();
+                $aCustom = [];
         }
 
         echoJson($this->getObjectSubscriptions()->serviceSubscribeWithAddons($iSellerId, $sSellerProvider, $iModuleId, $iItemId, $iItemCount, $sItemAddons, $sRedirect, $aCustom));
@@ -993,7 +993,7 @@ class BxPaymentModule extends BxBaseModPaymentModule
             //--- For Single time payments.
             if($bTypeSingle && (float)$aItem[$sKeyPriceSingle] == 0) {
                 $aCart = $this->_oDb->getCartContent($aInfo['client_id']);
-                $aCartCustoms = !empty($aCart['customs']) ? unserialize($aCart['customs']) : array();
+                $aCartCustoms = $aCart['customs'];
 
                 $aCartItem = array($aInfo['vendor_id'], $aItem['module_id'], $aItem['id'], $aItem['quantity']);
                 $aCartItemCustom = $this->_oConfig->pullCustom($aCartItem, $aCartCustoms);
@@ -1025,7 +1025,7 @@ class BxPaymentModule extends BxBaseModPaymentModule
 
         if($bTypeSingle && (empty($aCustoms) || !is_array($aCustoms))) {
             $aCart = $this->_oDb->getCartContent($aInfo['client_id']);
-            $aCartCustoms = !empty($aCart['customs']) ? unserialize($aCart['customs']) : array();
+            $aCartCustoms = $aCart['customs'];
 
             $aCustoms = array();
             foreach($aInfo['items'] as $aItem) {
@@ -1374,13 +1374,8 @@ class BxPaymentModule extends BxBaseModPaymentModule
         $iClientId = (int)$aPending['client_id'];
         $iSellerId = (int)$aPending['seller_id'];
         $sLicense = $this->_oConfig->getLicense();
-        $aCustoms = !empty($aPending['customs']) ? unserialize($aPending['customs']) : [];
-
-        $aCart = [];
-        if($bTypeSingle) {
-            $aCart = $this->_oDb->getCartContent($iClientId);
-            $aCart['customs'] = !empty($aCart['customs']) ? unserialize($aCart['customs']) : [];
-        }
+        $aCustoms = !empty($aPending['customs']) ? $this->_oConfig->s2a($aPending['customs'], false) : [];
+        $aCart = $bTypeSingle ? $this->_oDb->getCartContent($iClientId) : [];
 
         $bResult = false;
         $aItems = $this->_oConfig->descriptorsM2A($aPending['items']);