소스 검색

#4558 - Build-in API support (payments, ads)

roman.lesnikov@gmail.com 2 년 전
부모
커밋
22fc0f1b56

+ 11 - 0
modules/base/payment/classes/BxBaseModPaymentGridCarts.php

@@ -49,6 +49,17 @@ class BxBaseModPaymentGridCarts extends BxTemplGrid
                 $this->_sCurrencySign = $this->_oModule->getVendorCurrencySign($iSellerId);
                 $this->_sCurrencySign = $this->_oModule->getVendorCurrencySign($iSellerId);
         }
         }
     }
     }
+    
+    protected function _getActionDelete($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
+    {   
+        if (bx_is_api()){
+            $a['name'] = $sKey;
+            $a['type'] = 'callback';
+            return $a;
+        }
+        
+    	return $this->_getActionDefault($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
+    }
 
 
     public function addQueryParam($sKey, $sValue)
     public function addQueryParam($sKey, $sValue)
     {
     {

+ 10 - 10
modules/boonex/ads/classes/BxAdsFormSourcesDetails.php

@@ -108,19 +108,19 @@ class BxAdsFormSourcesDetails extends BxTemplFormView
                     break;
                     break;
 
 
                 case 'checkbox':
                 case 'checkbox':
-                    $this->aInputs[$aInput['name']]['value'] = 'on';
-                    $aAddon = array('checked' => $oSource->getOption($aInput['name']) == 'on');
+                   $this->aInputs[$aInput['name']]['value'] = '1';
+                    $aAddon = array('checked' => $oSource->getOption($aInput['name']) == '1');
                     break;
                     break;
 
 
                 case 'value':
                 case 'value':
-                       $sName = str_replace($aInput['source_option_prefix'], '', $aInput['name']);
-                       if(!in_array($sName, array('return_data_url', 'notify_url')))
-                            break;
-
-                       $sMethod = 'get' . bx_gen_method_name($sName);
-                       if(method_exists($oSource, $sMethod))
-                            $this->aInputs[$aInput['name']]['value'] = $oSource->$sMethod($this->_iProfileId);
-                       break;
+                   $sName = str_replace($aInput['source_option_prefix'], '', $aInput['name']);
+                   if(!in_array($sName, array('return_data_url', 'notify_url')))
+                        break;
+
+                   $sMethod = 'get' . bx_gen_method_name($sName);
+                   if(method_exists($oSource, $sMethod))
+                        $this->aInputs[$aInput['name']]['value'] = $oSource->$sMethod($this->_iProfileId);
+                   break;
             }
             }
 
 
             if(!empty($aAddon) && is_array($aAddon))
             if(!empty($aAddon) && is_array($aAddon))

+ 8 - 2
modules/boonex/ads/classes/BxAdsFormsEntryHelper.php

@@ -105,8 +105,11 @@ class BxAdsFormsEntryHelper extends BxBaseModTextFormsEntryHelper
 
 
                 $iVendorId = (int)$oPayments->getOption('site_admin');
                 $iVendorId = (int)$oPayments->getOption('site_admin');
                 $aResult = $oPayments->addToCart($iVendorId, $this->_oModule->_oConfig->getId(), $aCommodity['id'], 1);
                 $aResult = $oPayments->addToCart($iVendorId, $this->_oModule->_oConfig->getId(), $aCommodity['id'], 1);
-                if(isset($aResult['code']) && (int)$aResult['code'] == 0)
+                if(isset($aResult['code']) && (int)$aResult['code'] == 0){
                     $sUrl = $oPayments->getCartUrl($iVendorId);
                     $sUrl = $oPayments->getCartUrl($iVendorId);
+                    if (bx_is_api())
+                        return bx_api_get_block('redirect', ['uri' => '/' . bx_api_get_relative_url($sUrl), 'timeout' => 1000]);
+                }
             }
             }
         }
         }
 
 
@@ -130,8 +133,11 @@ class BxAdsFormsEntryHelper extends BxBaseModTextFormsEntryHelper
 
 
                 $iVendorId = (int)$oPayments->getOption('site_admin');
                 $iVendorId = (int)$oPayments->getOption('site_admin');
                 $aResult = $oPayments->addToCart($iVendorId, $this->_oModule->_oConfig->getId(), $aCommodity['id'], 1);
                 $aResult = $oPayments->addToCart($iVendorId, $this->_oModule->_oConfig->getId(), $aCommodity['id'], 1);
-                if(isset($aResult['code']) && (int)$aResult['code'] == 0)
+                if(isset($aResult['code']) && (int)$aResult['code'] == 0){
                     $sUrl = $oPayments->getCartUrl($iVendorId);
                     $sUrl = $oPayments->getCartUrl($iVendorId);
+                    if (bx_is_api())
+                        return bx_api_get_block('redirect', ['uri' => '/' . bx_api_get_relative_url($sUrl), 'timeout' => 1000]);
+                }
             }
             }
         }
         }
 
 

+ 15 - 10
modules/boonex/ads/classes/BxAdsModule.php

@@ -323,7 +323,8 @@ class BxAdsModule extends BxBaseModTextModule
             'CategoriesList' => '',
             'CategoriesList' => '',
             'BrowseCategory' => '',
             'BrowseCategory' => '',
             'RegisterImpression' => '',
             'RegisterImpression' => '',
-            'RegisterClick' => ''
+            'RegisterClick' => '',
+            'BlockSourcesDetails' => ''
         ]);
         ]);
     }
     }
 
 
@@ -1721,9 +1722,7 @@ class BxAdsModule extends BxBaseModTextModule
         $CNF = &$this->_oConfig->CNF;
         $CNF = &$this->_oConfig->CNF;
 
 
         if(!isLogged())
         if(!isLogged())
-            return [
-                'content' => MsgBox(_t('_Access denied'))
-            ];
+             return bx_is_api() ? [bx_api_get_msg(_t('_Access denied'))] : ['content' => MsgBox(_t('_Access denied'))];
 
 
         $iProfileId = !empty($iProfileId) ? $iProfileId : bx_get_logged_profile_id();
         $iProfileId = !empty($iProfileId) ? $iProfileId : bx_get_logged_profile_id();
 
 
@@ -1738,9 +1737,16 @@ class BxAdsModule extends BxBaseModTextModule
                     $sValue = bx_get($aOption['name']) !== false ? bx_get($aOption['name']) : '';
                     $sValue = bx_get($aOption['name']) !== false ? bx_get($aOption['name']) : '';
                     $this->_oDb->updateSourceOption($iProfileId, $aOption['id'], bx_process_input($sValue));
                     $this->_oDb->updateSourceOption($iProfileId, $aOption['id'], bx_process_input($sValue));
                 }
                 }
-
-                header('Location: ' . bx_absolute_url(BxDolPermalinks::getInstance()->permalink($CNF['URL_SOURCES'])));
-                return;
+                if (bx_is_api()){
+                    return [
+                        bx_api_get_block('form', $oForm->getCodeAPI(), ['ext' => ['name' => $this->getName(), 'request' => ['url' => '/api.php?r=' . $this->getName() . '/block_sources_details', 'immutable' => true]]]),
+                        bx_api_get_block('redirect', ['uri' => '/' . BxDolPermalinks::getInstance()->permalink($CNF['URL_SOURCES']), 'timeout' => 100])
+                        ];
+                }
+                else{
+                    header('Location: ' . bx_absolute_url(BxDolPermalinks::getInstance()->permalink($CNF['URL_SOURCES'])));
+                    return;
+                }
             }
             }
             else
             else
                 foreach($oForm->aInputs as $aInput)
                 foreach($oForm->aInputs as $aInput)
@@ -1751,9 +1757,8 @@ class BxAdsModule extends BxBaseModTextModule
                     }
                     }
         }
         }
 
 
-        return [
-            'content' => $oForm->getCode()
-        ];
+        return bx_is_api() ? [bx_api_get_block('form', $oForm->getCodeAPI(), ['ext' => ['name' => $this->getName(), 'request' => ['url' => '/api.php?r=' . $this->getName() . '/block_sources_details', 'immutable' => true]]])] : ['content' => $oForm->getCode()];
+        
     }
     }
 
 
     public function isEntryActive($aContentInfo)
     public function isEntryActive($aContentInfo)

+ 19 - 2
modules/boonex/payment/classes/BxPaymentGridCart.php

@@ -20,6 +20,19 @@ class BxPaymentGridCart extends BxBaseModPaymentGridCarts
 
 
         $this->_bSelectAll = true;
         $this->_bSelectAll = true;
     }
     }
+    
+    public function getCodeAPI()
+    {
+        $aData = parent::getCodeAPI();
+        $aData['settings']['field_id'] = 'id';
+        foreach ($aData['data'] as &$aRow){
+            $aRow['id'] = $aRow['checkbox']['data'];
+            $aRow['title']['value'] = strip_tags($aRow['title']['value']);
+            $aRow['price_single']['value'] = str_replace('$ ','$', $aRow['price_single']['value']);
+            
+        }
+        return $aData;
+    }
 
 
     public function performActionCheckout()
     public function performActionCheckout()
     {
     {
@@ -149,8 +162,12 @@ class BxPaymentGridCart extends BxBaseModPaymentGridCarts
 
 
                 $sActions .= $sAction;
                 $sActions .= $sAction;
             }
             }
-    	}
+    	}else{
+           if (bx_is_api())
+               return parent::_getActions ($sType, $sActionData, $isSmall, $isDisabled, $isPermanentState, $aRow);
+        }
 
 
+        
     	return $sActions . parent::_getActions ($sType, $sActionData, $isSmall, $isDisabled, $isPermanentState, $aRow);
     	return $sActions . parent::_getActions ($sType, $sActionData, $isSmall, $isDisabled, $isPermanentState, $aRow);
     }
     }
 
 
@@ -195,7 +212,7 @@ class BxPaymentGridCart extends BxBaseModPaymentGridCarts
             if($bProviderCredits && $bPayForCredits)
             if($bProviderCredits && $bPayForCredits)
                 continue;
                 continue;
             
             
-            $aActions[] = [
+            $aActions[$aProvider['name']] = [
                 'title'=> _t('_bx_payment_grid_action_title_crt_checkout', _t($CNF['T']['TXT_CART_PROVIDER'] . $aProvider['name'])),
                 'title'=> _t('_bx_payment_grid_action_title_crt_checkout', _t($CNF['T']['TXT_CART_PROVIDER'] . $aProvider['name'])),
                 'icon' => '',
                 'icon' => '',
                 'icon_only' => 0,
                 'icon_only' => 0,

+ 20 - 1
modules/boonex/payment/classes/BxPaymentGridCarts.php

@@ -18,6 +18,18 @@ class BxPaymentGridCarts extends BxBaseModPaymentGridCarts
 
 
         parent::__construct ($aOptions, $oTemplate);
         parent::__construct ($aOptions, $oTemplate);
     }
     }
+    
+    public function getCodeAPI()
+    {
+        $aData = parent::getCodeAPI();
+        $aData['settings']['field_id'] = 'id';
+        foreach ($aData['data'] as &$aRow){
+            $aRow['id'] = $aRow['checkbox']['data'];
+            $aRow['vendor_id']['value'] = strip_tags($aRow['vendor_id']['value']);
+            $aRow['items_price']['value'] = str_replace('$ ','$', $aRow['items_price']['value']);
+        }
+        return $aData;
+    }
 
 
     protected function _getCellVendorId($mixedValue, $sKey, $aField, $aRow)
     protected function _getCellVendorId($mixedValue, $sKey, $aField, $aRow)
     {
     {
@@ -44,6 +56,13 @@ class BxPaymentGridCarts extends BxBaseModPaymentGridCarts
     	$a['attr'] = array_merge($a['attr'], array(
     	$a['attr'] = array_merge($a['attr'], array(
             "onclick" => "window.open('" . bx_append_url_params($this->_oModule->_oConfig->getUrl('URL_CART'), array('seller_id' => $aRow['vendor_id'])) . "','_self');"
             "onclick" => "window.open('" . bx_append_url_params($this->_oModule->_oConfig->getUrl('URL_CART'), array('seller_id' => $aRow['vendor_id'])) . "','_self');"
     	));
     	));
+        
+         if (bx_is_api()){
+            $a['type'] = 'link';
+            $a['name'] = $sKey;
+            $a['url'] = bx_api_get_relative_url(bx_append_url_params($this->_oModule->_oConfig->getUrl('URL_CART'), array('seller_id' => $aRow['vendor_id'])));
+            return $a;
+        }
 
 
         return  parent::_getActionDefault($sType, $sKey, $a, false, $isDisabled, $aRow);
         return  parent::_getActionDefault($sType, $sKey, $a, false, $isDisabled, $aRow);
     }
     }
@@ -58,7 +77,7 @@ class BxPaymentGridCarts extends BxBaseModPaymentGridCarts
         if(empty($this->_aQueryAppend['client_id']))
         if(empty($this->_aQueryAppend['client_id']))
             return array();
             return array();
 
 
-        $this->_aOptions['source'] = $this->_oModule->getObjectCart()->getInfo(BX_PAYMENT_TYPE_SINGLE, $this->_aQueryAppend['client_id']);
+        $this->_aOptions['source'] = array_values($this->_oModule->getObjectCart()->getInfo(BX_PAYMENT_TYPE_SINGLE, $this->_aQueryAppend['client_id']));
 
 
         return parent::_getDataArray($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage);
         return parent::_getDataArray($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage);
     }
     }

+ 4 - 0
template/scripts/BxBaseFormView.php

@@ -368,6 +368,10 @@ class BxBaseFormView extends BxDolForm
                     $aInput['values'] = '';
                     $aInput['values'] = '';
                     $aInput['values_src'] = '';
                     $aInput['values_src'] = '';
                 }
                 }
+                
+                if (isset($aInput['type']) && 'block_header' == $aInput['type']){
+                    $aInput['name'] = $key;
+                }
 
 
                 if (isset($aInput['type']) && 'location' == $aInput['type']){
                 if (isset($aInput['type']) && 'location' == $aInput['type']){
                     $aLocationIndexes = BxDolForm::$LOCATION_INDEXES;
                     $aLocationIndexes = BxDolForm::$LOCATION_INDEXES;

+ 5 - 1
template/scripts/BxBaseGrid.php

@@ -322,7 +322,8 @@ class BxBaseGrid extends BxDolGrid
         $aFilter = [];
         $aFilter = [];
         $CNF = &$this->_oModule->_oConfig->CNF;
         $CNF = &$this->_oModule->_oConfig->CNF;
         $aFilter[''] = _t($CNF['T']['filter_item_select_one_' . $this->_sFilter1Name]);
         $aFilter[''] = _t($CNF['T']['filter_item_select_one_' . $this->_sFilter1Name]);
-        $aFilter = array_merge($aFilter, $this->_aFilter1Values);
+        if (is_array($this->_aFilter1Values))
+            $aFilter = array_merge($aFilter, $this->_aFilter1Values);
         foreach($aFilter as $iKey => &$aRow) {
         foreach($aFilter as $iKey => &$aRow) {
             $aRow = _t($aRow);
             $aRow = _t($aRow);
         }
         }
@@ -361,6 +362,9 @@ class BxBaseGrid extends BxDolGrid
                     $s = $this->$sMethod($aData[$iKey][$sKey], $sKey, $aField, $aRow);
                     $s = $this->$sMethod($aData[$iKey][$sKey], $sKey, $aField, $aRow);
                     $aDataRv[$iKey][$sKey] = $s;
                     $aDataRv[$iKey][$sKey] = $s;
                 }
                 }
+                else{
+                    $aDataRv[$iKey][$sKey] = ['type' => 'text', 'value'=> $aData[$iKey][$sKey]];    
+                }
                
                
             }
             }
         }
         }