コード例 #1
0
 /**
  * List all addresses for the current frontend user
  * @return void
  */
 protected function show()
 {
     global $objPage;
     $arrAddresses = array();
     $strUrl = $this->generateFrontendUrl($objPage->row()) . ($GLOBALS['TL_CONFIG']['disableAlias'] ? '&' : '?');
     $objAddress = $this->Database->execute("SELECT * FROM tl_iso_addresses WHERE pid={$this->User->id} AND store_id={$this->Isotope->Config->store_id}");
     while ($objAddress->next()) {
         $arrAddresses[] = array_merge($objAddress->row(), array('id' => $objAddress->id, 'class' => ($objAddress->isDefaultBilling ? 'default_billing' : '') . ($objAddress->isDefaultShipping ? ' default_shipping' : ''), 'text' => $this->Isotope->generateAddressString($objAddress->row()), 'edit_url' => ampersand($strUrl . 'act=edit&address=' . $objAddress->id), 'delete_url' => ampersand($strUrl . 'act=delete&address=' . $objAddress->id), 'default_billing' => $objAddress->isDefaultBilling ? true : false, 'default_shipping' => $objAddress->isDefaultShipping ? true : false));
     }
     if (empty($arrAddresses)) {
         $this->Template->mtype = 'empty';
         $this->Template->message = $GLOBALS['TL_LANG']['ERR']['noAddressBookEntries'];
     }
     $this->Template->addNewAddressLabel = $GLOBALS['TL_LANG']['MSC']['createNewAddressLabel'];
     $this->Template->editAddressLabel = $GLOBALS['TL_LANG']['MSC']['editAddressLabel'];
     $this->Template->deleteAddressLabel = $GLOBALS['TL_LANG']['MSC']['deleteAddressLabel'];
     $this->Template->deleteAddressConfirm = specialchars($GLOBALS['TL_LANG']['MSC']['deleteAddressConfirm']);
     $this->Template->addresses = IsotopeFrontend::generateRowClass($arrAddresses, '', 'class', 0, ISO_CLASS_FIRSTLAST | ISO_CLASS_EVENODD);
     $this->Template->addNewAddress = ampersand($strUrl . 'act=create');
 }
コード例 #2
0
 /**
  * Compile product list.
  *
  * This function is specially designed so you can keep it in your child classes and only override findProducts().
  * You will automatically gain product caching (see class property), grid classes, pagination and more.
  * 
  * @return void
  */
 protected function compile()
 {
     $arrProducts = null;
     if ($this->blnCacheProducts) {
         global $objPage;
         $time = time();
         $objCache = $this->Database->prepare("SELECT * FROM tl_iso_productcache\n\t\t\t\t\t\t\t\t\t\t\t\t  WHERE page_id=? AND module_id=? AND requestcache_id=? AND (keywords=? OR keywords='') AND (expires>{$time} OR expires=0)\n\t\t\t\t\t\t\t\t\t\t\t\t  ORDER BY keywords=''")->limit(1)->execute($objPage->id, $this->id, (int) $this->Input->get('isorc'), (string) $this->Input->get('keywords'));
         // Cache found
         if ($objCache->numRows) {
             $arrCacheIds = $objCache->products == '' ? array() : explode(',', $objCache->products);
             // Use the cache if keywords match. Otherwise we will use the product IDs as a "limit" for findProducts()
             if ($objCache->keywords == $this->Input->get('keywords')) {
                 $total = count($arrCacheIds);
                 if ($this->perPage > 0) {
                     $offset = $this->generatePagination($total);
                     $total = $total - $offset;
                     $total = $total > $this->perPage ? $this->perPage : $total;
                     $arrProducts = IsotopeFrontend::getProducts(array_slice($arrCacheIds, $offset, $this->perPage), IsotopeFrontend::getReaderPageId(null, $this->iso_reader_jumpTo));
                 } else {
                     $arrProducts = IsotopeFrontend::getProducts($arrCacheIds, IsotopeFrontend::getReaderPageId(null, $this->iso_reader_jumpTo));
                 }
                 // Cache is wrong, drop everything and run findProducts()
                 if (count($arrProducts) != $total) {
                     $arrCacheIds = null;
                     $arrProducts = null;
                 }
             }
         }
     }
     if (!is_array($arrProducts)) {
         // Display "loading products" message and add cache flag
         if ($this->blnCacheProducts) {
             $blnCacheMessage = (bool) $this->iso_productcache[$objPage->id][(int) $this->Input->get('isorc')];
             if ($blnCacheMessage && !$this->Input->get('buildCache')) {
                 $this->Template = new FrontendTemplate('mod_iso_productlist_caching');
                 $this->Template->message = $GLOBALS['ISO_LANG']['MSC']['productcacheLoading'];
                 return;
             }
             // Start measuring how long it takes to load the products
             $start = microtime(true);
             // Load products
             $arrProducts = $this->findProducts($arrCacheIds);
             // Decide if we should show the "caching products" message the next time
             $end = microtime(true) - $start;
             $this->blnCacheProducts = $end > 1 ? true : false;
             if ($blnCacheMessage != $this->blnCacheProducts) {
                 $arrCacheMessage = $this->iso_productcache;
                 $arrCacheMessage[$objPage->id][(int) $this->Input->get('isorc')] = $this->blnCacheProducts;
                 $this->Database->prepare("UPDATE tl_module SET iso_productcache=? WHERE id=?")->execute(serialize($arrCacheMessage), $this->id);
             }
             // Do not write cache if table is locked. That's the case if another process is already writing cache
             if ($this->Database->query("SHOW OPEN TABLES FROM `{$GLOBALS['TL_CONFIG']['dbDatabase']}` LIKE 'tl_iso_productcache'")->In_use == 0) {
                 $this->Database->lockTables(array('tl_iso_productcache' => 'WRITE', 'tl_iso_products' => 'READ'));
                 $arrIds = array();
                 foreach ($arrProducts as $objProduct) {
                     $arrIds[] = $objProduct->id;
                 }
                 $intExpires = (int) $this->Database->execute("SELECT MIN(start) AS expires FROM tl_iso_products WHERE start>{$time}")->expires;
                 // Also delete all expired caches if we run a delete anyway
                 $this->Database->prepare("DELETE FROM tl_iso_productcache WHERE (page_id=? AND module_id=? AND requestcache_id=? AND keywords=?) OR (expires>0 AND expires<{$time})")->executeUncached($objPage->id, $this->id, (int) $this->Input->get('isorc'), (string) $this->Input->get('keywords'));
                 $this->Database->prepare("INSERT INTO tl_iso_productcache (page_id,module_id,requestcache_id,keywords,products,expires) VALUES (?,?,?,?,?,?)")->executeUncached($objPage->id, $this->id, (int) $this->Input->get('isorc'), (string) $this->Input->get('keywords'), implode(',', $arrIds), $intExpires);
                 $this->Database->unlockTables();
             }
         } else {
             $arrProducts = $this->findProducts();
         }
         if ($this->perPage > 0) {
             $offset = $this->generatePagination(count($arrProducts));
             $arrProducts = array_slice($arrProducts, $offset, $this->perPage);
         }
     }
     // No products found
     if (!is_array($arrProducts) || !count($arrProducts)) {
         $this->Template = new FrontendTemplate('mod_message');
         $this->Template->type = 'empty';
         $this->Template->message = $this->iso_emptyMessage ? $this->iso_noProducts : $GLOBALS['TL_LANG']['MSC']['noProducts'];
         return;
     }
     if ($this->iso_jump_first && $this->Input->get('product') == '') {
         $objProduct = array_shift($arrProducts);
         $this->redirect($objProduct->href_reader);
     }
     $arrBuffer = array();
     foreach ($arrProducts as $objProduct) {
         $arrBuffer[] = array('html' => $objProduct->generate(strlen($this->iso_list_layout) ? $this->iso_list_layout : $objProduct->list_template, $this));
     }
     $this->Template->products = IsotopeFrontend::generateRowClass($arrBuffer, 'product', 'class', $this->iso_cols);
 }
コード例 #3
0
ファイル: IsotopeProduct.php プロジェクト: rikaix/core-1
 /**
  * Generate a product template
  * @param string
  * @param object
  * @return string
  */
 public function generate($strTemplate, &$objModule)
 {
     global $objPage;
     $this->formSubmit = ($objModule instanceof ContentElement ? 'cte' : 'fmd') . $objModule->id . '_product_' . ($this->pid ? $this->pid : $this->id);
     $this->validateVariant();
     $objTemplate = new IsotopeTemplate($strTemplate);
     $arrProductOptions = array();
     $arrAjaxOptions = array();
     $arrAttributes = $this->getAttributes();
     foreach ($arrAttributes as $attribute => $varValue) {
         if ($GLOBALS['TL_DCA']['tl_iso_products']['fields'][$attribute]['attributes']['customer_defined'] || $GLOBALS['TL_DCA']['tl_iso_products']['fields'][$attribute]['attributes']['variant_option']) {
             $objTemplate->hasOptions = true;
             $arrProductOptions[$attribute] = array_merge($GLOBALS['TL_DCA']['tl_iso_products']['fields'][$attribute], array('name' => $attribute, 'html' => $this->generateProductOptionWidget($attribute)));
             if ($GLOBALS['TL_DCA']['tl_iso_products']['fields'][$attribute]['attributes']['variant_option']) {
                 $arrAjaxOptions[] = $attribute;
             }
         } else {
             $objTemplate->{$attribute} = $this->generateAttribute($attribute, $varValue);
         }
     }
     $arrButtons = array();
     // Buttons
     if (isset($GLOBALS['ISO_HOOKS']['buttons']) && is_array($GLOBALS['ISO_HOOKS']['buttons'])) {
         foreach ($GLOBALS['ISO_HOOKS']['buttons'] as $callback) {
             $this->import($callback[0]);
             $arrButtons = $this->{$callback}[0]->{$callback}[1]($arrButtons);
         }
         $arrButtons = array_intersect_key($arrButtons, array_flip(deserialize($objModule->iso_buttons, true)));
     }
     if ($this->Input->post('FORM_SUBMIT') == $this->formSubmit && !$this->doNotSubmit) {
         foreach ($arrButtons as $button => $data) {
             if (strlen($this->Input->post($button))) {
                 if (is_array($data['callback']) && count($data['callback']) == 2) {
                     $this->import($data['callback'][0]);
                     $this->{$data['callback'][0]}->{$data['callback'][1]}($this, $objModule);
                 }
                 break;
             }
         }
     }
     $objTemplate->buttons = $arrButtons;
     $objTemplate->quantityLabel = $GLOBALS['TL_LANG']['MSC']['quantity'];
     $objTemplate->useQuantity = $objModule->iso_use_quantity;
     $objTemplate->quantity_requested = $this->quantity_requested;
     $objTemplate->raw = array_merge($this->arrData, $this->arrCache);
     $objTemplate->raw_options = $this->arrOptions;
     $objTemplate->href_reader = $this->href_reader;
     $objTemplate->label_detail = $GLOBALS['TL_LANG']['MSC']['detailLabel'];
     $objTemplate->options = IsotopeFrontend::generateRowClass($arrProductOptions, 'product_option');
     $objTemplate->hasOptions = count($arrProductOptions) > 0 ? true : false;
     $objTemplate->enctype = $this->hasUpload ? 'multipart/form-data' : 'application/x-www-form-urlencoded';
     $objTemplate->formId = $this->formSubmit;
     $objTemplate->action = ampersand($this->Environment->request, true);
     $objTemplate->formSubmit = $this->formSubmit;
     list(, $startScript, $endScript) = IsotopeFrontend::getElementAndScriptTags();
     $GLOBALS['TL_MOOTOOLS'][] = $startScript . "\nnew {$this->ajaxClass}('{$objModule->id}', '" . ($this->pid ? $this->pid : $this->id) . "', '{$this->formSubmit}', ['ctrl_" . implode("_" . $this->formSubmit . "', 'ctrl_", $arrAjaxOptions) . "_" . $this->formSubmit . "'], {language: '{$GLOBALS['TL_LANGUAGE']}', action: '" . ($objModule instanceof Module ? 'fmd' : 'cte') . "', page: {$objPage->id}, loadMessage:'" . specialchars($GLOBALS['ISO_LANG']['MSC']['loadingProductData']) . "'});\n" . $endScript;
     // HOOK for altering product data before output
     if (isset($GLOBALS['ISO_HOOKS']['generateProduct']) && is_array($GLOBALS['ISO_HOOKS']['generateProduct'])) {
         foreach ($GLOBALS['ISO_HOOKS']['generateProduct'] as $callback) {
             $this->import($callback[0]);
             $objTemplate = $this->{$callback}[0]->{$callback}[1]($objTemplate, $this);
         }
     }
     return $objTemplate->parse();
 }
コード例 #4
0
ファイル: ModuleIsotopeCart.php プロジェクト: rikaix/core-1
 /**
  * Generate module
  * @return void
  */
 protected function compile()
 {
     $arrProducts = $this->Isotope->Cart->getProducts();
     if (!count($arrProducts)) {
         $this->Template->empty = true;
         $this->Template->message = $this->iso_emptyMessage ? $this->iso_noProducts : $GLOBALS['TL_LANG']['MSC']['noItemsInCart'];
         return;
     }
     $objTemplate = new IsotopeTemplate($this->iso_cart_layout);
     global $objPage;
     $strUrl = $this->generateFrontendUrl($objPage->row());
     $blnReload = false;
     $arrQuantity = $this->Input->post('quantity');
     $arrProductData = array();
     // Surcharges must be initialized before getProducts() to apply tax_id to each product
     $arrSurcharges = $this->Isotope->Cart->getSurcharges();
     $arrProducts = $this->Isotope->Cart->getProducts();
     $lastAdded = $this->iso_continueShopping && count($_SESSION['ISO_CONFIRM']) ? $this->Isotope->Cart->lastAdded : 0;
     foreach ($arrProducts as $i => $objProduct) {
         // Remove product from cart
         if ($this->Input->get('remove') == $objProduct->cart_id && $this->Isotope->Cart->deleteProduct($objProduct)) {
             $this->redirect(strlen($this->Input->get('referer')) ? base64_decode($this->Input->get('referer', true)) : $strUrl);
         } elseif ($this->Input->post('FORM_SUBMIT') == 'iso_cart_update_' . $this->id && is_array($arrQuantity)) {
             $blnReload = true;
             $this->Isotope->Cart->updateProduct($objProduct, array('product_quantity' => $arrQuantity[$objProduct->cart_id]));
             continue;
             // no need to generate $arrProductData, we reload anyway
         }
         $arrProductData[] = array_merge($objProduct->getAttributes(), array('id' => $objProduct->id, 'image' => $objProduct->images->main_image, 'link' => $objProduct->href_reader, 'original_price' => $this->Isotope->formatPriceWithCurrency($objProduct->original_price), 'price' => $this->Isotope->formatPriceWithCurrency($objProduct->price), 'total_price' => $this->Isotope->formatPriceWithCurrency($objProduct->total_price), 'tax_id' => $objProduct->tax_id, 'quantity' => $objProduct->quantity_requested, 'cart_item_id' => $objProduct->cart_id, 'product_options' => $objProduct->getOptions(), 'remove_link' => ampersand($strUrl . ($GLOBALS['TL_CONFIG']['disableAlias'] ? '&' : '?') . 'remove=' . $objProduct->cart_id . '&referer=' . base64_encode($this->Environment->request)), 'remove_link_text' => $GLOBALS['TL_LANG']['MSC']['removeProductLinkText'], 'remove_link_title' => specialchars(sprintf($GLOBALS['TL_LANG']['MSC']['removeProductLinkTitle'], $objProduct->name))));
         if ($lastAdded == $objProduct->cart_id) {
             $objTemplate->continueJumpTo = $objProduct->href_reader;
         }
     }
     $blnInsufficientSubtotal = $this->Isotope->Config->cartMinSubtotal > 0 && $this->Isotope->Config->cartMinSubtotal > $this->Isotope->Cart->subTotal ? true : false;
     // Redirect if the "checkout" button has been submitted and minimum order total is reached
     if ($blnReload && $this->Input->post('checkout') != '' && $this->iso_checkout_jumpTo && !$blnInsufficientSubtotal) {
         $this->redirect($this->generateFrontendUrl($this->Database->execute("SELECT * FROM tl_page WHERE id={$this->iso_checkout_jumpTo}")->fetchAssoc()));
     } elseif ($blnReload) {
         $this->reload();
     }
     // HOOK for adding additional forms into the template
     if (isset($GLOBALS['ISO_HOOKS']['compileCart']) && is_array($GLOBALS['ISO_HOOKS']['compileCart'])) {
         foreach ($GLOBALS['ISO_HOOKS']['compileCart'] as $name => $callback) {
             $this->import($callback[0]);
             $strForm = $this->{$callback}[0]->{$callback}[1]($this, $objTemplate, $arrProductData, $arrSurcharges);
             if ($strForm !== false) {
                 $arrForms[$name] = $strForm;
             }
         }
     }
     $objTemplate->hasError = $blnInsufficientSubtotal ? true : false;
     $objTemplate->minSubtotalError = sprintf($GLOBALS['TL_LANG']['ERR']['cartMinSubtotal'], $this->Isotope->formatPriceWithCurrency($this->Isotope->Config->cartMinSubtotal));
     $objTemplate->formId = 'iso_cart_update_' . $this->id;
     $objTemplate->formSubmit = 'iso_cart_update_' . $this->id;
     $objTemplate->summary = $GLOBALS['ISO_LANG']['MSC']['cartSummary'];
     $objTemplate->action = $this->Environment->request;
     $objTemplate->products = IsotopeFrontend::generateRowClass($arrProductData, 'row', 'rowClass', 0, ISO_CLASS_COUNT | ISO_CLASS_FIRSTLAST | ISO_CLASS_EVENODD);
     $objTemplate->cartJumpTo = $this->iso_cart_jumpTo ? $this->generateFrontendUrl($this->Database->execute("SELECT * FROM tl_page WHERE id={$this->iso_cart_jumpTo}")->fetchAssoc()) : '';
     $objTemplate->cartLabel = $GLOBALS['TL_LANG']['MSC']['cartBT'];
     $objTemplate->checkoutJumpToLabel = $GLOBALS['TL_LANG']['MSC']['checkoutBT'];
     $objTemplate->checkoutJumpTo = $this->iso_checkout_jumpTo && !$blnInsufficientSubtotal ? $this->generateFrontendUrl($this->Database->execute("SELECT * FROM tl_page WHERE id={$this->iso_checkout_jumpTo}")->fetchAssoc()) : '';
     $objTemplate->continueLabel = $GLOBALS['TL_LANG']['MSC']['continueShoppingBT'];
     $objTemplate->subTotalLabel = $GLOBALS['TL_LANG']['MSC']['subTotalLabel'];
     $objTemplate->grandTotalLabel = $GLOBALS['TL_LANG']['MSC']['grandTotalLabel'];
     $objTemplate->subTotalPrice = $this->Isotope->formatPriceWithCurrency($this->Isotope->Cart->subTotal);
     $objTemplate->grandTotalPrice = $this->Isotope->formatPriceWithCurrency($this->Isotope->Cart->grandTotal);
     // @todo make a module option.
     $objTemplate->showOptions = false;
     $objTemplate->surcharges = IsotopeFrontend::formatSurcharges($arrSurcharges);
     $objTemplate->forms = $arrForms;
     $this->Template->empty = false;
     $this->Template->cart = $objTemplate->parse();
 }
コード例 #5
0
 /**
  * Generate the module
  * @return void
  */
 protected function compile()
 {
     $objOrder = new IsotopeOrder();
     if (!$objOrder->findBy('uniqid', $this->Input->get('uid'))) {
         $this->Template = new FrontendTemplate('mod_message');
         $this->Template->type = 'error';
         $this->Template->message = $GLOBALS['TL_LANG']['ERR']['orderNotFound'];
         return;
     }
     $arrOrder = $objOrder->getData();
     $this->Template->setData($arrOrder);
     $this->import('Isotope');
     $this->Isotope->overrideConfig($objOrder->config_id);
     // Article reader
     $arrPage = $this->Database->prepare("SELECT * FROM tl_page WHERE id=?")->limit(1)->execute($this->jumpTo)->fetchAssoc();
     $arrAllDownloads = array();
     $arrItems = array();
     $arrProducts = $objOrder->getProducts();
     foreach ($arrProducts as $i => $objProduct) {
         $arrDownloads = array();
         $objDownloads = $this->Database->prepare("SELECT p.*, o.* FROM tl_iso_order_downloads o LEFT OUTER JOIN tl_iso_downloads p ON o.download_id=p.id WHERE o.pid=?")->execute($objProduct->cart_id);
         while ($objDownloads->next()) {
             $blnDownloadable = ($objOrder->status == 'complete' || intval($objOrder->date_paid) > 0 && intval($objOrder->date_paid) <= time()) && ($objDownloads->downloads_remaining === '' || $objDownloads->downloads_remaining > 0) ? true : false;
             // Send file to the browser
             if (strlen($this->Input->get('file')) && $this->Input->get('file') == $objDownloads->id && $blnDownloadable) {
                 if (!$this->backend && $objDownloads->downloads_remaining !== '') {
                     $this->Database->prepare("UPDATE tl_iso_order_downloads SET downloads_remaining=? WHERE id=?")->execute($objDownloads->downloads_remaining - 1, $objDownloads->id);
                 }
                 $this->sendFileToBrowser($objDownloads->singleSRC);
             }
             $arrDownload = array('raw' => $objDownloads->row(), 'title' => $objDownloads->title, 'href' => TL_MODE == 'FE' ? IsotopeFrontend::addQueryStringToUrl('file=' . $objDownloads->id) : '', 'remaining' => $objDownloads->downloads_allowed > 0 ? sprintf($GLOBALS['TL_LANG']['MSC']['downloadsRemaining'], intval($objDownloads->downloads_remaining)) : '', 'downloadable' => $blnDownloadable);
             $arrDownloads[] = $arrDownload;
             $arrAllDownloads[] = $arrDownload;
         }
         $arrItems[] = array('raw' => $objProduct->getData(), 'sku' => $objProduct->sku, 'name' => $objProduct->name, 'image' => $objProduct->images->main_image, 'product_options' => $objProduct->getOptions(), 'quantity' => $objProduct->quantity_requested, 'price' => $this->Isotope->formatPriceWithCurrency($objProduct->price), 'total' => $this->Isotope->formatPriceWithCurrency($objProduct->total_price), 'href' => $this->jumpTo ? $this->generateFrontendUrl($arrPage, '/product/' . $objProduct->alias) : '', 'tax_id' => $objProduct->tax_id, 'downloads' => $arrDownloads);
     }
     $this->Template->info = deserialize($objOrder->checkout_info, true);
     $this->Template->items = IsotopeFrontend::generateRowClass($arrItems, 'row', 'rowClass', 0, ISO_CLASS_COUNT | ISO_CLASS_FIRSTLAST | ISO_CLASS_EVENODD);
     $this->Template->downloads = $arrAllDownloads;
     $this->Template->downloadsLabel = $GLOBALS['TL_LANG']['MSC']['downloadsLabel'];
     $this->Template->raw = $arrOrder;
     $this->Template->date = $this->parseDate($GLOBALS['TL_CONFIG']['dateFormat'], $objOrder->date);
     $this->Template->time = $this->parseDate($GLOBALS['TL_CONFIG']['timeFormat'], $objOrder->date);
     $this->Template->datim = $this->parseDate($GLOBALS['TL_CONFIG']['datimFormat'], $objOrder->date);
     $this->Template->orderDetailsHeadline = sprintf($GLOBALS['TL_LANG']['MSC']['orderDetailsHeadline'], $objOrder->order_id, $this->Template->datim);
     $this->Template->orderStatus = sprintf($GLOBALS['TL_LANG']['MSC']['orderStatusHeadline'], $GLOBALS['TL_LANG']['ORDER'][$objOrder->status]);
     $this->Template->orderStatusKey = $objOrder->status;
     $this->Template->subTotalPrice = $this->Isotope->formatPriceWithCurrency($objOrder->subTotal);
     $this->Template->grandTotal = $this->Isotope->formatPriceWithCurrency($objOrder->grandTotal);
     $this->Template->subTotalLabel = $GLOBALS['TL_LANG']['MSC']['subTotalLabel'];
     $this->Template->grandTotalLabel = $GLOBALS['TL_LANG']['MSC']['grandTotalLabel'];
     $this->Template->surcharges = IsotopeFrontend::formatSurcharges($objOrder->getSurcharges());
     $this->Template->billing_label = $GLOBALS['TL_LANG']['ISO']['billing_address'];
     $this->Template->billing_address = $this->Isotope->generateAddressString($objOrder->billing_address, $this->Isotope->Config->billing_fields);
     if (strlen($objOrder->shipping_method)) {
         $arrShippingAddress = $objOrder->shipping_address;
         if (!is_array($arrShippingAddress) || $arrShippingAddress['id'] == -1) {
             $this->Template->has_shipping = false;
             $this->Template->billing_label = $GLOBALS['TL_LANG']['ISO']['billing_shipping_address'];
         } else {
             $this->Template->has_shipping = true;
             $this->Template->shipping_label = $GLOBALS['TL_LANG']['ISO']['shipping_address'];
             $this->Template->shipping_address = $this->Isotope->generateAddressString($arrShippingAddress, $this->Isotope->Config->shipping_fields);
         }
     }
 }
コード例 #6
0
    /**
     * Generate the current step widgets.
     * strResourceTable is used either to load a DCA or else to gather settings related to a given DCA.
     *
     * @todo <table...> was in a template, but I don't get why we need to define the table here?
     * @param string
     * @param integer
     * @return string
     */
    protected function generateAddressWidgets($strAddressType, $intOptions)
    {
        $arrWidgets = array();
        $this->loadLanguageFile('tl_iso_addresses');
        $this->loadDataContainer('tl_iso_addresses');
        $arrFields = $strAddressType == 'billing_address' ? $this->Isotope->Config->billing_fields : $this->Isotope->Config->shipping_fields;
        $arrDefault = $this->Isotope->Cart->{$strAddressType};
        if ($arrDefault['id'] == -1) {
            $arrDefault = array();
        }
        foreach ($arrFields as $field) {
            $arrData = $GLOBALS['TL_DCA']['tl_iso_addresses']['fields'][$field['value']];
            if (!is_array($arrData) || !$arrData['eval']['feEditable'] || !$field['enabled'] || $arrData['eval']['membersOnly'] && FE_USER_LOGGED_IN !== true) {
                continue;
            }
            $strClass = $GLOBALS['TL_FFL'][$arrData['inputType']];
            // Continue if the class is not defined
            if (!$this->classFileExists($strClass)) {
                continue;
            }
            // Special field "country"
            if ($field['value'] == 'country') {
                $arrCountries = $strAddressType == 'billing_address' ? $this->Isotope->Config->billing_countries : $this->Isotope->Config->shipping_countries;
                $arrData['options'] = array_values(array_intersect($arrData['options'], $arrCountries));
                $arrDefault['country'] = $this->Isotope->Config->country;
            } elseif (strlen($arrData['eval']['conditionField'])) {
                $arrData['eval']['conditionField'] = $strAddressType . '_' . $arrData['eval']['conditionField'];
            } elseif ($field['value'] == 'isDefaultBilling' && $strAddressType == 'billing_address' && $intOptions < 2 || $field['value'] == 'isDefaultShipping' && $strAddressType == 'shipping_address' && $intOptions < 3) {
                $arrDefault[$field['value']] = '1';
            }
            $objWidget = new $strClass($this->prepareForWidget($arrData, $strAddressType . '_' . $field['value'], strlen($_SESSION['CHECKOUT_DATA'][$strAddressType][$field['value']]) ? $_SESSION['CHECKOUT_DATA'][$strAddressType][$field['value']] : $arrDefault[$field['value']]));
            $objWidget->mandatory = $field['mandatory'] ? true : false;
            $objWidget->required = $objWidget->mandatory;
            $objWidget->tableless = $this->tableless;
            $objWidget->label = $field['label'] ? $this->Isotope->translate($field['label']) : $objWidget->label;
            $objWidget->storeValues = true;
            // Validate input
            if ($this->Input->post('FORM_SUBMIT') == $this->strFormId && ($this->Input->post($strAddressType) === '0' || $this->Input->post($strAddressType) == '')) {
                $objWidget->validate();
                $varValue = $objWidget->value;
                // Convert date formats into timestamps
                if (strlen($varValue) && in_array($arrData['eval']['rgxp'], array('date', 'time', 'datim'))) {
                    $objDate = new Date($varValue, $GLOBALS['TL_CONFIG'][$arrData['eval']['rgxp'] . 'Format']);
                    $varValue = $objDate->tstamp;
                }
                // Do not submit if there are errors
                if ($objWidget->hasErrors()) {
                    $this->doNotSubmit = true;
                } elseif ($objWidget->submitInput()) {
                    $arrAddress[$field['value']] = $varValue;
                }
            } elseif ($this->Input->post($strAddressType) === '0' || $this->Input->post($strAddressType) == '') {
                $this->Input->setPost($objWidget->name, $objWidget->value);
                $objValidator = clone $objWidget;
                $objValidator->validate();
                if ($objValidator->hasErrors()) {
                    $this->doNotSubmit = true;
                }
            }
            $arrWidgets[] = $objWidget;
        }
        $arrWidgets = IsotopeFrontend::generateRowClass($arrWidgets, 'row', 'rowClass', 0, ISO_CLASS_COUNT | ISO_CLASS_FIRSTLAST | ISO_CLASS_EVENODD);
        // Validate input
        if ($this->Input->post('FORM_SUBMIT') == $this->strFormId && !$this->doNotSubmit && is_array($arrAddress) && count($arrAddress)) {
            $arrAddress['id'] = 0;
            $_SESSION['CHECKOUT_DATA'][$strAddressType] = $arrAddress;
        }
        if (is_array($_SESSION['CHECKOUT_DATA'][$strAddressType]) && $_SESSION['CHECKOUT_DATA'][$strAddressType]['id'] === 0) {
            $this->Isotope->Cart->{$strAddressType} = $_SESSION['CHECKOUT_DATA'][$strAddressType];
        }
        $strBuffer = '';
        foreach ($arrWidgets as $objWidget) {
            $strBuffer .= $objWidget->parse();
        }
        if ($this->tableless) {
            return $strBuffer;
        }
        return '
<table>
' . $strBuffer . '
</table>';
    }