protected function displayProducts($mixedItems, $aParams = array()) { if (!is_array($mixedItems)) { return MsgBox($mixedItems); } $sJsObject = $this->getPageJsObject(); $oTemplate = BxDolStudioTemplate::getInstance(); $aDownloaded = $this->getDownloadedModules(); $bShoppingCart = isset($aParams['is_shopping_cart']) && $aParams['is_shopping_cart']; $sResult = ''; foreach ($mixedItems 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); $bDownload = !$bShoppingCart && ($bFree || $bPurchased) && $bDownloadable; $bQueued = $this->oDb->isQueued('download', $aItem['name']); $sPrice = !$bFree ? _t('_adm_str_txt_price_csign', $aItem['currency_sign'], $aItem['price']) : _t('_adm_str_txt_price_free'); $sDiscount = !$bFree && !empty($aItem['discount']) ? _t('_adm_str_txt_discount_csign', $aItem['currency_sign'], $aItem['discount']['price']) : ''; $sIcon = !empty($aItem['thumbnail']['big']) ? $aItem['thumbnail']['big'] : BxDolStudioUtils::getIconDefault(BX_DOL_MODULE_TYPE_MODULE); $bIcon = strpos($sIcon, '.') === false; $sResult .= $oTemplate->parseHtmlByName('str_product_v2.html', array('js_object' => $sJsObject, 'id' => $aItem['id'], 'name' => $aItem['name'], 'url' => $aItem['url'], 'bx_if:icon' => array('condition' => $bIcon, 'content' => array('icon' => $sIcon)), 'bx_if:image' => array('condition' => !$bIcon, 'content' => array('icon_url' => $sIcon)), 'title' => $aItem['title'], 'bx_if:show_vendor_price' => array('condition' => !$bShoppingCart, 'content' => array('vendor' => $aItem['author'], 'price' => $sPrice, 'discount' => $sDiscount)), 'bx_if:show_count_price' => array('condition' => $bShoppingCart, 'content' => array('count' => isset($aParams['counts'][$aItem['id']]) ? (int) $aParams['counts'][$aItem['id']] : 1, 'price' => $sPrice, 'discount' => $sDiscount)), 'bx_if:show_purchase' => array('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('js_object' => $sJsObject, 'file_id' => $aItem['file_id'])), 'bx_if:show_download_disabled' => array('condition' => $bDownload && !$bQueued && $bDownloaded, 'content' => array()), 'bx_if:show_queued_disabled' => array('condition' => $bDownload && $bQueued && !$bDownloaded, 'content' => array()), 'bx_if:show_delete' => array('condition' => $bShoppingCart, 'content' => array('js_object' => $sJsObject, 'id' => $aItem['id'], 'vendor' => $aItem['author'])))); } return $sResult; }
protected function getCheckoutList() { $sJsObject = $this->getPageJsObject(); $oTemplate = BxDolStudioTemplate::getInstance(); //--- Empty cart by vendor if the payment was accepted. $mixedVendor = bx_get('vendor'); $mixedProducts = bx_get('products'); if ($mixedVendor !== false && $mixedProducts !== false) { bx_import('BxDolStudioCart'); $oCart = BxDolStudioCart::getInstance(); $aProducts = explode(',', base64_decode($mixedProducts)); foreach ($aProducts as $iId) { $oCart->delete($mixedVendor, $iId); } return $this->getMessage('_adm_block_cpt_checkout', '_adm_msg_modules_success_checkouted'); } $aVendors = $this->loadCheckout(); $aTmplVarsBlocks = array(); foreach ($aVendors as $sName => $aInfo) { $fTotal = 0; $sCurrency = ''; foreach ($aInfo['products'] as $aProduct) { $iCount = isset($aInfo['counts'][$aProduct['id']]) ? (int) $aInfo['counts'][$aProduct['id']] : 1; $fTotal += $iCount * $aProduct['price']; if ($sCurrency == '' && isset($aProduct['currency_sign'])) { $sCurrency = $aProduct['currency_sign']; } } $aActions = array(array('name' => 'checkout-' . $sName, 'caption' => '_adm_action_cpt_checkout', 'url' => 'javascript:void(0)', 'onclick' => $sJsObject . ".checkoutCart('" . $sName . "', this);"), array('name' => 'delete-all-' . $sName, 'caption' => '_adm_action_cpt_delete_all', 'url' => 'javascript:void(0)', 'onclick' => $sJsObject . ".deleteAllFromCart('" . $sName . "', this)")); $aTmplVarsBlocks[] = array('caption' => $this->getBlockCaption(array('caption' => _t('_adm_block_cpt_checkout_by_vendor_csign', $sName, $sCurrency, $fTotal), 'actions' => $aActions)), 'panel_top' => '', 'items' => $this->displayProducts($aInfo['products'], array('is_shopping_cart' => true, 'counts' => $aInfo['counts'])), 'panel_bottom' => ''); } if (empty($aTmplVarsBlocks)) { return $this->getMessage('_adm_block_cpt_checkout', '_Empty'); } return $oTemplate->parseHtmlByName('store.html', array('js_object' => $sJsObject, 'bx_repeat:blocks' => $aTmplVarsBlocks)); }
private function checkoutCart($sVendor) { bx_import('BxDolStudioCart'); $oCart = BxDolStudioCart::getInstance(); $aItems = $oCart->getByVendor($sVendor); if (empty($aItems) || !is_array($aItems)) { return false; } $aIds = array(); foreach ($aItems as $aItem) { $aIds[] = $aItem['item_id']; } $sSid = bx_site_hash(); return BX_DOL_UNITY_URL_MARKET . 'purchase/' . $sVendor . '?sid=' . $sSid . '&products=' . base64_encode(implode(',', $aIds)); }