瀏覽代碼

Merge branch 'master' of https://github.com/unaio/una

roman.lesnikov@gmail.com 2 年之前
父節點
當前提交
8687ea68f1

+ 13 - 0
modules/boonex/ads/classes/BxAdsFormEntry.php

@@ -260,6 +260,19 @@ class BxAdsFormEntry extends BxBaseModTextFormEntry
         return parent::delete($iContentId, $aContentInfo);
     }
 
+    protected function genCustomInputSource ($aInput)
+    {
+        $CNF = &$this->_oModule->_oConfig->CNF;
+
+        $aInput = array_merge($aInput, [
+            'ajax_get_suggestions' => BX_DOL_URL_ROOT . "modules/?r=" . $this->_oModule->_oConfig->getUri() . "/get_source&source_type=" . $this->aInputs[$CNF['FIELD_SOURCE_TYPE']]['value'], 
+            'placeholder' => _t('_bx_ads_form_entry_input_source_paceholder'),
+            'custom' => ['only_once' => true]
+        ]);
+
+        return $this->genCustomInputUsernamesSuggestions($aInput);
+    }
+
     public function genInputPrice(&$aInput)
     {
         $CNF = &$this->_oModule->_oConfig->CNF;

+ 68 - 5
modules/boonex/ads/classes/BxAdsModule.php

@@ -63,6 +63,23 @@ class BxAdsModule extends BxBaseModTextModule
         return $aResult;
     }
 
+    public function actionGetSource()
+    {
+        $sSourceType = bx_get('source_type');
+        if(empty($sSourceType)) {
+            $aSource = $this->serviceGetSource($this->_iProfileId);
+            if(!empty($aSource) && is_array($aSource))
+                $sSourceType = $aSource['name'];
+        }
+
+        $sTerm = bx_get('term');
+
+        $aEntries = $this->serviceLoadEntriesFromSourceByTerm($sSourceType, $sTerm);
+
+        header('Content-Type:text/javascript; charset=utf-8');
+        echo(json_encode($aEntries));
+    }
+
     public function actionLoadEntryFromSource()
     {
         $sSourceType = bx_process_url_param(bx_process_input(bx_get('source_type')));
@@ -318,6 +335,7 @@ class BxAdsModule extends BxBaseModTextModule
         return array_merge(parent::serviceGetSafeServices(), [
             'IsSourcesAvaliable' => '',
             'LoadEntryFromSource' => '',
+            'LoadEntriesFromSourceByTerm' => '',
             'EntityReviews' => '',
             'EntityReviewsRating' => '',
             'CategoriesList' => '',
@@ -1706,15 +1724,61 @@ class BxAdsModule extends BxBaseModTextModule
     	return $mixedResult;
     }
 
-    public function serviceLoadEntryFromSource($sSourceType, $sSource)
+    public function serviceLoadEntriesFromSourceByTerm($sSourceType, $sTerm)
     {
-        $iProfileId = bx_get_logged_profile_id();
+        $CNF = &$this->_oConfig->CNF;
 
-        $oSource = $this->getObjectSource($sSourceType, $iProfileId);
+        $oSource = $this->getObjectSource($sSourceType, $this->_iProfileId);
         if(!$oSource)
             return [];
 
-        return $oSource->getEntry($sSource);
+        $aEntries = $oSource->getEntries(['sample' => 'all_id_title_pairs']);
+        if(empty($aEntries) || !is_array($aEntries))
+            return [];
+
+        $aResults = []; 
+        foreach($aEntries as $aEntry) {
+            if(stripos($aEntry[$CNF['FIELD_TITLE']], $sTerm) === false)
+                continue;
+
+            $aResults[] = [
+                'label' => $aEntry[$CNF['FIELD_TITLE']], 
+                'value' => $aEntry[$CNF['FIELD_SOURCE']], 
+            ];
+        }
+
+        return $aResults; 
+    }
+
+    public function serviceLoadEntryFromSource($sSourceType, $sSource)
+    {
+        $CNF = &$this->_oConfig->CNF;
+
+        $aResult = [];
+        $oSource = $this->getObjectSource($sSourceType, $this->_iProfileId);
+        if(!$oSource)
+            return $aResult;
+
+        $aEntry = $oSource->getEntry($sSource);
+        if(empty($aEntry) || !is_array($aEntry))
+            return $aResult;
+
+        $aName = $this->serviceCheckName($aEntry[$CNF['FIELD_TITLE']]);
+        if(!empty($aName) && is_array($aName))
+            $aResult[$CNF['FIELD_NAME']] = ['type' => 'text', 'value' => $aName['name']];
+
+        $aKey2Type = [
+            $CNF['FIELD_TITLE'] => 'text',
+            $CNF['FIELD_URL'] => 'hidden',
+            $CNF['FIELD_TEXT'] => 'text_html',
+            $CNF['FIELD_PRICE'] => 'text', 
+            $CNF['FIELD_QUANTITY'] => 'text'
+        ];
+        foreach($aEntry as $sKey => $sValue)
+            if(isset($aKey2Type[$sKey]))
+                $aResult[$sKey] = ['type' => $aKey2Type[$sKey], 'value' => $sValue];
+
+        return $aResult;
     }
 
     public function serviceBlockSourcesDetails($iProfileId = 0)
@@ -2457,7 +2521,6 @@ class BxAdsModule extends BxBaseModTextModule
             $sHtmlId = $this->_oConfig->getHtmlIds('unit') . $aContentInfo[$CNF['FIELD_ID']] . '-' . time() . '-' . mt_rand(0, 100);
 
             $aResult = array_merge($aResult, [
-                'url' => 'javascript:void(0)',
                 'onclick' => 'return ' . $sJsObject . '.registerClick(this, ' . $aContentInfo[$CNF['FIELD_ID']] . ')',
                 'raw' => $this->_oTemplate->parseHtmlByName('timeline_post_promotion.html', [
                     'html_id' => $sHtmlId,

+ 72 - 7
modules/boonex/ads/classes/BxAdsSourceShopifyAdmin.php

@@ -70,24 +70,89 @@ class BxAdsSourceShopifyAdmin extends BxAdsSource
         if(empty($aProduct) || !is_array($aProduct) || empty($aProduct['product']))
             return [];
 
-        $aProduct = $aProduct['product'];
+        return $this->_prepareProduct($aProduct['product']);
+    }
+    
+    public function getEntries($aParams)
+    {
+        $CNF = &$this->_oModule->_oConfig->CNF;
+
+        $sSample = $aParams['sample'];
+        $aRequest = [
+            'fields' => 'id,title,handle,body_html,variants',
+            'status' => isset($aParams['status']) ? $aParams['status'] : 'active'
+        ];
+
+        switch($sSample) {
+            case 'ids':
+                $aRequest = array_merge($aRequest, [
+                    'ids' => implode(',', $aParams['ids']),
+                ]);
+                break;
+
+            case 'title':
+                $aRequest = array_merge($aRequest, [
+                    'title' => $aParams['title'],
+                ]);
+                break;
+
+            case 'all_id_title_pairs':
+                $aRequest = array_merge($aRequest, [
+                    'fields' => 'id,title',
+                ]);
+                break;
+
+            case 'all':
+                break;
+        }
+
+        $sProducts = $this->_call('products.json', $aRequest, 'get');
+        if(empty($sProducts))
+            return [];
+        
+        $aProducts = json_decode($sProducts, true);
+        if(empty($aProducts) || !is_array($aProducts) || empty($aProducts['products']))
+            return [];
+
+        $aResults = [];
+        foreach($aProducts['products'] as $aProduct) {
+            switch($sSample) {
+                case 'all_id_title_pairs':
+                    $aResults[] = [
+                        $CNF['FIELD_SOURCE'] => $aProduct['id'],
+                        $CNF['FIELD_TITLE'] => $aProduct['title']
+                    ];
+                    break;
+                 
+                default:
+                    $aResults[] = $this->_prepareProduct($aProduct);
+            }
+        }
+
+        return $aResults;
+    }
+    
+    protected function _prepareProduct($aProduct)
+    {
+        $CNF = &$this->_oModule->_oConfig->CNF;
 
         $aResult = [
-            $CNF['FIELD_TITLE'] => ['type' => 'text', 'value' => $aProduct['title']],
-            $CNF['FIELD_URL'] => ['type' => 'hidden', 'value' => $this->_sStorefront . 'products/' . $aProduct['handle']],
-            $CNF['FIELD_TEXT'] => ['type' => 'text_html', 'value' => $aProduct['body_html']],
+            $CNF['FIELD_SOURCE'] => $aProduct['id'],
+            $CNF['FIELD_TITLE'] => $aProduct['title'],
+            $CNF['FIELD_URL'] => $this->_sStorefront . 'products/' . $aProduct['handle'],
+            $CNF['FIELD_TEXT'] => $aProduct['body_html'],
         ];
 
         if(!empty($aProduct['variants']) && is_array($aProduct['variants'])) {
             $aVariant = array_shift($aProduct['variants']);
 
             if(isset($aVariant['price']))
-                $aResult[$CNF['FIELD_PRICE']] = ['type' => 'text', 'value' => (float)$aVariant['price']];
+                $aResult[$CNF['FIELD_PRICE']] = (float)$aVariant['price'];
 
             if(isset($aVariant['inventory_quantity']))
-                $aResult[$CNF['FIELD_QUANTITY']] = ['type' => 'text', 'value' => (int)$aVariant['inventory_quantity']];
+                $aResult[$CNF['FIELD_QUANTITY']] = (int)$aVariant['inventory_quantity'];
         }
-
+        
         return $aResult;
     }
 

+ 0 - 3
modules/boonex/ads/classes/BxAdsTemplate.php

@@ -293,11 +293,9 @@ class BxAdsTemplate extends BxBaseModTextTemplate
         if($this->_oConfig->isPromotion()) {
             $sJsObject = $this->_oConfig->getJsObject('main');
 
-            $sContentUrl = 'javascript:void(0)';
             $sContentOnclick = 'return ' . $sJsObject . '.registerClick(this, ' . $aData[$CNF['FIELD_ID']] . ')';
 
             $aResult = array_merge($aResult, [
-                'content_url' => $sContentUrl,
                 'bx_if:show_onclick' => [
                     'condition' => true,
                     'content' => [
@@ -309,7 +307,6 @@ class BxAdsTemplate extends BxBaseModTextTemplate
 
             if($aResult['bx_if:thumb']['condition'])
                 $aResult['bx_if:thumb']['content'] = array_merge($aResult['bx_if:thumb']['content'], [
-                    'content_url' => $sContentUrl,
                     'bx_if:show_thumb_onclick' => [
                         'condition' => true,
                         'content' => [

+ 1 - 0
modules/boonex/ads/install/langs/en.xml

@@ -136,6 +136,7 @@
     <string name="_bx_ads_form_entry_input_source_type"><![CDATA[Source]]></string>
     <string name="_bx_ads_form_entry_input_sys_source"><![CDATA[Source]]></string>
     <string name="_bx_ads_form_entry_input_source"><![CDATA[Source]]></string>
+    <string name="_bx_ads_form_entry_input_source_paceholder"><![CDATA[Type product title here...]]></string>
     <string name="_bx_ads_form_entry_input_sys_url"><![CDATA[Link]]></string>
     <string name="_bx_ads_form_entry_input_sys_budget_total"><![CDATA[Campaign budget]]></string>
     <string name="_bx_ads_form_entry_input_budget_total"><![CDATA[Campaign budget]]></string>

+ 1 - 1
modules/boonex/ads/install/sql/install.sql

@@ -814,7 +814,7 @@ INSERT INTO `sys_form_inputs`(`object`, `module`, `name`, `value`, `values`, `ch
 ('bx_ads', 'bx_ads', 'attachments', '', '', 0, 'custom', '_bx_ads_form_entry_input_sys_attachments', '', '', 0, 0, 0, '', '', '', '', '', '', '', '', 1, 0),
 ('bx_ads', 'bx_ads', 'labels', '', '', 0, 'custom', '_sys_form_input_sys_labels', '_sys_form_input_labels', '', 0, 0, 0, '', '', '', '', '', '', '', '', 1, 0),
 ('bx_ads', 'bx_ads', 'source_type', '', '', 0, 'hidden', '_bx_ads_form_entry_input_sys_source_type', '_bx_ads_form_entry_input_source_type', '', 0, 0, 0, '', '', '', '', '', '', 'Xss', '', 1, 0),
-('bx_ads', 'bx_ads', 'source', '', '', 0, 'text', '_bx_ads_form_entry_input_sys_source', '_bx_ads_form_entry_input_source', '', 0, 0, 0, '', '', '', '', '', '', 'Xss', '', 1, 0),
+('bx_ads', 'bx_ads', 'source', '', '', 0, 'custom', '_bx_ads_form_entry_input_sys_source', '_bx_ads_form_entry_input_source', '', 0, 0, 0, '', '', '', '', '', '', '', '', 1, 0),
 ('bx_ads', 'bx_ads', 'url', '', '', 0, 'hidden', '_bx_ads_form_entry_input_sys_url', '', '', 0, 0, 0, '', '', '', '', '', '', 'Xss', '', 1, 0),
 ('bx_ads', 'bx_ads', 'budget_total', '', '', 0, 'text', '_bx_ads_form_entry_input_sys_budget_total', '_bx_ads_form_entry_input_budget_total', '', 0, 0, 0, '', '', '', '', '', '', 'Float', '', 1, 0),
 ('bx_ads', 'bx_ads', 'budget_daily', '', '', 0, 'text', '_bx_ads_form_entry_input_sys_budget_daily', '_bx_ads_form_entry_input_budget_daily', '', 0, 0, 0, '', '', '', '', '', '', 'Float', '', 1, 0);

+ 1 - 0
modules/boonex/russian/data/langs/bx_ads/ru.xml

@@ -135,6 +135,7 @@
     <string name="_bx_ads_form_entry_input_source_type"><![CDATA[Тип источника]]></string>
     <string name="_bx_ads_form_entry_input_sys_source"><![CDATA[Источник]]></string>
     <string name="_bx_ads_form_entry_input_source"><![CDATA[Источник]]></string>
+    <string name="_bx_ads_form_entry_input_source_paceholder"><![CDATA[Введите название продукта...]]></string>
     <string name="_bx_ads_form_entry_input_sys_url"><![CDATA[Ссылка]]></string>
     <string name="_bx_ads_form_entry_input_sys_budget_total"><![CDATA[Бюджет рекламной кампании]]></string>
     <string name="_bx_ads_form_entry_input_budget_total"><![CDATA[Бюджет рекламной кампании]]></string>