Răsfoiți Sursa

Ticket #4521 - Payments: Add possibility to change sell price in Manual Order form.

AntonLV 3 ani în urmă
părinte
comite
9ecce3af0a

+ 11 - 7
modules/boonex/payment/classes/BxPaymentGridProcessed.php

@@ -63,7 +63,7 @@ class BxPaymentGridProcessed extends BxBaseModPaymentGridOrders
         foreach($aModules as $aModule)
         foreach($aModules as $aModule)
            $oForm->aInputs['module_id']['values'][] = array('key' => $aModule['id'], 'value' => $aModule['title']);
            $oForm->aInputs['module_id']['values'][] = array('key' => $aModule['id'], 'value' => $aModule['title']);
 
 
-        $oForm->aInputs['items']['content'] = $this->_oModule->_oTemplate->displayItems($sType);
+        $oForm->aInputs['items']['content'] = $this->_oModule->_oTemplate->displayItems($this->_aQueryAppend['seller_id'], $sType);
 
 
         $oForm->initChecker();
         $oForm->initChecker();
         if($oForm->isSubmittedAndValid()) {
         if($oForm->isSubmittedAndValid()) {
@@ -73,7 +73,7 @@ class BxPaymentGridProcessed extends BxBaseModPaymentGridOrders
             if(empty($aItemIds) || !is_array($aItemIds))
             if(empty($aItemIds) || !is_array($aItemIds))
                 return echoJson(array('msg' => $this->_sLangsPrefix . 'err_empty_items'));
                 return echoJson(array('msg' => $this->_sLangsPrefix . 'err_empty_items'));
 
 
-            $aItems = array();
+            $aItems = [];
             $sPriceKey = $this->_oModule->_oConfig->getKey('KEY_ARRAY_PRICE_SINGLE');
             $sPriceKey = $this->_oModule->_oConfig->getKey('KEY_ARRAY_PRICE_SINGLE');
             foreach($aItemIds as $iItemId) {
             foreach($aItemIds as $iItemId) {
                 $iItemId = (int)$iItemId;
                 $iItemId = (int)$iItemId;
@@ -83,11 +83,11 @@ class BxPaymentGridProcessed extends BxBaseModPaymentGridOrders
                 if($iItemQuantity <= 0)
                 if($iItemQuantity <= 0)
                     return echoJson(array('msg' => $this->_sLangsPrefix . 'err_wrong_quantity'));
                     return echoJson(array('msg' => $this->_sLangsPrefix . 'err_wrong_quantity'));
 
 
-                $aItems[] = array(
+                $aItems[$iItemId] = [
                     'id' => $iItemId, 
                     'id' => $iItemId, 
                      $sPriceKey => $fItemPrice, 
                      $sPriceKey => $fItemPrice, 
                     'quantity' => $iItemQuantity
                     'quantity' => $iItemQuantity
-                );
+                ];
             }
             }
 
 
             $mixedResult = $this->_oModule->getObjectOrders()->addOrder(array(
             $mixedResult = $this->_oModule->getObjectOrders()->addOrder(array(
@@ -99,7 +99,7 @@ class BxPaymentGridProcessed extends BxBaseModPaymentGridOrders
                 'error_code' => 0,
                 'error_code' => 0,
                 'error_msg' => 'Manually processed',        		
                 'error_msg' => 'Manually processed',        		
                 'module_id' => $oForm->getCleanValue('module_id'),
                 'module_id' => $oForm->getCleanValue('module_id'),
-                'items' => $aItems
+                'items' => array_values($aItems)
             ));
             ));
             if(is_array($mixedResult))
             if(is_array($mixedResult))
                 return echoJson($mixedResult);
                 return echoJson($mixedResult);
@@ -108,8 +108,12 @@ class BxPaymentGridProcessed extends BxBaseModPaymentGridOrders
             if(!$this->_oModule->registerPayment($iPendingId))
             if(!$this->_oModule->registerPayment($iPendingId))
                 return echoJson(array('msg' => _t($this->_sLangsPrefix . 'err_cannot_perform')));
                 return echoJson(array('msg' => _t($this->_sLangsPrefix . 'err_cannot_perform')));
 
 
-            $aOrders = $this->_oModule->_oDb->getOrderProcessed(array('type' => 'pending_id', 'pending_id' => $iPendingId, 'with_key' => 'id'));
-            return echoJson(array('grid' => $this->getCode(false), 'blink' => array_keys($aOrders)));
+            $aOrders = $this->_oModule->_oDb->getOrderProcessed(['type' => 'pending_id', 'pending_id' => $iPendingId, 'with_key' => 'id']);
+            foreach($aOrders as $iOrder => $aOrder)
+                if((float)$aOrder['amount'] != ($fAmount = $aItems[$aOrder['item_id']][$sPriceKey]))
+                    $this->_oModule->_oDb->updateOrderProcessed($iOrder, ['amount' => $fAmount]);
+
+            return echoJson(['grid' => $this->getCode(false), 'blink' => array_keys($aOrders)]);
         }
         }
 
 
         $sKey = 'order_' . $this->_sOrdersType . '_add';
         $sKey = 'order_' . $this->_sOrdersType . '_add';

+ 6 - 3
modules/boonex/payment/classes/BxPaymentModule.php

@@ -139,12 +139,15 @@ class BxPaymentModule extends BxBaseModPaymentModule
     {
     {
     	$iSellerId = $this->getProfileId();
     	$iSellerId = $this->getProfileId();
         $aItems = $this->callGetCartItems((int)$iModuleId, array($iSellerId));
         $aItems = $this->callGetCartItems((int)$iModuleId, array($iSellerId));
+        $aParams = [
+            'filter' => bx_get('filter')
+        ];
 
 
-        echoJson(array(
+        echoJson([
             'code' => 0, 
             'code' => 0, 
             'eval' => $this->_oConfig->getJsObject('processed') . '.onSelectModule(oData);', 
             'eval' => $this->_oConfig->getJsObject('processed') . '.onSelectModule(oData);', 
-            'data' => $this->_oTemplate->displayItems($sType, $aItems)
-        ));
+            'data' => $this->_oTemplate->displayItems($iSellerId, $sType, $aItems, $aParams)
+        ]);
     }
     }
 
 
     public function actionGetFilterValuesItem($iSellerId, $iModuleId)
     public function actionGetFilterValuesItem($iSellerId, $iModuleId)

+ 40 - 12
modules/boonex/payment/classes/BxPaymentTemplate.php

@@ -383,27 +383,35 @@ class BxPaymentTemplate extends BxBaseModPaymentTemplate
         return $oGrid->getCode();
         return $oGrid->getCode();
     }
     }
 
 
-    public function displayItems($sType, $aItems = array())
+    public function displayItems($iSellerId, $sType, $aItems = [], $aParams = [])
     {
     {
-        $aTmplVarsItems = array();
+        $oModule = $this->getModule();
+        $oForm = new BxTemplFormView([]);
 
 
-        $oForm = new BxTemplFormView(array());
+        $sSign = !$this->_oConfig->isSingleSeller() ? $oModule->getVendorCurrencySign($iSellerId) : $this->_oConfig->getDefaultCurrencySign();
 
 
+        $bFilter = !empty($aParams['filter']);
+        $sFilter = $bFilter ? $aParams['filter'] : '';
+        
+        $aTmplVarsItems = [];
         if(!empty($aItems) && is_array($aItems))
         if(!empty($aItems) && is_array($aItems))
             foreach($aItems as $aItem) {
             foreach($aItems as $aItem) {
+                if($bFilter && stripos($aItem['title'], $sFilter) === false)
+                    continue;
+
                 $fPrice = $this->_oConfig->getPrice($sType, $aItem);
                 $fPrice = $this->_oConfig->getPrice($sType, $aItem);
 
 
-                $aInputHidden = array(
-                    'type' => 'hidden',
-                    'name' => 'item-price-' . $aItem['id'],
-                    'value' => $fPrice
-                );
                 $aInputCheckbox = array(
                 $aInputCheckbox = array(
                     'type' => 'checkbox',
                     'type' => 'checkbox',
                     'name' => 'items[]',
                     'name' => 'items[]',
                     'value' => $aItem['id']
                     'value' => $aItem['id']
                 );
                 );
-                $aInputText = array(
+                $aInputPrice = array(
+                    'type' => 'text',
+                    'name' => 'item-price-' . $aItem['id'],
+                    'value' => $fPrice
+                );
+                $aInputQuantity = array(
                     'type' => 'text',
                     'type' => 'text',
                     'name' => 'item-quantity-' . $aItem['id'],
                     'name' => 'item-quantity-' . $aItem['id'],
                     'value' => 1
                     'value' => 1
@@ -412,6 +420,7 @@ class BxPaymentTemplate extends BxBaseModPaymentTemplate
                 $aTmplVarsItems[$aItem['name']] = array(
                 $aTmplVarsItems[$aItem['name']] = array(
                     'id' => $aItem['id'],
                     'id' => $aItem['id'],
                     'price' => $fPrice,
                     'price' => $fPrice,
+                    'price_f' => _t_format_currency_ext($fPrice, ['sign' => $sSign]),
                     'bx_if:link' => array(
                     'bx_if:link' => array(
                         'condition' => !empty($aItem['url']),
                         'condition' => !empty($aItem['url']),
                         'content' => array(
                         'content' => array(
@@ -425,21 +434,40 @@ class BxPaymentTemplate extends BxBaseModPaymentTemplate
                             'title' => $aItem['title']
                             'title' => $aItem['title']
                         )
                         )
                     ),
                     ),
-                    'input_hidden' => $oForm->genInput($aInputHidden),
                     'input_checkbox' => $oForm->genInput($aInputCheckbox),
                     'input_checkbox' => $oForm->genInput($aInputCheckbox),
-                    'input_text' => $oForm->genInput($aInputText),
+                    'input_price' => $oForm->genInput($aInputPrice),
+                    'input_quantity' => $oForm->genInput($aInputQuantity),
                 );
                 );
             }
             }
 
 
-        if(!empty($aTmplVarsItems) && is_array($aTmplVarsItems)) {
+        
+        $bTmplVarsItems = !empty($aTmplVarsItems) && is_array($aTmplVarsItems);
+        if($bTmplVarsItems) {
             ksort($aTmplVarsItems);
             ksort($aTmplVarsItems);
             $aTmplVarsItems = array_values($aTmplVarsItems);
             $aTmplVarsItems = array_values($aTmplVarsItems);
         }
         }
         else 
         else 
             $aTmplVarsItems = MsgBox(_t($this->_sLangsPrefix . 'msg_no_results'));
             $aTmplVarsItems = MsgBox(_t($this->_sLangsPrefix . 'msg_no_results'));
 
 
+        $sInputFilter = '';
+        if($bFilter || $bTmplVarsItems) {
+            $sJsMethod = 'javascript:' . $this->_oModule->_oConfig->getJsObject('processed') . '.filterItems(event, this);';
+            $aInputFilter = [
+                'type' => 'text',
+                'name' => 'filter',
+                'value' => $sFilter,
+                'attrs' => [
+                    'placeholder' => _t('_sys_search_placeholder'),
+                    'onkeydown' => $sJsMethod,
+                    'onpaste' => $sJsMethod
+                ]
+            ];
+            $sInputFilter = $oForm->genInput($aInputFilter);
+        }       
+
         return $this->parseHtmlByName('items.html', array(
         return $this->parseHtmlByName('items.html', array(
             'html_id' => $this->_oConfig->getHtmlIds('processed', 'order_processed_items'),
             'html_id' => $this->_oConfig->getHtmlIds('processed', 'order_processed_items'),
+            'input_filter' => $sInputFilter,
             'bx_repeat:items' => $aTmplVarsItems
             'bx_repeat:items' => $aTmplVarsItems
         ));
         ));
     }
     }

+ 4 - 1
modules/boonex/payment/install/langs/en.xml

@@ -229,7 +229,7 @@
     <string name="_bx_payment_form_processed_input_module_id"><![CDATA[Module]]></string>
     <string name="_bx_payment_form_processed_input_module_id"><![CDATA[Module]]></string>
     <string name="_bx_payment_form_processed_input_module_id_err"><![CDATA[You need to select a module here.]]></string>
     <string name="_bx_payment_form_processed_input_module_id_err"><![CDATA[You need to select a module here.]]></string>
     <string name="_bx_payment_form_processed_input_items_sys"><![CDATA[Items]]></string>
     <string name="_bx_payment_form_processed_input_items_sys"><![CDATA[Items]]></string>
-    <string name="_bx_payment_form_processed_input_items"><![CDATA[Items]]></string>
+    <string name="_bx_payment_form_processed_input_items"><![CDATA[]]></string>
     <string name="_bx_payment_form_processed_input_items_err"><![CDATA[You need to select at least one item from the list here.]]></string>
     <string name="_bx_payment_form_processed_input_items_err"><![CDATA[You need to select at least one item from the list here.]]></string>
     <string name="_bx_payment_form_processed_input_add"><![CDATA[Add]]></string>
     <string name="_bx_payment_form_processed_input_add"><![CDATA[Add]]></string>
     <string name="_bx_payment_form_processed_input_add_sys"><![CDATA[Add]]></string>
     <string name="_bx_payment_form_processed_input_add_sys"><![CDATA[Add]]></string>
@@ -394,8 +394,11 @@
     <string name="_bx_payment_txt_license"><![CDATA[License]]></string>
     <string name="_bx_payment_txt_license"><![CDATA[License]]></string>
     <string name="_bx_payment_txt_seller"><![CDATA[Seller]]></string>
     <string name="_bx_payment_txt_seller"><![CDATA[Seller]]></string>
     <string name="_bx_payment_txt_author"><![CDATA[Author]]></string>
     <string name="_bx_payment_txt_author"><![CDATA[Author]]></string>
+    <string name="_bx_payment_txt_item"><![CDATA[Product]]></string>
+    <string name="_bx_payment_txt_quantity"><![CDATA[Qt.]]></string>
     <string name="_bx_payment_txt_order"><![CDATA[Order ID]]></string>
     <string name="_bx_payment_txt_order"><![CDATA[Order ID]]></string>
     <string name="_bx_payment_txt_price"><![CDATA[Price]]></string>
     <string name="_bx_payment_txt_price"><![CDATA[Price]]></string>
+    <string name="_bx_payment_txt_price_sold"><![CDATA[Sold Price]]></string>
     <string name="_bx_payment_txt_processed_with"><![CDATA[Processed with]]></string>
     <string name="_bx_payment_txt_processed_with"><![CDATA[Processed with]]></string>
     <string name="_bx_payment_txt_message"><![CDATA[Result]]></string>
     <string name="_bx_payment_txt_message"><![CDATA[Result]]></string>
     <string name="_bx_payment_txt_date"><![CDATA[Date]]></string>
     <string name="_bx_payment_txt_date"><![CDATA[Date]]></string>

+ 34 - 2
modules/boonex/payment/js/orders.js

@@ -128,14 +128,46 @@ BxPaymentOrders.prototype.selectModule = function(oSelect) {
             _t:oDate.getTime()
             _t:oDate.getTime()
         },
         },
         function(oData) {
         function(oData) {
-        	oPopup.bx_loading(false);
+            oPopup.bx_loading(false);
 
 
-        	processJsonData(oData);
+            processJsonData(oData);
         },
         },
         'json'
         'json'
     );
     );
 };
 };
 
 
+BxPaymentOrders.prototype.filterItems = function(e, oFilter) {
+    var $this = this;
+    var oDate = new Date();
+
+    var oPopup = $('#' + this._aHtmlIds['order_processed_add']);
+    oPopup.bx_loading(true);
+
+    if ('undefined' != typeof(glBxPaymentOrdersTimeoutHandler) && glBxPaymentOrdersTimeoutHandler)
+        clearTimeout(glBxPaymentOrdersTimeoutHandler);
+
+    glBxPaymentOrdersTimeoutHandler = setTimeout(function () {
+        $.get(
+            $this._sActionsUrl + 'get_items/single/' + parseInt(oPopup.find("[name = 'module_id']").val()) + '/',
+            {
+                filter: $(oFilter).val(),
+                _t:oDate.getTime()
+            },
+            function(oData) {
+                oPopup.bx_loading(false);
+
+                processJsonData(oData);
+
+                oFilter = oPopup.find("[name = 'filter']").focus().get(0);
+                oFilter.selectionStart = oFilter.selectionEnd = oFilter.value.length;
+            },
+            'json'
+        );
+    }, 500);
+
+    return true;
+};
+
 BxPaymentOrders.prototype.onSelectModule = function(oData) {
 BxPaymentOrders.prototype.onSelectModule = function(oData) {
 	if(oData.data != undefined)
 	if(oData.data != undefined)
 		$('#' + this._aHtmlIds['order_processed_items']).replaceWith(oData.data);
 		$('#' + this._aHtmlIds['order_processed_items']).replaceWith(oData.data);

+ 18 - 10
modules/boonex/payment/template/css/orders.css

@@ -21,27 +21,35 @@ div.bx-payment-pa-item {
     -webkit-align-items: center;
     -webkit-align-items: center;
     align-items: center;
     align-items: center;
 }
 }
-div.bx-payment-pa-item-chb,
+div.bx-payment-pa-item.bx-payment-pai-filter .bx-form-input-text {
+    width: 40%;
+}
+
 div.bx-payment-pa-item-title,
 div.bx-payment-pa-item-title,
 div.bx-payment-pa-item-quantity {
 div.bx-payment-pa-item-quantity {
     position: relative;
     position: relative;
 }
 }
-div.bx-payment-pa-item-chb input {
-    display: block;
-    margin: 0px;
-    padding: 0px;
-}
 div.bx-payment-pa-item-title {
 div.bx-payment-pa-item-title {
-    width: 80%;
+    width: 50%;
 }
 }
 div.bx-payment-pa-item-title-cnt {
 div.bx-payment-pa-item-title-cnt {
-	TEXT-OVERFLOW: ellipsis;
+    TEXT-OVERFLOW: ellipsis;
     -o-text-overflow: ellipsis;
     -o-text-overflow: ellipsis;
     white-space: nowrap;
     white-space: nowrap;
-	overflow: hidden;
+    overflow: hidden;
+}
+div.bx-payment-pa-item-title .bx-form-input-checkbox {
+    margin: 0px;
+    padding: 0px;
+    vertical-align: middle;
+}
+div.bx-payment-pa-item-price {
+    width: 20%;
+    box-sizing: border-box;
 }
 }
 div.bx-payment-pa-item-quantity {
 div.bx-payment-pa-item-quantity {
-    width: 16%;
+    width: 10%;
+    box-sizing: border-box;
 }
 }
 
 
 /*--- View Order ---*/
 /*--- View Order ---*/

+ 12 - 3
modules/boonex/payment/template/items.html

@@ -1,17 +1,26 @@
 <div id="__html_id__" class="bx-payment-pa-items">
 <div id="__html_id__" class="bx-payment-pa-items">
     <div class="bx-payment-pa-items-cnt">
     <div class="bx-payment-pa-items-cnt">
+        <div class="bx-payment-pa-item bx-payment-pai-filter bx-def-margin-thd-top-auto bx-clearfix">__input_filter__</div>
+        <div class="bx-payment-pa-item bx-payment-pai-header bx-def-margin-thd-top-auto bx-clearfix">
+            <div class="bx-payment-pa-item-title bx-def-padding-thd-right"><bx_text:_bx_payment_txt_item /></div>
+            <div class="bx-payment-pa-item-price bx-def-padding-thd-right"><bx_text:_bx_payment_txt_price /></div>
+            <div class="bx-payment-pa-item-price bx-def-padding-thd-right"><bx_text:_bx_payment_txt_price_sold /></div>
+            <div class="bx-payment-pa-item-quantity"><bx_text:_bx_payment_txt_quantity /></div>
+        </div>
         <bx_repeat:items>
         <bx_repeat:items>
             <div class="bx-payment-pa-item bx-def-margin-thd-top-auto bx-clearfix">
             <div class="bx-payment-pa-item bx-def-margin-thd-top-auto bx-clearfix">
-                <div class="bx-payment-pa-item-chb">__input_hidden____input_checkbox__</div>
                 <div class="bx-payment-pa-item-title">
                 <div class="bx-payment-pa-item-title">
-                    <div class="bx-payment-pa-item-title-cnt bx-def-padding-sec-leftright">
+                    <div class="bx-payment-pa-item-title-cnt bx-def-padding-thd-right">
+                        __input_checkbox__
                         <bx_if:link>
                         <bx_if:link>
                             <a href="__url__" target="_blank" title="__title__">__title__</a>
                             <a href="__url__" target="_blank" title="__title__">__title__</a>
                         </bx_if:link>
                         </bx_if:link>
                         <bx_if:text>__title__</bx_if:text>
                         <bx_if:text>__title__</bx_if:text>
                     </div>
                     </div>
                 </div>
                 </div>
-                <div class="bx-payment-pa-item-quantity">__input_text__</div>
+                <div class="bx-payment-pa-item-price bx-def-padding-thd-right">__price_f__</div>
+                <div class="bx-payment-pa-item-price bx-def-padding-thd-right">__input_price__</div>
+                <div class="bx-payment-pa-item-quantity">__input_quantity__</div>
             </div>
             </div>
         </bx_repeat:items>
         </bx_repeat:items>
     </div>
     </div>

+ 4 - 1
modules/boonex/russian/data/langs/bx_payment/ru.xml

@@ -230,7 +230,7 @@
     <string name="_bx_payment_form_processed_input_module_id"><![CDATA[Модуль]]></string>
     <string name="_bx_payment_form_processed_input_module_id"><![CDATA[Модуль]]></string>
     <string name="_bx_payment_form_processed_input_module_id_err"><![CDATA[Вам необходимо выбрать модуль.]]></string>
     <string name="_bx_payment_form_processed_input_module_id_err"><![CDATA[Вам необходимо выбрать модуль.]]></string>
     <string name="_bx_payment_form_processed_input_items_sys"><![CDATA[Товары]]></string>
     <string name="_bx_payment_form_processed_input_items_sys"><![CDATA[Товары]]></string>
-    <string name="_bx_payment_form_processed_input_items"><![CDATA[Товары]]></string>
+    <string name="_bx_payment_form_processed_input_items"><![CDATA[]]></string>
     <string name="_bx_payment_form_processed_input_items_err"><![CDATA[Вам необходимо выбрать хотя бы один товар из списка.]]></string>
     <string name="_bx_payment_form_processed_input_items_err"><![CDATA[Вам необходимо выбрать хотя бы один товар из списка.]]></string>
     <string name="_bx_payment_form_processed_input_add"><![CDATA[Добавить]]></string>
     <string name="_bx_payment_form_processed_input_add"><![CDATA[Добавить]]></string>
     <string name="_bx_payment_form_processed_input_add_sys"><![CDATA[Добавить]]></string>
     <string name="_bx_payment_form_processed_input_add_sys"><![CDATA[Добавить]]></string>
@@ -396,8 +396,11 @@
     <string name="_bx_payment_txt_license"><![CDATA[Лицензия]]></string>
     <string name="_bx_payment_txt_license"><![CDATA[Лицензия]]></string>
     <string name="_bx_payment_txt_seller"><![CDATA[Продавец]]></string>
     <string name="_bx_payment_txt_seller"><![CDATA[Продавец]]></string>
     <string name="_bx_payment_txt_author"><![CDATA[Автор]]></string>
     <string name="_bx_payment_txt_author"><![CDATA[Автор]]></string>
+    <string name="_bx_payment_txt_item"><![CDATA[Товар]]></string>
+    <string name="_bx_payment_txt_quantity"><![CDATA[Шт.]]></string>
     <string name="_bx_payment_txt_order"><![CDATA[ID заказа]]></string>
     <string name="_bx_payment_txt_order"><![CDATA[ID заказа]]></string>
     <string name="_bx_payment_txt_price"><![CDATA[Цена]]></string>
     <string name="_bx_payment_txt_price"><![CDATA[Цена]]></string>
+    <string name="_bx_payment_txt_price_sold"><![CDATA[Цена продажи]]></string>
     <string name="_bx_payment_txt_processed_with"><![CDATA[Обработан используя]]></string>
     <string name="_bx_payment_txt_processed_with"><![CDATA[Обработан используя]]></string>
     <string name="_bx_payment_txt_message"><![CDATA[Результат]]></string>
     <string name="_bx_payment_txt_message"><![CDATA[Результат]]></string>
     <string name="_bx_payment_txt_date"><![CDATA[Дата]]></string>
     <string name="_bx_payment_txt_date"><![CDATA[Дата]]></string>