Pārlūkot izejas kodu

#31 - Studio: Inline notifications in Store.

AntonLV 11 gadi atpakaļ
vecāks
revīzija
d248e2e734

+ 1 - 0
modules/boonex/english/data/langs/system/en.xml

@@ -519,6 +519,7 @@
 	<string name="_adm_bp_wrn_page_delete"><![CDATA[Are you sure you want to delete the page?]]></string>
 	<string name="_adm_bp_wrn_page_block_delete"><![CDATA[Are you sure you want to delete the block?]]></string>
 	<string name="_adm_btn_cancel_submit"><![CDATA[Cancel]]></string>
+	<string name="_adm_btn_checkout_submit"><![CDATA[Checkout]]></string>
 	<string name="_adm_btn_delete_submit"><![CDATA[Delete]]></string>
 	<string name="_adm_btn_designer_submit"><![CDATA[Submit]]></string>
 	<string name="_adm_btn_download_submit"><![CDATA[Download]]></string>

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

@@ -519,6 +519,7 @@
 	<string name="_adm_bp_wrn_page_delete"><![CDATA[Вы уверены, что хотите удалить эту страницу?]]></string>
 	<string name="_adm_bp_wrn_page_block_delete"><![CDATA[Вы уверены, что хотите удалить этот блок?]]></string>
 	<string name="_adm_btn_cancel_submit"><![CDATA[Отменить]]></string>
+	<string name="_adm_btn_checkout_submit"><![CDATA[Оплатить]]></string>
 	<string name="_adm_btn_delete_submit"><![CDATA[Удалить]]></string>
 	<string name="_adm_btn_designer_submit"><![CDATA[Выполнить]]></string>
 	<string name="_adm_btn_download_submit"><![CDATA[Скачать]]></string>

+ 10 - 5
studio/classes/BxDolStudioCart.php

@@ -66,10 +66,17 @@ class BxDolStudioCart extends BxDol implements iBxDolSingleton
         return $aResult;
     }
 
+	public function exists($sVendor, $iItemId)
+	{
+		$sDiv = BxDolStudioCart::$sPDiv;
+
+		$sCartItems = $this->getItems();
+		return strpos($sCartItems, $sVendor . $sDiv . $iItemId . $sDiv) !== false;
+	}
+
     public function add($sVendor, $iItemId, $iItemCount)
     {
         $sDiv = BxDolStudioCart::$sPDiv;
-        $oSession = BxDolSession::getInstance();
 
         $sCartItem = $sVendor . $sDiv . $iItemId . $sDiv . $iItemCount;
         $sCartItems = $this->getItems();
@@ -124,14 +131,12 @@ class BxDolStudioCart extends BxDol implements iBxDolSingleton
 
     protected function getItems()
     {
-        $oSession = BxDolSession::getInstance();
-        return $oSession->getValue($this->sSessionKey);
+        return BxDolSession::getInstance()->getValue($this->sSessionKey);
     }
 
     protected function setItems($sItems)
     {
-        $oSession = BxDolSession::getInstance();
-        $oSession->setValue($this->sSessionKey, $sItems);
+        BxDolSession::getInstance()->setValue($this->sSessionKey, $sItems);
     }
 
     protected function parseBy($aItems, $sKey)

+ 6 - 13
studio/classes/BxDolStudioStore.php

@@ -92,12 +92,12 @@ class BxDolStudioStore extends BxTemplStudioPage
                     $iItemCount = 1;
 
                     if(empty($sVendor) || empty($iItem)) {
-                        $aResult = array('code' => BX_DOL_STUDIO_IU_RC_FAILED, 'message' => _t('_adm_err_modules_cannot_add_to_cart'), 'message_inline' => true);
+                        $aResult = array('code' => BX_DOL_STUDIO_IU_RC_FAILED, 'message' => _t('_adm_err_modules_cannot_add_to_cart'));
                         break;
                     }
 
                     BxDolStudioCart::getInstance()->add($sVendor, $iItem, $iItemCount);
-                    $aResult = array('code' => BX_DOL_STUDIO_IU_RC_SUCCESS, 'message' => _t('_adm_msg_modules_success_added_to_cart'), 'message_inline' => true);
+                    $aResult = array('code' => BX_DOL_STUDIO_IU_RC_SUCCESS, 'message' => _t('_adm_msg_modules_success_added_to_cart'));
                     break;
 
                 case 'delete-from-cart':
@@ -105,7 +105,7 @@ class BxDolStudioStore extends BxTemplStudioPage
                     $iItem = (int)bx_get('str_item');
 
                     if(empty($sVendor)) {
-                        $aResult = array('code' => BX_DOL_STUDIO_IU_RC_FAILED, 'message' => _t('_adm_err_modules_cannot_delete_from_cart'), 'message_inline' => true);
+                        $aResult = array('code' => BX_DOL_STUDIO_IU_RC_FAILED, 'message' => _t('_adm_err_modules_cannot_delete_from_cart'));
                         break;
                     }
 
@@ -116,7 +116,7 @@ class BxDolStudioStore extends BxTemplStudioPage
                 case 'checkout-cart':
                     $sVendor = bx_process_input(bx_get('str_vendor'));
                     if(empty($sVendor)) {
-                        $aResult = array('code' => BX_DOL_STUDIO_IU_RC_FAILED, 'message' => _t('_adm_err_modules_cannot_checkout_empty_vendor'), 'message_inline' => true);
+                        $aResult = array('code' => BX_DOL_STUDIO_IU_RC_FAILED, 'message' => _t('_adm_err_modules_cannot_checkout_empty_vendor'));
                         break;
                     }
 
@@ -149,15 +149,8 @@ class BxDolStudioStore extends BxTemplStudioPage
                     break;
             }
 
-            if(!empty($aResult['message'])) {
-            	$oTemplate = BxDolStudioTemplate::getInstance();
-            	$oFunctions = BxTemplStudioFunctions::getInstance();
-
-            	if(isset($aResult['message_inline']) && $aResult['message_inline'] === true)
-            		$aResult['message'] = $oFunctions->inlineBox('', $oTemplate->parseHtmlByName('mod_action_result_inline.html', array('content' => $aResult['message'])), true);
-            	else
-            		$aResult['message'] = $oFunctions->transBox('', $oTemplate->parseHtmlByName('mod_action_result.html', array('content' => $aResult['message'])));
-            }
+            if(!empty($aResult['message']))
+				$aResult['message'] = BxTemplStudioFunctions::getInstance()->inlineBox('', BxDolStudioTemplate::getInstance()->parseHtmlByName('mod_action_result_inline.html', array('content' => $aResult['message'])), true);
 
             echo json_encode($aResult);
             exit;

+ 16 - 13
studio/js/store.js

@@ -13,8 +13,6 @@ function BxDolStudioStore(oOptions) {
 
     this.sIdPageContent = 'bx-std-pc-content';
     this.sIdPopupProduct = 'bx-std-str-popup-product';
-    this.sIdPopupFiles = 'bx-std-str-popup-files';
-    this.sIdPopupFile = 'bx-std-str-popup-file';
 }
 
 BxDolStudioStore.prototype.addToCart = function(sVendor, iProduct, oButton) {
@@ -41,6 +39,8 @@ BxDolStudioStore.prototype.addToCart = function(sVendor, iProduct, oButton) {
 
 				if(parseInt(oCounter.html()) > 0)
 					oCounter.parent('.bx-std-pmen-item-counter').show();
+
+				$(oButton).hide().next('.bx-std-pc-checkout').show();
 			}
 		},
 		'json'
@@ -188,7 +188,7 @@ BxDolStudioStore.prototype._onGetFile = function(oData, oButton) {
 	}
 
 	if(oData.message)
-		this.showPopup(this.sIdPopupFile, oData.message, oButton);
+		this.showNotification(oData.message);
 };
 
 BxDolStudioStore.prototype.info = function(sModuleName, oLink) {
@@ -217,7 +217,7 @@ BxDolStudioStore.prototype.info = function(sModuleName, oLink) {
 				});
 			}
 			else
-				$this.showPopup(sId, oData.message, oLink);
+				$this.showNotification(oData.message);
 		},
 		'json'
 	);
@@ -321,7 +321,7 @@ BxDolStudioStore.prototype.perform = function(sType, sValue, onSuccess, oInput)
     		bx_loading_btn(oInput, false);
 
     		if(oData.message.length > 0)
-    			$this.showPopup('bx-std-str-popup-' + sType, oData.message);
+    			$this.showNotification(oData.message);
 
     		switch(parseInt(oData.code)) {
 	    		case 0:
@@ -351,7 +351,7 @@ BxDolStudioStore.prototype.changePage = function(sType) {
 		},
 		function(oData) {
 			if(oData.code != 0) {
-				$this.showPopup('bx-std-str-popup-browsing', oData.message);
+				$this.showNotification(oData.message);
 				return;
 			}
 
@@ -383,7 +383,7 @@ BxDolStudioStore.prototype.changePagePaginate = function(oButton, sType, iStart,
 		},
 		function(oData) {
 			if(oData.code != 0) {
-				$this.showPopup('bx-std-str-popup-browsing', oData.message);
+				$this.showNotification(oData.message);
 				return;
 			}
 
@@ -397,6 +397,15 @@ BxDolStudioStore.prototype.changePagePaginate = function(oButton, sType, iStart,
 	return true;
 };
 
+BxDolStudioStore.prototype.showNotification = function(sContent) {
+	$(sContent).appendTo('body').dolPopupInline({
+		removeOnClose: true
+	});   
+};
+
+/**
+ * It isn't used anywhere for now.
+ */
 BxDolStudioStore.prototype.showPopup = function(sId, sContent, mixedPointer) {
     $('#' + sId).remove();
     $('<div id="' + sId + '" style="display: none;"></div>').appendTo('body').html(sContent);
@@ -409,10 +418,4 @@ BxDolStudioStore.prototype.showPopup = function(sId, sContent, mixedPointer) {
 
     $('#' + sId).dolPopup(oParams);
 };
-
-BxDolStudioStore.prototype.showNotification = function(sContent) {
-	$(sContent).appendTo('body').dolPopupInline({
-		removeOnClose: true
-	});   
-};
 /** @} */

+ 32 - 2
studio/template/scripts/BxBaseStudioStore.php

@@ -421,6 +421,9 @@ class BxBaseStudioStore extends BxDolStudioStore
 
         $bFree = (int)$aProduct['is_free'] == 1;
         $bPurchased = (int)$aProduct['is_purchased'] == 1;
+        $bPurchase = !$bFree && !$bPurchased;
+
+		$bInCart = $bPurchase && BxDolStudioCart::getInstance()->exists($aProduct['author_name'], $aProduct['id']);
 
         $bDownloadable = (int)$aProduct['is_file'] == 1;
         $bDownloaded = array_key_exists($sModuleName, $aDownloaded);
@@ -473,13 +476,25 @@ class BxBaseStudioStore extends BxDolStudioStore
                 )
             ),
             'bx_if:show_purchase' => array(
-                'condition' => !$bFree && !$bPurchased,
+                'condition' => $bPurchase && !$bInCart,
                 'content' => array(
                     'js_object' => $sJsObject,
                     'id' => $aProduct['id'],
                     'vendor' => $aProduct['author_name'],
                 )
             ),
+            'bx_if:show_checkout' => array(
+                    'condition' => $bPurchase,
+                    'content' => array(
+                        'js_object' => $sJsObject,
+                        'id' => $aProduct['id'],
+                        'vendor' => $aProduct['author_name'],
+                		'bx_if:show_as_hidden' => array(
+                			'condition' => !$bInCart,
+                			'content' => array()
+                		)
+                    )
+                ),
             'bx_if:show_download' => array(
                 'condition' => $bDownload && !$bDownloaded,
                 'content' => array(
@@ -537,6 +552,9 @@ class BxBaseStudioStore extends BxDolStudioStore
         foreach($aItems as $aItem) {
             $bFree = (int)$aItem['is_free'] == 1;
             $bPurchased = (int)$aItem['is_purchased'] == 1;
+            $bPurchase = !$bShoppingCart && !$bFree && !$bPurchased;
+
+            $bInCart = $bPurchase && BxDolStudioCart::getInstance()->exists($aItem['author'], $aItem['id']);
 
             $bDownloadable = (int)$aItem['is_file'] == 1;
             $bDownloaded = in_array($aItem['name'], $aDownloaded);
@@ -580,13 +598,25 @@ class BxBaseStudioStore extends BxDolStudioStore
                     )
                 ),
                 'bx_if:show_purchase' => array(
-                    'condition' => !$bShoppingCart && !$bFree && !$bPurchased,
+                    'condition' => $bPurchase && !$bInCart,
                     'content' => array(
                         'js_object' => $sJsObject,
                         'id' => $aItem['id'],
                         'vendor' => $aItem['author']
                     )
                 ),
+                'bx_if:show_checkout' => array(
+                    'condition' => $bPurchase,
+                    'content' => array(
+                        'js_object' => $sJsObject,
+                        'id' => $aItem['id'],
+                        'vendor' => $aItem['author'],
+                		'bx_if:show_as_hidden' => array(
+                			'condition' => !$bInCart,
+                			'content' => array()
+                		)
+                    )
+                ),
                 'bx_if:show_download' => array(
                     'condition' => $bDownload && !$bQueued && !$bDownloaded,
                     'content' => array(

+ 6 - 1
studio/template/str_product_v2.html

@@ -21,10 +21,15 @@
 	        </bx_if:show_count_price>
 	        <div class="bx-std-pc-action bx-def-margin-thd-top bx-clearfix">
 	        	<bx_if:show_purchase>
-	            	<button class="bx-btn bx-btn-small bx-std-pc-purchase" type="button" onclick="javascript:__js_object__.addToCart('__vendor__', __id__, this)">
+					<button class="bx-btn bx-btn-small bx-std-pc-purchase" type="button" onclick="javascript:__js_object__.addToCart('__vendor__', __id__, this)">
 	            		<bx_text:_adm_btn_purchase_submit />
 	            	</button>
 	            </bx_if:show_purchase>
+	            <bx_if:show_checkout>
+	           		<button class="bx-btn bx-btn-small bx-std-pc-checkout" type="button" onclick="javascript:__js_object__.checkoutCart('__vendor__', this)" <bx_if:show_as_hidden>style="display:none;"</bx_if:show_as_hidden>>
+	            		<bx_text:_adm_btn_checkout_submit />
+	            	</button>
+	            </bx_if:show_checkout>
 	        	<bx_if:show_download>
 	            	<button class="bx-btn bx-btn-small bx-std-pc-download" type="button" onclick="javascript:__js_object__.getFile(__file_id__, this)">
 	            		<bx_text:_adm_btn_download_submit />

+ 5 - 0
studio/template/str_product_view.html

@@ -80,6 +80,11 @@
 		<bx_if:show_purchase>
 			<input class="bx-btn bx-def-margin-right" type="button" value="<bx_text:_adm_btn_purchase_submit />" onclick="javascript:__js_object__.addToCart('__vendor__', __id__, this)" />
 		</bx_if:show_purchase>
+		<bx_if:show_checkout>
+			<button class="bx-btn bx-def-margin-right" type="button" onclick="javascript:__js_object__.checkoutCart('__vendor__', this)" <bx_if:show_as_hidden>style="display:none;"</bx_if:show_as_hidden>>
+				<bx_text:_adm_btn_checkout_submit />
+			</button>
+		</bx_if:show_checkout>
 		<bx_if:show_download>
 			<input class="bx-btn bx-def-margin-right" type="button" value="<bx_text:_adm_btn_download_submit />" onclick="javascript:__js_object__.getFile(__file_id__, this)" />
 		</bx_if:show_download>