Пример #1
0
 /**
  * Creates a PDF document and sends this pricelist to the client
  *
  * Unfortunately, ezpdf does not return anything after printing the
  * document, so there's no way to tell whether it has succeeded.
  * Thus, you should not rely on the return value, except when it is
  * false -- in that case, loading of some data failed.
  * @return  boolean           False on failure, true on supposed success
  */
 function send_as_pdf()
 {
     global $objInit, $_ARRAYLANG;
     if (!$this->load()) {
         return \Message::error($_ARRAYLANG['TXT_SHOP_PRICELIST_ERROR_LOADING']);
     }
     $objPdf = new \Cezpdf('A4');
     $objPdf->setEncryption('', '', array('print'));
     $objPdf->selectFont(\Cx\Core\Core\Controller\Cx::instanciate()->getCodeBaseLibraryPath() . '/ezpdf/fonts/' . $this->font);
     $objPdf->ezSetMargins(0, 0, 0, 0);
     // Reset margins
     $objPdf->setLineStyle(0.5);
     $marginTop = 30;
     $biggerCountTop = $biggerCountBottom = 0;
     $arrHeaderLeft = $arrHeaderRight = $arrFooterLeft = $arrFooterRight = array();
     if ($this->header) {
         // header should be shown
         $arrHeaderLeft = explode("\n", $this->header_left);
         $arrHeaderRight = explode("\n", $this->header_right);
         $countLeft = count($arrHeaderLeft);
         $countRight = count($arrHeaderRight);
         $biggerCountTop = $countLeft > $countRight ? $countLeft : $countRight;
         $marginTop = $biggerCountTop * 14 + 36;
     }
     // Bottom margin
     $marginBottom = 20;
     $arrFooterRight = array();
     if ($this->footer) {
         // footer should be shown
         // Old, obsolete:
         $this->footer_left = str_replace('<--DATE-->', date(ASCMS_DATE_FORMAT_DATE, time()), $this->footer_left);
         $this->footer_right = str_replace('<--DATE-->', date(ASCMS_DATE_FORMAT_DATE, time()), $this->footer_right);
         // New:
         $this->footer_left = str_replace('[DATE]', date(ASCMS_DATE_FORMAT_DATE, time()), $this->footer_left);
         $this->footer_right = str_replace('[DATE]', date(ASCMS_DATE_FORMAT_DATE, time()), $this->footer_right);
         $arrFooterLeft = explode("\n", $this->footer_left);
         $arrFooterRight = explode("\n", $this->footer_right);
         $countLeft = count($arrFooterLeft);
         $countRight = count($arrFooterRight);
         $biggerCountBottom = $countLeft > $countRight ? $countLeft : $countRight;
         $marginBottom = $biggerCountBottom * 20 + 20;
     }
     // Borders
     if ($this->border) {
         $linesForAllPages = $objPdf->openObject();
         $objPdf->saveState();
         $objPdf->setStrokeColor(0, 0, 0, 1);
         $objPdf->rectangle(10, 10, 575.28, 821.89);
         $objPdf->restoreState();
         $objPdf->closeObject();
         $objPdf->addObject($linesForAllPages, 'all');
     }
     // Header
     $headerArray = array();
     $startpointY = 0;
     if ($this->header) {
         $objPdf->ezSetY(830);
         $headerForAllPages = $objPdf->openObject();
         $objPdf->saveState();
         for ($i = 0; $i < $biggerCountTop; ++$i) {
             $headerArray[$i] = array('left' => isset($arrHeaderLeft[$i]) ? $arrHeaderLeft[$i] : '', 'right' => isset($arrHeaderRight[$i]) ? $arrHeaderRight[$i] : '');
         }
         $tempY = $objPdf->ezTable($headerArray, '', '', array('showHeadings' => 0, 'fontSize' => $this->font_size_header, 'shaded' => 0, 'width' => 540, 'showLines' => 0, 'xPos' => 'center', 'xOrientation' => 'center', 'cols' => array('right' => array('justification' => 'right'))));
         $tempY -= 5;
         if ($this->border) {
             $objPdf->setStrokeColor(0, 0, 0);
             $objPdf->line(10, $tempY, 585.28, $tempY);
         }
         $startpointY = $tempY - 5;
         $objPdf->restoreState();
         $objPdf->closeObject();
         $objPdf->addObject($headerForAllPages, 'all');
     }
     // Footer
     $pageNumbersX = $pageNumbersY = $pageNumbersFont = 0;
     if ($this->footer) {
         $footerForAllPages = $objPdf->openObject();
         $objPdf->saveState();
         $tempY = $marginBottom - 5;
         if ($this->border) {
             $objPdf->setStrokeColor(0, 0, 0);
             $objPdf->line(10, $tempY, 585.28, $tempY);
         }
         // length of the longest word
         $longestWord = 0;
         foreach ($arrFooterRight as $line) {
             if ($longestWord < strlen($line)) {
                 $longestWord = strlen($line);
             }
         }
         for ($i = $biggerCountBottom - 1; $i >= 0; --$i) {
             if (empty($arrFooterLeft[$i])) {
                 $arrFooterLeft[$i] = '';
             }
             if (empty($arrFooterRight[$i])) {
                 $arrFooterRight[$i] = '';
             }
             if ($arrFooterLeft[$i] == '<--PAGENUMBER-->' || $arrFooterLeft[$i] == '[PAGENUMBER]') {
                 $pageNumbersX = 65;
                 $pageNumbersY = $tempY - 18 - $i * $this->font_size_footer;
                 $pageNumbersFont = $this->font_size_list;
             } else {
                 $objPdf->addText(25, $tempY - 18 - $i * $this->font_size_footer, $this->font_size_footer, $arrFooterLeft[$i]);
             }
             if ($arrFooterRight[$i] == '<--PAGENUMBER-->' || $arrFooterRight[$i] == '[PAGENUMBER]') {
                 $pageNumbersX = 595.28 - 25;
                 $pageNumbersY = $tempY - 18 - $i * $this->font_size_footer;
                 $pageNumbersFont = $this->font_size_list;
             } else {
                 // Properly align right
                 $width = $objPdf->getTextWidth($this->font_size_footer, $arrFooterRight[$i]);
                 $objPdf->addText(595.28 - $width - 25, $tempY - 18 - $i * $this->font_size_footer, $this->font_size_footer, $arrFooterRight[$i]);
             }
         }
         $objPdf->restoreState();
         $objPdf->closeObject();
         $objPdf->addObject($footerForAllPages, 'all');
     }
     // Page numbers
     if (isset($pageNumbersX)) {
         $objPdf->ezStartPageNumbers($pageNumbersX, $pageNumbersY, $pageNumbersFont, '', $_ARRAYLANG['TXT_SHOP_PRICELIST_FORMAT_PAGENUMBER'], 1);
     }
     // Margins
     $objPdf->ezSetMargins($marginTop, $marginBottom, 30, 30);
     // Product table
     if (isset($startpointY)) {
         $objPdf->ezSetY($startpointY);
     }
     $objInit->backendLangId = $this->lang_id;
     $_ARRAYLANG = $objInit->loadLanguageData('Shop');
     Currency::setActiveCurrencyId($this->currency_id);
     $currency_symbol = Currency::getActiveCurrencySymbol();
     $category_ids = $this->category_ids();
     if ($category_ids == '*') {
         $category_ids = null;
     }
     $count = 1000;
     // Be sensible!
     // Pattern is "%" because all-empty parameters will result in an
     // empty array!
     $arrProduct = Products::getByShopParams($count, 0, null, $category_ids, null, '%', null, null, '`category_id` ASC, `name` ASC');
     $arrCategoryName = ShopCategories::getNameArray();
     $arrOutput = array();
     foreach ($arrProduct as $product_id => $objProduct) {
         $categoryIds = explode(',', $objProduct->category_id());
         $arrCategoryNames = array();
         foreach ($categoryIds as $categoryId) {
             $arrCategoryNames[] = $arrCategoryName[$categoryId];
         }
         //$objProduct = new Product();
         $arrOutput[$product_id] = array('product_name' => self::decode($objProduct->name()), 'category_name' => self::decode(implode(', ', $arrCategoryNames)), 'product_code' => self::decode($objProduct->code()), 'product_id' => self::decode($objProduct->id()), 'price' => ($objProduct->discount_active() ? "S " . Currency::formatPrice($objProduct->discountprice()) : Currency::formatPrice($objProduct->price())) . ' ' . $currency_symbol);
     }
     $objPdf->ezTable($arrOutput, array('product_name' => '<b>' . self::decode($_ARRAYLANG['TXT_SHOP_PRODUCT_NAME']) . '</b>', 'category_name' => '<b>' . self::decode($_ARRAYLANG['TXT_SHOP_CATEGORY_NAME']) . '</b>', 'product_code' => '<b>' . self::decode($_ARRAYLANG['TXT_SHOP_PRODUCT_CODE']) . '</b>', 'product_id' => '<b>' . self::decode($_ARRAYLANG['TXT_ID']) . '</b>', 'price' => '<b>' . self::decode($_ARRAYLANG['TXT_SHOP_PRICE']) . '</b>'), '', array('showHeadings' => 1, 'fontSize' => $this->font_size_list, 'width' => 530, 'innerLineThickness' => 0.5, 'outerLineThickness' => 0.5, 'shaded' => 2, 'shadeCol' => array(hexdec(substr($this->row_color_1, 0, 2)) / 255, hexdec(substr($this->row_color_1, 2, 2)) / 255, hexdec(substr($this->row_color_1, 4, 2)) / 255), 'shadeCol2' => array(hexdec(substr($this->row_color_2, 0, 2)) / 255, hexdec(substr($this->row_color_2, 2, 2)) / 255, hexdec(substr($this->row_color_2, 4, 2)) / 255), 'cols' => array('product_name' => array('width' => 255), 'category_name' => array('width' => 130), 'product_code' => array('width' => 50), 'product_id' => array('width' => 40, 'justification' => 'right'), 'price' => array('width' => 55, 'justification' => 'right'))));
     $objPdf->ezStream();
     // Never reached
     return true;
 }
Пример #2
0
 /**
  * Set up the shop page with products and discounts
  *
  * @param   array       $product_ids    The optional array of Product IDs.
  *                                      Overrides any URL parameters if set
  * @return  boolean                     True on success, false otherwise
  * @global  ADONewConnection  $objDatabase    Database connection object
  * @global  array       $_ARRAYLANG     Language array
  * @global  array       $_CONFIG        Core configuration array, see {@link /config/settings.php}
  * @global  string(?)   $themesPages    Themes pages(?)
  */
 static function view_product_overview($product_ids = null)
 {
     global $_ARRAYLANG;
     // activate javascript shadowbox
     \JS::activate('shadowbox');
     $flagSpecialoffer = intval(\Cx\Core\Setting\Controller\Setting::getValue('show_products_default', 'Shop'));
     if (isset($_REQUEST['cmd']) && $_REQUEST['cmd'] == 'discounts') {
         $flagSpecialoffer = Products::DEFAULT_VIEW_DISCOUNTS;
     }
     $flagLastFive = isset($_REQUEST['lastFive']);
     $product_id = isset($_REQUEST['productId']) ? intval($_REQUEST['productId']) : null;
     $cart_id = null;
     if (isset($_REQUEST['referer']) && $_REQUEST['referer'] == 'cart') {
         $cart_id = $product_id;
         $product_id = Cart::get_product_id($cart_id);
     }
     $manufacturer_id = isset($_REQUEST['manufacturerId']) ? intval($_REQUEST['manufacturerId']) : null;
     $term = isset($_REQUEST['term']) ? trim(contrexx_input2raw($_REQUEST['term'])) : null;
     $category_id = isset($_REQUEST['catId']) ? intval($_REQUEST['catId']) : null;
     if (!($product_id || $category_id || $manufacturer_id || $term || $cart_id)) {
         // NOTE: This is different from NULL
         // in that it enables listing the subcategories
         $category_id = 0;
     }
     // Validate parameters
     if ($product_id && empty($category_id)) {
         $objProduct = Product::getById($product_id);
         if ($objProduct) {
             $category_id = $objProduct->category_id();
         }
         if (isset($_SESSION['shop']['previous_category_id'])) {
             $category_id_previous = $_SESSION['shop']['previous_category_id'];
             foreach (preg_split('/\\s*,\\s*/', $category_id) as $id) {
                 if ($category_id_previous == intval($id)) {
                     $category_id = $category_id_previous;
                 }
             }
         }
     }
     // Remember visited Products
     if ($product_id) {
         self::rememberVisitedProducts($product_id);
     }
     $objCategory = null;
     if ($category_id && empty($product_id)) {
         $objCategory = ShopCategory::getById($category_id);
         if (!$objCategory) {
             $category_id = null;
         }
     }
     $shopMenu = '<form method="post" action="' . \Cx\Core\Routing\Url::fromModuleAndCmd('Shop', '') . '">' . '<input type="text" name="term" value="' . htmlentities($term, ENT_QUOTES, CONTREXX_CHARSET) . '" style="width:150px;" />&nbsp;' . '<select name="catId" style="width:150px;">' . '<option value="0">' . $_ARRAYLANG['TXT_ALL_PRODUCT_GROUPS'] . '</option>' . ShopCategories::getMenuoptions($category_id) . '</select>&nbsp;' . Manufacturer::getMenu('manufacturerId', $manufacturer_id, true) . '<input type="submit" name="bsubmit" value="' . $_ARRAYLANG['TXT_SEARCH'] . '" style="width:66px;" />' . '</form>';
     self::$objTemplate->setGlobalVariable($_ARRAYLANG + array('SHOP_MENU' => $shopMenu, 'SHOP_SEARCH_TERM' => htmlentities($term, ENT_QUOTES, CONTREXX_CHARSET), 'SHOP_CATEGORIES_MENUOPTIONS' => ShopCategories::getMenuoptions($category_id, true, 0, true), 'SHOP_MANUFACTURER_MENUOPTIONS' => Manufacturer::getMenuoptions($manufacturer_id, true)));
     // Only show the cart info when the JS cart is not active!
     global $_CONFIGURATION;
     if (empty($_CONFIGURATION['custom']['shopJsCart'])) {
         self::$objTemplate->setVariable(array('SHOP_CART_INFO' => self::cart_info()));
     }
     // Exclude Category list from search results
     if ($term == '') {
         self::showCategories($category_id);
     }
     if (self::$objTemplate->blockExists('shopNextCategoryLink')) {
         $nextCat = ShopCategory::getNextShopCategoryId($category_id);
         $objCategory = ShopCategory::getById($nextCat);
         if ($objCategory) {
             self::$objTemplate->setVariable(array('SHOP_NEXT_CATEGORY_ID' => $nextCat, 'SHOP_NEXT_CATEGORY_TITLE' => str_replace('"', '&quot;', $objCategory->name())));
         }
     }
     $pagingCmd = !empty($_REQUEST['cmd']) ? '&amp;cmd=' . contrexx_input2raw($_REQUEST['cmd']) : '';
     $pagingCatId = '';
     $pagingManId = '';
     $pagingTerm = '';
     // TODO: This probably breaks paging in search results!
     // Should only reset the flag conditionally, but add the URL parameters in
     // any case, methinks!
     if ($category_id > 0 && $term == '') {
         $flagSpecialoffer = false;
         $pagingCatId = "&amp;catId={$category_id}";
     }
     if ($manufacturer_id > 0) {
         $flagSpecialoffer = false;
         $pagingManId = "&amp;manufacturer_id={$manufacturer_id}";
     }
     if ($term != '') {
         $flagSpecialoffer = false;
         $pagingTerm = '&amp;term=' . htmlentities($term, ENT_QUOTES, CONTREXX_CHARSET);
     }
     // The Product count is passed by reference and set to the total
     // number of records, though only as many as specified by the core
     // paging limit are returned in the array.
     $limit = \Cx\Core\Setting\Controller\Setting::getValue('numof_products_per_page_frontend', 'Shop');
     //\DBG::activate(DBG_ERROR_FIREPHP);
     // Use Sorting class for the Product order
     $uri = \Html::getRelativeUri_entities();
     $arrOrder = array('product.ord' => $_ARRAYLANG['TXT_SHOP_ORDER_PRODUCT_ORD'], 'name' => $_ARRAYLANG['TXT_SHOP_ORDER_PRODUCT_TITLE'], 'code' => $_ARRAYLANG['TXT_SHOP_ORDER_PRODUCT_CODE'], 'price' => $_ARRAYLANG['TXT_SHOP_ORDER_PRODUCT_PRICE'], 'id' => $_ARRAYLANG['TXT_SHOP_ORDER_PRODUCT_DATE'], 'bestseller' => $_ARRAYLANG['TXT_SHOP_ORDER_PRODUCT_BESTSELLER']);
     $defaultOrder = \Sorting::getFieldindex(Products::$arrProductOrder[\Cx\Core\Setting\Controller\Setting::getValue('product_sorting', 'Shop')]);
     $objSorting = new \Sorting($uri, $arrOrder, true, 'shop_order_products', $defaultOrder);
     //\DBG::log("Sorting headers: ".var_export($objSorting->getHeaderArray(), true));
     $count = $limit;
     $arrProduct = array();
     if ($product_ids) {
         $arrProduct = self::getValidProducts($product_ids);
         $product_id = null;
         // Suppress meta title from single Product
     } elseif ($product_id) {
         $arrProduct = self::getValidProducts(array($product_id));
     } else {
         $arrProduct = Products::getByShopParams($count, \Paging::getPosition(), $product_id, $category_id, $manufacturer_id, $term, $flagSpecialoffer, $flagLastFive, $objSorting->getOrder(), self::$objCustomer && self::$objCustomer->is_reseller());
     }
     // Only show sorting when there's enough to be sorted
     if ($count > 1) {
         $objSorting->parseHeaders(self::$objTemplate, 'shop_product_order');
     }
     if ($count == 0 && !ShopCategories::getChildCategoryIdArray($category_id)) {
         //if ($term != '' || $manufacturer_id != 0 || $flagSpecialoffer) {
         if (self::$objTemplate->blockExists('no_product')) {
             self::$objTemplate->touchBlock('no_product');
         }
         return true;
     }
     if ($objCategory) {
         // Only indicate the category name when there are products
         if ($count) {
             self::$objTemplate->setVariable(array('SHOP_CATEGORY_CURRENT_NAME' => contrexx_raw2xhtml($objCategory->name()), 'SHOP_PRODUCTS_IN_CATEGORY' => sprintf($_ARRAYLANG['TXT_SHOP_PRODUCTS_IN_CATEGORY'], contrexx_raw2xhtml($objCategory->name()))));
         }
     } else {
         // TODO: There are other cases of flag combinations that are not indivuidually
         // handled here yet.
         if ($term == '') {
             if ($flagSpecialoffer == Products::DEFAULT_VIEW_DISCOUNTS) {
                 self::$objTemplate->setVariable('SHOP_PRODUCTS_IN_CATEGORY', $_ARRAYLANG['TXT_SHOP_PRODUCTS_SPECIAL_OFFER']);
             } else {
                 if (self::$objTemplate->blockExists('products_in_category')) {
                     self::$objTemplate->hideBlock('products_in_category');
                 }
             }
         } else {
             self::$objTemplate->setVariable('SHOP_PRODUCTS_IN_CATEGORY', sprintf($_ARRAYLANG['TXT_SHOP_PRODUCTS_SEARCH_RESULTS'], contrexx_raw2xhtml($term)));
         }
     }
     $uri = '&amp;section=Shop' . MODULE_INDEX . $pagingCmd . $pagingCatId . $pagingManId . $pagingTerm;
     self::$objTemplate->setVariable(array('SHOP_PRODUCT_PAGING' => \Paging::get($uri, '', $count, $limit, $count > 0), 'SHOP_PRODUCT_TOTAL' => $count));
     // Global microdata: Seller information
     $seller_url = \Cx\Core\Routing\Url::fromModuleAndCmd('Shop', '')->toString();
     $seller_name = \Cx\Core\Setting\Controller\Setting::getValue('company', 'Shop');
     if (empty($seller_name)) {
         $seller_name = $seller_url;
     }
     self::$objTemplate->setVariable(array('SHOP_SELLER_NAME' => $seller_name, 'SHOP_SELLER_URL' => $seller_url));
     $formId = 0;
     $arrDefaultImageSize = $arrSize = null;
     foreach ($arrProduct as $objProduct) {
         if (!empty($product_id)) {
             self::$pageTitle = $objProduct->name();
         }
         $id = $objProduct->id();
         $productSubmitFunction = '';
         $arrPictures = Products::get_image_array_from_base64($objProduct->pictures());
         $havePicture = false;
         $arrProductImages = array();
         foreach ($arrPictures as $index => $image) {
             $thumbnailPath = $pictureLink = '';
             if (empty($image['img']) || $image['img'] == ShopLibrary::noPictureName) {
                 // We have at least one picture on display already.
                 // No need to show "no picture" three times!
                 if ($havePicture) {
                     continue;
                 }
                 $thumbnailPath = self::$defaultImage;
                 $pictureLink = '#';
                 //"javascript:alert('".$_ARRAYLANG['TXT_NO_PICTURE_AVAILABLE']."');";
                 if (empty($arrDefaultImageSize)) {
                     $arrDefaultImageSize = getimagesize(\Cx\Core\Core\Controller\Cx::instanciate()->getWebsitePath() . self::$defaultImage);
                     self::scaleImageSizeToThumbnail($arrDefaultImageSize);
                 }
                 $arrSize = $arrDefaultImageSize;
             } else {
                 $thumbnailPath = \Cx\Core\Core\Controller\Cx::instanciate()->getWebsiteImagesShopWebPath() . '/' . \ImageManager::getThumbnailFilename($image['img']);
                 if ($image['width'] && $image['height']) {
                     $pictureLink = contrexx_raw2encodedUrl(\Cx\Core\Core\Controller\Cx::instanciate()->getWebsiteImagesShopWebPath() . '/' . $image['img']) . '" rel="shadowbox[' . ($formId + 1) . ']';
                     // Thumbnail display size
                     $arrSize = array($image['width'], $image['height']);
                 } else {
                     $pictureLink = '#';
                     if (!file_exists(\Cx\Core\Core\Controller\Cx::instanciate()->getWebsitePath() . $thumbnailPath)) {
                         continue;
                     }
                     $arrSize = getimagesize(\Cx\Core\Core\Controller\Cx::instanciate()->getWebsitePath() . $thumbnailPath);
                 }
                 self::scaleImageSizeToThumbnail($arrSize);
                 // Use the first available picture in microdata, if any
                 if (!$havePicture) {
                     $picture_url = \Cx\Core\Routing\Url::fromCapturedRequest(\Cx\Core\Core\Controller\Cx::instanciate()->getWebsiteImagesShopWebPath() . '/' . $image['img'], \Cx\Core\Core\Controller\Cx::instanciate()->getWebsiteOffsetPath(), array());
                     self::$objTemplate->setVariable('SHOP_PRODUCT_IMAGE', $picture_url->toString());
                     //\DBG::log("Set image to ".$picture_url->toString());
                 }
             }
             $arrProductImages[] = array('THUMBNAIL' => contrexx_raw2encodedUrl($thumbnailPath), 'THUMBNAIL_SIZE' => $arrSize[3], 'THUMBNAIL_LINK' => $pictureLink, 'POPUP_LINK' => $pictureLink, 'POPUP_LINK_NAME' => $_ARRAYLANG['TXT_SHOP_IMAGE'] . ' ' . $index);
             $havePicture = true;
         }
         $i = 1;
         foreach ($arrProductImages as $arrProductImage) {
             // TODO: Instead of several numbered image blocks, use a single one repeatedly
             self::$objTemplate->setVariable(array('SHOP_PRODUCT_THUMBNAIL_' . $i => $arrProductImage['THUMBNAIL'], 'SHOP_PRODUCT_THUMBNAIL_SIZE_' . $i => $arrProductImage['THUMBNAIL_SIZE']));
             if (!empty($arrProductImage['THUMBNAIL_LINK'])) {
                 self::$objTemplate->setVariable(array('SHOP_PRODUCT_THUMBNAIL_LINK_' . $i => $arrProductImage['THUMBNAIL_LINK'], 'TXT_SEE_LARGE_PICTURE' => $_ARRAYLANG['TXT_SEE_LARGE_PICTURE']));
             } else {
                 self::$objTemplate->setVariable('TXT_SEE_LARGE_PICTURE', contrexx_raw2xhtml($objProduct->name()));
             }
             if ($arrProductImage['POPUP_LINK']) {
                 self::$objTemplate->setVariable('SHOP_PRODUCT_POPUP_LINK_' . $i, $arrProductImage['POPUP_LINK']);
             }
             self::$objTemplate->setVariable('SHOP_PRODUCT_POPUP_LINK_NAME_' . $i, $arrProductImage['POPUP_LINK_NAME']);
             ++$i;
         }
         $stock = $objProduct->stock_visible() ? $_ARRAYLANG['TXT_STOCK'] . ': ' . intval($objProduct->stock()) : '';
         $price = $objProduct->get_custom_price(self::$objCustomer, 0, 1, true);
         // If there is a discountprice and it's enabled
         $discountPrice = '';
         if ($objProduct->discountprice() > 0 && $objProduct->discount_active()) {
             $price = '<s>' . $price . '</s>';
             $discountPrice = $objProduct->get_custom_price(self::$objCustomer, 0, 1, false);
         }
         $groupCountId = $objProduct->group_id();
         $groupArticleId = $objProduct->article_id();
         $groupCustomerId = 0;
         if (self::$objCustomer) {
             $groupCustomerId = self::$objCustomer->group_id();
         }
         self::showDiscountInfo($groupCustomerId, $groupArticleId, $groupCountId, 1);
         /* OLD
                     $price = Currency::getCurrencyPrice(
                         $objProduct->getCustomerPrice(self::$objCustomer)
                     );
                     $discountPrice = '';
                     $discount_active = $objProduct->discount_active();
                     if ($discount_active) {
                         $discountPrice = $objProduct->discountprice();
                         if ($discountPrice > 0) {
                             $price = "<s>$price</s>";
                             $discountPrice =
                                 Currency::getCurrencyPrice($discountPrice);
                         }
                     }
         */
         $short = $objProduct->short();
         $longDescription = $objProduct->long();
         $detailLink = null;
         // Detaillink is required for microdata (even when longdesc
         // is empty)
         $detail_url = \Cx\Core\Routing\Url::fromModuleAndCmd('Shop', 'details', FRONTEND_LANG_ID, array('productId' => $objProduct->id()))->toString();
         self::$objTemplate->setVariable('SHOP_PRODUCT_DETAIL_URL', $detail_url);
         if (!$product_id && !empty($longDescription)) {
             $detailLink = '<a href="' . $detail_url . '"' . ' title="' . $_ARRAYLANG['TXT_MORE_INFORMATIONS'] . '">' . $_ARRAYLANG['TXT_MORE_INFORMATIONS'] . '</a>';
             self::$objTemplate->setVariable('SHOP_PRODUCT_DETAILLINK', $detailLink);
         }
         // Check Product flags.
         // Only the meter flag is currently implemented and in use.
         $flagMeter = $objProduct->testFlag('__METER__');
         // Submit button name and function.
         // Calling productOptions() also sets the $flagMultipart variable
         // to the appropriate encoding type for the form if
         // any upload fields are in use.
         $flagMultipart = false;
         $productSubmitName = $productSubmitFunction = '';
         if (isset($_GET['cmd']) && $_GET['cmd'] == 'details' && isset($_GET['referer']) && $_GET['referer'] == 'cart') {
             $productSubmitName = "updateProduct[{$cart_id}]";
             $productSubmitFunction = self::productOptions($id, $formId, $cart_id, $flagMultipart);
         } else {
             $productSubmitName = 'addProduct';
             $productSubmitFunction = self::productOptions($id, $formId, $cart_id, $flagMultipart);
         }
         $shopProductFormName = "shopProductForm{$formId}";
         $row = $formId % 2 + 1;
         self::$objTemplate->setVariable(array('SHOP_ROWCLASS' => 'row' . $row, 'SHOP_PRODUCT_ID' => $objProduct->id(), 'SHOP_PRODUCT_TITLE' => contrexx_raw2xhtml($objProduct->name()), 'SHOP_PRODUCT_DESCRIPTION' => $short, 'SHOP_PRODUCT_DETAILDESCRIPTION' => $longDescription ? $longDescription : $short, 'SHOP_PRODUCT_FORM_NAME' => $shopProductFormName, 'SHOP_PRODUCT_SUBMIT_NAME' => $productSubmitName, 'SHOP_PRODUCT_SUBMIT_FUNCTION' => $productSubmitFunction, 'SHOP_FORM_ENCTYPE' => $flagMultipart ? ' enctype="multipart/form-data"' : '', 'TXT_SHOP_PRODUCT_COUNT' => $flagMeter ? $_ARRAYLANG['TXT_SHOP_PRODUCT_METER'] : $_ARRAYLANG['TXT_SHOP_PRODUCT_COUNT'], 'SHOP_CURRENCY_CODE' => Currency::getActiveCurrencyCode()));
         if ($objProduct->code()) {
             self::$objTemplate->setVariable('SHOP_PRODUCT_CUSTOM_ID', htmlentities($objProduct->code(), ENT_QUOTES, CONTREXX_CHARSET));
         }
         $manufacturer_name = $manufacturer_url = $manufacturer_link = '';
         $manufacturer_id = $objProduct->manufacturer_id();
         if ($manufacturer_id) {
             $manufacturer_name = Manufacturer::getNameById($manufacturer_id, FRONTEND_LANG_ID);
             $manufacturer_url = Manufacturer::getUrlById($manufacturer_id, FRONTEND_LANG_ID);
         }
         if (!empty($manufacturer_url) || !empty($manufacturer_name)) {
             if (empty($manufacturer_name)) {
                 $manufacturer_name = $manufacturer_url;
             }
             if (!empty($manufacturer_url)) {
                 $manufacturer_link = '<a href="' . $manufacturer_url . '">' . $manufacturer_name . '</a>';
             }
             // TODO: Test results for any combination of name and url
             self::$objTemplate->setVariable(array('SHOP_MANUFACTURER_NAME' => $manufacturer_name, 'SHOP_MANUFACTURER_URL' => $manufacturer_url, 'SHOP_MANUFACTURER_LINK' => $manufacturer_link, 'TXT_SHOP_MANUFACTURER_LINK' => $_ARRAYLANG['TXT_SHOP_MANUFACTURER_LINK']));
         }
         // This is the old Product field for the Manufacturer URI.
         // This is now extended by the Manufacturer table and should thus
         // get a new purpose.  As it is product specific, it could be
         // renamed and reused as a link to individual Products!
         $externalLink = $objProduct->uri();
         if (!empty($externalLink)) {
             self::$objTemplate->setVariable(array('SHOP_EXTERNAL_LINK' => '<a href="' . $externalLink . '" title="' . $_ARRAYLANG['TXT_SHOP_EXTERNAL_LINK'] . '" target="_blank">' . $_ARRAYLANG['TXT_SHOP_EXTERNAL_LINK'] . '</a>'));
         }
         if ($price) {
             self::$objTemplate->setGlobalVariable(array('SHOP_PRODUCT_PRICE' => $price, 'SHOP_PRODUCT_PRICE_UNIT' => Currency::getActiveCurrencySymbol()));
         }
         // Only show the discount price if it's actually in use,
         // avoid an "empty <font> tag" HTML warning
         if ($discountPrice) {
             self::$objTemplate->setGlobalVariable(array('SHOP_PRODUCT_DISCOUNTPRICE' => $discountPrice, 'SHOP_PRODUCT_DISCOUNTPRICE_UNIT' => Currency::getActiveCurrencySymbol()));
             if (self::$objTemplate->blockExists('price_discount')) {
                 self::$objTemplate->touchBlock('price_discount');
             }
         } else {
             if (self::$objTemplate->blockExists('price')) {
                 self::$objTemplate->touchBlock('price');
             }
         }
         // Special outlet ShopCategory with discounts varying daily.
         // This should be implemented in a more generic way, in the
         // Discount class maybe.
         if ($objProduct->is_outlet()) {
             self::$objTemplate->setVariable(array('TXT_SHOP_DISCOUNT_TODAY' => $_ARRAYLANG['TXT_SHOP_DISCOUNT_TODAY'], 'SHOP_DISCOUNT_TODAY' => $objProduct->getOutletDiscountRate() . '%', 'TXT_SHOP_PRICE_TODAY' => $_ARRAYLANG['TXT_SHOP_PRICE_TODAY'], 'SHOP_PRICE_TODAY' => Currency::getCurrencyPrice($objProduct->getDiscountedPrice()), 'SHOP_PRICE_TODAY_UNIT' => Currency::getActiveCurrencySymbol()));
         }
         if ($objProduct->stock_visible()) {
             self::$objTemplate->setVariable(array('SHOP_PRODUCT_STOCK' => $stock));
         }
         if ($detailLink) {
             self::$objTemplate->setVariable(array('SHOP_PRODUCT_DETAILLINK' => $detailLink));
         }
         $distribution = $objProduct->distribution();
         $weight = '';
         if ($distribution == 'delivery') {
             $weight = $objProduct->weight();
         }
         // Hide the weight if it is zero or disabled in the configuration
         if ($weight > 0 && \Cx\Core\Setting\Controller\Setting::getValue('weight_enable', 'Shop')) {
             self::$objTemplate->setVariable(array('TXT_SHOP_PRODUCT_WEIGHT' => $_ARRAYLANG['TXT_SHOP_PRODUCT_WEIGHT'], 'SHOP_PRODUCT_WEIGHT' => Weight::getWeightString($weight)));
         }
         if (Vat::isEnabled()) {
             self::$objTemplate->setVariable(array('SHOP_PRODUCT_TAX_PREFIX' => Vat::isIncluded() ? $_ARRAYLANG['TXT_SHOP_VAT_PREFIX_INCL'] : $_ARRAYLANG['TXT_SHOP_VAT_PREFIX_EXCL'], 'SHOP_PRODUCT_TAX' => Vat::getShort($objProduct->vat_id())));
         }
         // Add flag images for flagged Products
         $strImage = '';
         $strFlags = $objProduct->flags();
         $arrVirtual = ShopCategories::getVirtualCategoryNameArray(FRONTEND_LANG_ID);
         foreach (explode(' ', $strFlags) as $strFlag) {
             if (in_array($strFlag, $arrVirtual)) {
                 $strImage .= '<img src="images/content/' . $strFlag . '.jpg" alt="' . $strFlag . '" />';
             }
         }
         if ($strImage) {
             self::$objTemplate->setVariable('SHOP_PRODUCT_FLAG_IMAGE', $strImage);
         }
         $minimum_order_quantity = $objProduct->minimum_order_quantity();
         //Activate Quantity-Inputfield when minimum_order_quantity exists
         if (self::$objTemplate->blockExists('orderQuantity') && $minimum_order_quantity > 0) {
             self::$objTemplate->setVariable('SHOP_PRODUCT_MINIMUM_ORDER_QUANTITY', contrexx_raw2xhtml($objProduct->minimum_order_quantity()));
         } elseif (self::$objTemplate->blockExists('orderQuantity') && !$minimum_order_quantity) {
             self::$objTemplate->hideBlock('orderQuantity');
         }
         if (self::$objTemplate->blockExists('shopProductRow')) {
             self::$objTemplate->parse('shopProductRow');
         }
         ++$formId;
     }
     return true;
 }
Пример #3
0
 /**
  * Show Products
  */
 function view_product_overview()
 {
     global $_ARRAYLANG;
     if (isset($_POST['bsubmit'])) {
         $this->update_products();
     }
     if (isset($_POST['multi_action'])) {
         if ($_POST['multi_action'] == 'activate') {
             Products::set_active($_POST['selectedProductId'], true);
         } elseif ($_POST['multi_action'] == 'deactivate') {
             Products::set_active($_POST['selectedProductId'], false);
         }
     }
     self::$objTemplate->addBlockfile('SHOP_PRODUCTS_FILE', 'shop_products_block', 'module_shop_product_catalog.html');
     self::$objTemplate->setGlobalVariable($_ARRAYLANG);
     $category_id = empty($_REQUEST['category_id']) ? null : intval($_REQUEST['category_id']);
     //DBG::log("Requested Category ID: $category_id");
     $manufacturer_id = empty($_REQUEST['manufacturer_id']) ? null : intval($_REQUEST['manufacturer_id']);
     $flagSpecialoffer = isset($_REQUEST['specialoffer']);
     $searchTerm = empty($_REQUEST['searchterm']) ? null : trim(contrexx_input2raw($_REQUEST['searchterm']));
     $url = \Html::getRelativeUri();
     // TODO: Strip URL parameters: Which?
     //        \Html::stripUriParam($url, '');
     $arrSorting = array('`product`.`id`' => $_ARRAYLANG['TXT_SHOP_ID'], '`product`.`active`' => $_ARRAYLANG['TXT_SHOP_PRODUCT_ACTIVE'], '`product`.`ord`' => $_ARRAYLANG['TXT_SHOP_PRODUCT_ORDER'], 'name' => $_ARRAYLANG['TXT_SHOP_PRODUCT_NAME'], 'code' => $_ARRAYLANG['TXT_SHOP_PRODUCT_CODE'], '`product`.`discountprice`' => $_ARRAYLANG['TXT_SHOP_PRODUCT_DISCOUNTPRICE'], '`product`.`normalprice`' => $_ARRAYLANG['TXT_SHOP_PRODUCT_NORMALPRICE'], '`product`.`resellerprice`' => $_ARRAYLANG['TXT_SHOP_PRODUCT_RESELLERPRICE'], '`product`.`distribution`' => $_ARRAYLANG['TXT_SHOP_PRODUCT_DISTRIBUTION'], '`product`.`stock`' => $_ARRAYLANG['TXT_SHOP_PRODUCT_STOCK']);
     $objSorting = new \Sorting($url, $arrSorting, false, 'order_shop_product');
     $limit = \Cx\Core\Setting\Controller\Setting::getValue('numof_products_per_page_backend', 'Shop');
     $tries = 2;
     while ($tries--) {
         // have to set $count again because it will be set to 0 in Products::getByShopParams
         $count = $limit;
         // Mind that $count is handed over by reference.
         $arrProducts = Products::getByShopParams($count, \Paging::getPosition(), 0, $category_id, $manufacturer_id, $searchTerm, $flagSpecialoffer, false, $objSorting->getOrder(), null, true);
         if (count($arrProducts) > 0 || \Paging::getPosition() == 0) {
             break;
         }
         \Paging::reset();
     }
     self::$objTemplate->setVariable(array('SHOP_CATEGORY_MENU' => \Html::getSelect('category_id', array(0 => $_ARRAYLANG['TXT_ALL_PRODUCT_GROUPS']) + ShopCategories::getNameArray(), $category_id), 'SHOP_SEARCH_TERM' => $searchTerm, 'SHOP_PRODUCT_TOTAL' => $count));
     if (empty($arrProducts)) {
         self::$objTemplate->touchBlock('no_product');
         return true;
     }
     self::$objTemplate->setVariable(array('SHOP_PRODUCT_PAGING' => \Paging::get($url, '<b>' . $_ARRAYLANG['TXT_PRODUCTS'] . '</b>', $count, $limit, true), 'SHOP_HEADING_PRODUCT_ID' => $objSorting->getHeaderForField('`product`.`id`'), 'SHOP_HEADING_PRODUCT_ACTIVE' => $objSorting->getHeaderForField('`product`.`active`'), 'SHOP_HEADING_PRODUCT_ORD' => $objSorting->getHeaderForField('`product`.`ord`'), 'SHOP_HEADING_PRODUCT_NAME' => $objSorting->getHeaderForField('name'), 'SHOP_HEADING_PRODUCT_CODE' => $objSorting->getHeaderForField('code'), 'SHOP_HEADING_PRODUCT_DISCOUNTPRICE' => $objSorting->getHeaderForField('`product`.`discountprice`'), 'SHOP_HEADING_PRODUCT_NORMALPRICE' => $objSorting->getHeaderForField('`product`.`normalprice`'), 'SHOP_HEADING_PRODUCT_RESELLERPRICE' => $objSorting->getHeaderForField('`product`.`resellerprice`'), 'SHOP_HEADING_PRODUCT_DISTRIBUTION' => $objSorting->getHeaderForField('`product`.`distribution`'), 'SHOP_HEADING_PRODUCT_STOCK' => $objSorting->getHeaderForField('`product`.`stock`')));
     $arrLanguages = \FWLanguage::getActiveFrontendLanguages();
     // Intended to show an edit link for all active frontend languages.
     // However, the design doesn't like it.  Limit to the current one.
     $arrLanguages = array(FRONTEND_LANG_ID => $arrLanguages[FRONTEND_LANG_ID]);
     $i = 0;
     foreach ($arrProducts as $objProduct) {
         $productStatus = '';
         $productStatusValue = '';
         $productStatusPicture = 'status_red.gif';
         if ($objProduct->active()) {
             $productStatus = \Html::ATTRIBUTE_CHECKED;
             $productStatusValue = 1;
             $productStatusPicture = 'status_green.gif';
         }
         $discount_active = '';
         $specialOfferValue = '';
         if ($objProduct->discount_active()) {
             $discount_active = \Html::ATTRIBUTE_CHECKED;
             $specialOfferValue = 1;
         }
         self::$objTemplate->setGlobalVariable(array('SHOP_ROWCLASS' => 'row' . (++$i % 2 + 1), 'SHOP_PRODUCT_ID' => $objProduct->id(), 'SHOP_PRODUCT_CODE' => $objProduct->code(), 'SHOP_PRODUCT_NAME' => contrexx_raw2xhtml($objProduct->name()), 'SHOP_PRODUCT_PRICE1' => Currency::formatPrice($objProduct->price()), 'SHOP_PRODUCT_PRICE2' => Currency::formatPrice($objProduct->resellerprice()), 'SHOP_PRODUCT_DISCOUNT' => Currency::formatPrice($objProduct->discountprice()), 'SHOP_PRODUCT_SPECIAL_OFFER' => $discount_active, 'SHOP_SPECIAL_OFFER_VALUE_OLD' => $specialOfferValue, 'SHOP_PRODUCT_VAT_MENU' => Vat::getShortMenuString($objProduct->vat_id(), 'taxId[' . $objProduct->id() . ']'), 'SHOP_PRODUCT_VAT_ID' => $objProduct->vat_id() ? $objProduct->vat_id() : 'NULL', 'SHOP_PRODUCT_DISTRIBUTION' => $objProduct->distribution(), 'SHOP_PRODUCT_STOCK' => $objProduct->stock(), 'SHOP_PRODUCT_SHORT_DESC' => $objProduct->short(), 'SHOP_PRODUCT_STATUS' => $productStatus, 'SHOP_PRODUCT_STATUS_PICTURE' => $productStatusPicture, 'SHOP_ACTIVE_VALUE_OLD' => $productStatusValue, 'SHOP_SORT_ORDER' => $objProduct->ord(), 'SHOP_DISTRIBUTION' => $_ARRAYLANG['TXT_DISTRIBUTION_' . strtoupper($objProduct->distribution())], 'SHOP_SHOW_PRODUCT_ON_START_PAGE_CHECKED' => $objProduct->shown_on_startpage() ? \Html::ATTRIBUTE_CHECKED : '', 'SHOP_SHOW_PRODUCT_ON_START_PAGE_OLD' => $objProduct->shown_on_startpage() ? '1' : '', 'SHOP_PRODUCT_NAME' => contrexx_raw2xhtml($objProduct->name())));
         // All languages active
         foreach ($arrLanguages as $lang_id => $arrLanguage) {
             self::$objTemplate->setVariable(array('SHOP_PRODUCT_LANGUAGE_ID' => $lang_id, 'SHOP_PRODUCT_LANGUAGE_EDIT' => sprintf($_ARRAYLANG['TXT_SHOP_PRODUCT_LANGUAGE_EDIT'], $lang_id, $arrLanguage['lang'], $arrLanguage['name'])));
             self::$objTemplate->parse('product_language');
         }
         self::$objTemplate->touchBlock('productRow');
         self::$objTemplate->parse('productRow');
     }
     return true;
 }