Beispiel #1
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;
 }
Beispiel #2
0
 /**
  * The Cart view
  *
  * Mind that the Cart needs to be {@see update()}d before calling this
  * method.
  * @global  array $_ARRAYLANG   Language array
  * @param   \Cx\Core\Html\Sigma $objTemplate  The optional Template
  */
 static function view($objTemplate = null)
 {
     global $_ARRAYLANG;
     if (!$objTemplate) {
         // TODO: Handle missing or empty Template, load one
         die("Cart::view(): ERROR: No template");
         //            return false;
     }
     $objTemplate->setGlobalVariable($_ARRAYLANG);
     $i = 0;
     if (count(self::$products)) {
         foreach (self::$products as $arrProduct) {
             $groupCountId = $arrProduct['group_id'];
             $groupArticleId = $arrProduct['article_id'];
             $groupCustomerId = 0;
             if (Shop::customer()) {
                 $groupCustomerId = Shop::customer()->group_id();
             }
             Shop::showDiscountInfo($groupCustomerId, $groupArticleId, $groupCountId, $arrProduct['quantity']);
             // product image
             $arrProductImg = Products::get_image_array_from_base64($arrProduct['product_images']);
             $shopImagesWebPath = \Cx\Core\Core\Controller\Cx::instanciate()->getWebsiteImagesWebPath() . '/Shop/';
             $thumbnailPath = $shopImagesWebPath . ShopLibrary::noPictureName;
             foreach ($arrProductImg as $productImg) {
                 if (!empty($productImg['img']) && $productImg['img'] != ShopLibrary::noPictureName) {
                     $thumbnailPath = $shopImagesWebPath . \ImageManager::getThumbnailFilename($productImg['img']);
                     break;
                 }
             }
             /* UNUSED (and possibly obsolete, too)
                             if (isset($arrProduct['discount_string'])) {
             //DBG::log("Shop::view_cart(): Product ID ".$arrProduct['id'].": ".$arrProduct['discount_string']);
                                 $objTemplate->setVariable(
                                     'SHOP_DISCOUNT_COUPON_STRING',
                                         $arrProduct['coupon_string']
                                 );
                             }*/
             // The fields that don't apply have been set to ''
             // (empty string) already -- see update().
             $objTemplate->setVariable(array('SHOP_PRODUCT_ROW' => 'row' . (++$i % 2 + 1), 'SHOP_PRODUCT_ID' => $arrProduct['id'], 'SHOP_PRODUCT_CODE' => $arrProduct['product_id'], 'SHOP_PRODUCT_THUMBNAIL' => $thumbnailPath, 'SHOP_PRODUCT_CART_ID' => $arrProduct['cart_id'], 'SHOP_PRODUCT_TITLE' => str_replace('"', '&quot;', contrexx_raw2xhtml($arrProduct['title'])), 'SHOP_PRODUCT_PRICE' => $arrProduct['price'], 'SHOP_PRODUCT_PRICE_UNIT' => Currency::getActiveCurrencySymbol(), 'SHOP_PRODUCT_QUANTITY' => $arrProduct['quantity'], 'SHOP_PRODUCT_ITEMPRICE' => $arrProduct['itemprice'], 'SHOP_PRODUCT_ITEMPRICE_UNIT' => Currency::getActiveCurrencySymbol(), 'SHOP_REMOVE_PRODUCT' => $_ARRAYLANG['TXT_SHOP_REMOVE_ITEM']));
             //DBG::log("Attributes String: {$arrProduct['options_long']}");
             if ($arrProduct['options_long']) {
                 $objTemplate->setVariable('SHOP_PRODUCT_OPTIONS', $arrProduct['options_long']);
             }
             if (\Cx\Core\Setting\Controller\Setting::getValue('weight_enable', 'Shop')) {
                 $objTemplate->setVariable(array('SHOP_PRODUCT_WEIGHT' => Weight::getWeightString($arrProduct['weight']), 'TXT_WEIGHT' => $_ARRAYLANG['TXT_TOTAL_WEIGHT']));
             }
             if (Vat::isEnabled()) {
                 $objTemplate->setVariable(array('SHOP_PRODUCT_TAX_RATE' => $arrProduct['vat_rate'] ? Vat::format($arrProduct['vat_rate']) : '', 'SHOP_PRODUCT_TAX_AMOUNT' => $arrProduct['vat_amount'] . '&nbsp;' . Currency::getActiveCurrencySymbol()));
             }
             if (intval($arrProduct['minimum_order_quantity']) > 0) {
                 $objTemplate->setVariable(array('SHOP_PRODUCT_MINIMUM_ORDER_QUANTITY' => $arrProduct['minimum_order_quantity']));
             } else {
                 if ($objTemplate->blockExists('orderQuantity')) {
                     $objTemplate->hideBlock('orderQuantity');
                 }
                 if ($objTemplate->blockExists('minimumOrderQuantity')) {
                     $objTemplate->hideBlock('minimumOrderQuantity');
                 }
             }
             $objTemplate->parse('shopCartRow');
         }
     } else {
         $objTemplate->hideBlock('shopCart');
         if ($objTemplate->blockExists('shopCartEmpty')) {
             $objTemplate->touchBlock('shopCartEmpty');
             $objTemplate->parse('shopCartEmpty');
         }
         if ($_SESSION['shop']['previous_product_ids']) {
             $ids = $_SESSION['shop']['previous_product_ids']->toArray();
             Shop::view_product_overview($ids);
         }
     }
     $objTemplate->setGlobalVariable(array('TXT_PRODUCT_ID' => $_ARRAYLANG['TXT_ID'], 'SHOP_PRODUCT_TOTALITEM' => self::get_item_count(), 'SHOP_PRODUCT_TOTALPRICE' => Currency::formatPrice(self::get_price()), 'SHOP_PRODUCT_TOTALPRICE_PLUS_VAT' => Currency::formatPrice(self::get_price() + (Vat::isEnabled() && !Vat::isIncluded() ? self::get_vat_amount() : 0)), 'SHOP_PRODUCT_TOTALPRICE_UNIT' => Currency::getActiveCurrencySymbol(), 'SHOP_TOTAL_WEIGHT' => Weight::getWeightString(self::get_weight()), 'SHOP_PRICE_UNIT' => Currency::getActiveCurrencySymbol()));
     // Show the Coupon code field only if there is at least one defined
     if (Coupon::count_available()) {
         //DBG::log("Coupons available");
         $objTemplate->setVariable(array('SHOP_DISCOUNT_COUPON_CODE' => isset($_SESSION['shop']['coupon_code']) ? $_SESSION['shop']['coupon_code'] : ''));
         if ($objTemplate->blockExists('shopCoupon')) {
             $objTemplate->parse('shopCoupon');
         }
         if (self::get_discount_amount()) {
             $total_discount_amount = self::get_discount_amount();
             //DBG::log("Shop::view_cart(): Total: Amount $total_discount_amount");
             $objTemplate->setVariable(array('SHOP_DISCOUNT_COUPON_TOTAL' => $_ARRAYLANG['TXT_SHOP_DISCOUNT_COUPON_AMOUNT_TOTAL'], 'SHOP_DISCOUNT_COUPON_TOTAL_AMOUNT' => Currency::formatPrice(-$total_discount_amount)));
         }
     }
     if (Vat::isEnabled()) {
         $objTemplate->setVariable(array('TXT_TAX_PREFIX' => Vat::isIncluded() ? $_ARRAYLANG['TXT_SHOP_VAT_PREFIX_INCL'] : $_ARRAYLANG['TXT_SHOP_VAT_PREFIX_EXCL'], 'SHOP_TOTAL_TAX_AMOUNT' => self::get_vat_amount() . '&nbsp;' . Currency::getActiveCurrencySymbol()));
         if (Vat::isIncluded()) {
             $objTemplate->setVariable(array('SHOP_GRAND_TOTAL_EXCL_TAX' => Currency::formatPrice(self::get_price() - self::get_vat_amount()) . '&nbsp;' . Currency::getActiveCurrencySymbol()));
         }
     }
     if (self::needs_shipment()) {
         $objTemplate->setVariable(array('TXT_SHIP_COUNTRY' => $_ARRAYLANG['TXT_SHIP_COUNTRY'], 'SHOP_COUNTRIES_MENU' => \Cx\Core\Country\Controller\Country::getMenu('countryId2', $_SESSION['shop']['countryId2'], true, "document.forms['shopForm'].submit()"), 'SHOP_COUNTRIES_MENUOPTIONS' => \Cx\Core\Country\Controller\Country::getMenuoptions($_SESSION['shop']['countryId2'])));
     }
     if (\Cx\Core\Setting\Controller\Setting::getValue('orderitems_amount_min', 'Shop') > 0 && \Cx\Core\Setting\Controller\Setting::getValue('orderitems_amount_min', 'Shop') > self::get_price()) {
         $objTemplate->setVariable('MESSAGE_TEXT', sprintf($_ARRAYLANG['TXT_SHOP_ORDERITEMS_AMOUNT_MIN'], Currency::formatPrice(\Cx\Core\Setting\Controller\Setting::getValue('orderitems_amount_min', 'Shop')), Currency::getActiveCurrencySymbol()));
     } elseif (\Cx\Core\Setting\Controller\Setting::getValue('orderitems_amount_max', 'Shop') > 0 && \Cx\Core\Setting\Controller\Setting::getValue('orderitems_amount_max', 'Shop') < self::get_price()) {
         $objTemplate->setVariable('MESSAGE_TEXT', sprintf($_ARRAYLANG['TXT_SHOP_ORDERITEMS_AMOUNT_MAX'], Currency::formatPrice(\Cx\Core\Setting\Controller\Setting::getValue('orderitems_amount_max', 'Shop')), Currency::getActiveCurrencySymbol()));
     } else {
         $objTemplate->setVariable('TXT_NEXT', $_ARRAYLANG['TXT_NEXT']);
     }
 }
Beispiel #3
0
 /**
  * Returns the first matching picture name found in the Products
  * within the Shop Category given by its ID.
  * @global  ADONewConnection  $objDatabase    Database connection object
  * @param type $category_id
  * @return  string                      The image name, or the
  *                                      empty string.
  * @static
  * @author  Reto Kohli <*****@*****.**>
  */
 static function getPictureByCategoryId($category_id)
 {
     global $objDatabase;
     $category_id = intval($category_id);
     $query = "\n            SELECT `picture`\n              FROM `" . DBPREFIX . "module_shop" . MODULE_INDEX . "_products`\n             WHERE FIND_IN_SET({$category_id}, `category_id`)\n               AND `picture`!=''\n             ORDER BY `ord` ASC";
     $objResult = $objDatabase->SelectLimit($query, 1);
     if ($objResult && $objResult->RecordCount() > 0) {
         // Got a picture
         $arrImages = Products::get_image_array_from_base64($objResult->fields['picture']);
         $imageName = $arrImages[1]['img'];
         return $imageName;
     }
     // No picture found here
     return '';
 }
Beispiel #4
0
 /**
  * Stores the posted Product, if any
  * @return  boolean           True on success, null on noop, false otherwise
  */
 static function store_product()
 {
     global $_ARRAYLANG;
     if (!isset($_POST['bstore'])) {
         return null;
     }
     $product_name = contrexx_input2raw($_POST['product_name']);
     $product_code = contrexx_input2raw($_POST['product_code']);
     // Multiple Categories
     $category_id = isset($_POST['shopCategoriesAssigned']) ? contrexx_input2raw(join(',', $_POST['shopCategoriesAssigned'])) : '';
     $customer_price = $_POST['customer_price'];
     $reseller_price = $_POST['reseller_price'];
     $discount_active = !empty($_POST['discount_active']);
     $discount_price = $_POST['discount_price'];
     //DBG::log("ShopManager::store_product(): customer_price $customer_price, reseller_price $reseller_price, discount_price $discount_price");
     $vat_id = $_POST['vat_id'];
     $short = contrexx_input2raw($_POST['short']);
     $long = contrexx_input2raw($_POST['long']);
     $stock = $_POST['stock'];
     $stock_visible = !empty($_POST['stock_visible']);
     $uri = contrexx_input2raw($_POST['uri']);
     $active = !empty($_POST['articleActive']);
     $b2b = !empty($_POST['B2B']);
     $b2c = !empty($_POST['B2C']);
     $date_start = contrexx_input2raw($_POST['date_start']);
     $date_end = contrexx_input2raw($_POST['date_end']);
     $manufacturer_id = isset($_POST['manufacturer_id']) ? contrexx_input2int($_POST['manufacturer_id']) : 0;
     $minimum_order_quantity = $_POST['minimum_order_quantity'];
     // Currently not used on the detail page
     //        $flags = (isset($_POST['Flags'])
     //                ? join(' ', $_POST['Flags']) : '');
     $distribution = $_POST['distribution'];
     // Different meaning of the "weight" field for downloads!
     // The getWeight() method will treat purely numeric values
     // like the validity period (in days) the same as a weight
     // without its unit and simply return its integer value.
     $weight = $distribution == 'delivery' ? Weight::getWeight($_POST['weight']) : $_POST['accountValidity'];
     // Assigned frontend groups for protected downloads
     $usergroup_ids = isset($_POST['groupsAssigned']) ? implode(',', $_POST['groupsAssigned']) : '';
     $discount_group_count_id = $_POST['discount_group_count_id'];
     $discount_group_article_id = $_POST['discount_group_article_id'];
     //DBG::log("ShopManager::store_product(): Set \$discount_group_article_id to $discount_group_article_id");
     $keywords = contrexx_input2raw($_POST['keywords']);
     for ($i = 1; $i <= 3; ++$i) {
         // Images outside the above directory are copied to the shop image folder.
         // Note that the image paths below do not include the document root, but
         // are relative to it.
         $picture = contrexx_input2raw($_POST['productImage' . $i]);
         // Ignore the picture if it's the default image!
         // Storing it would be pointless.
         // Images outside the above directory are copied to the shop image folder.
         // Note that the image paths below do not include the document root, but
         // are relative to it.
         if ($picture == self::$defaultImage || !self::moveImage($picture)) {
             $picture = '';
         }
         // Update the posted path (used below)
         $_POST['productImage' . $i] = $picture;
     }
     // add all to pictures DBstring
     $imageName = base64_encode($_POST['productImage1']) . '?' . base64_encode($_POST['productImage1_width']) . '?' . base64_encode($_POST['productImage1_height']) . ':' . base64_encode($_POST['productImage2']) . '?' . base64_encode($_POST['productImage2_width']) . '?' . base64_encode($_POST['productImage2_height']) . ':' . base64_encode($_POST['productImage3']) . '?' . base64_encode($_POST['productImage3_width']) . '?' . base64_encode($_POST['productImage3_height']);
     // Note that the flags of the Product *MUST NOT* be changed
     // when inserting or updating the Product data, as the original
     // flags are needed for their own update later.
     $objProduct = null;
     $product_id = intval($_POST['id']);
     if ($product_id) {
         $objProduct = Product::getById($product_id);
     }
     $new = false;
     if (!$objProduct) {
         $new = true;
         $objProduct = new Product($product_code, $category_id, $product_name, $distribution, $customer_price, $active, 0, $weight);
         if (!$objProduct->store()) {
             return \Message::error($_ARRAYLANG['TXT_SHOP_PRODUCT_ERROR_STORING']);
         }
         //            $product_id = $objProduct->id();
     }
     // Apply the changes to all Products with the same Product code.
     // Note: This is disabled for the time being, as virtual categories are, too.
     //        if ($product_code != '') {
     //            $arrProduct = Products::getByCustomId($product_code);
     //        } else {
     //            $arrProduct = array($objProduct);
     //        }
     //        if (!is_array($arrProduct)) return false;
     //        foreach ($arrProduct as $objProduct) {
     // Update each product
     $objProduct->code($product_code);
     // NOTE: Only change the parent ShopCategory for a Product
     // that is in a real ShopCategory.
     $objProduct->category_id($category_id);
     $objProduct->name($product_name);
     $objProduct->distribution($distribution);
     $objProduct->price($customer_price);
     $objProduct->active($active);
     // On the overview only: $objProduct->ord();
     $objProduct->weight($weight);
     $objProduct->resellerprice($reseller_price);
     $objProduct->discount_active($discount_active);
     $objProduct->discountprice($discount_price);
     $objProduct->vat_id($vat_id);
     $objProduct->short($short);
     $objProduct->long($long);
     $objProduct->stock($stock);
     $objProduct->minimum_order_quantity($minimum_order_quantity);
     $objProduct->stock_visible($stock_visible);
     $objProduct->uri($uri);
     $objProduct->b2b($b2b);
     $objProduct->b2c($b2c);
     $objProduct->date_start($date_start);
     $objProduct->date_end($date_end);
     $objProduct->manufacturer_id($manufacturer_id);
     $objProduct->pictures($imageName);
     // Currently not used on the detail page
     //                $objProduct->flags($flags);
     $objProduct->usergroup_ids($usergroup_ids);
     $objProduct->group_id($discount_group_count_id);
     $objProduct->article_id($discount_group_article_id);
     $objProduct->keywords($keywords);
     //DBG::log("ShopManager::store_product(): Product: reseller_price ".$objProduct->resellerprice());
     // Remove old Product Attributes.
     // They are re-added below.
     $objProduct->clearAttributes();
     // Add current product attributes
     if (isset($_POST['options']) && is_array($_POST['options'])) {
         foreach ($_POST['options'] as $valueId => $nameId) {
             $order = intval($_POST['productOptionsSortId'][$nameId]);
             $objProduct->addAttribute(intval($valueId), $order);
         }
     }
     // Mind that this will always be an *update*, see the call to
     // store() above.
     if (!$objProduct->store()) {
         return \Message::error($_ARRAYLANG['TXT_SHOP_PRODUCT_ERROR_STORING']);
     }
     //        }
     // Add/remove Categories and Products to/from
     // virtual ShopCategories.
     // Note that this *MUST* be called *AFTER* the Product is updated
     // or inserted.
     // Virtual categories are disabled for the time being
     //        Products::changeFlagsByProductCode(
     //            $product_code, $flags
     //        );
     $objImage = new \ImageManager();
     $arrImages = Products::get_image_array_from_base64($imageName);
     // Create thumbnails if not available, or update them
     foreach ($arrImages as $arrImage) {
         if (!empty($arrImage['img']) && $arrImage['img'] != ShopLibrary::noPictureName) {
             if (!$objImage->_createThumbWhq(\Cx\Core\Core\Controller\Cx::instanciate()->getWebsiteImagesShopPath() . '/', \Cx\Core\Core\Controller\Cx::instanciate()->getWebsiteImagesShopWebPath() . '/', $arrImage['img'], \Cx\Core\Setting\Controller\Setting::getValue('thumbnail_max_width', 'Shop'), \Cx\Core\Setting\Controller\Setting::getValue('thumbnail_max_height', 'Shop'), \Cx\Core\Setting\Controller\Setting::getValue('thumbnail_quality', 'Shop'))) {
                 \Message::error(sprintf($_ARRAYLANG['TXT_SHOP_COULD_NOT_CREATE_THUMBNAIL'], $arrImage['img']));
             }
         }
     }
     \Message::ok($new ? $_ARRAYLANG['TXT_DATA_RECORD_ADDED_SUCCESSFUL'] : $_ARRAYLANG['TXT_DATA_RECORD_UPDATED_SUCCESSFUL']);
     switch ($_POST['afterStoreAction']) {
         case 'newEmpty':
             \Cx\Core\Csrf\Controller\Csrf::redirect('index.php?cmd=Shop' . MODULE_INDEX . '&act=products&tpl=manage');
         case 'newTemplate':
             \Cx\Core\Csrf\Controller\Csrf::redirect('index.php?cmd=Shop' . MODULE_INDEX . '&act=products&tpl=manage&id=' . $objProduct->id() . '&new=1');
     }
     \Cx\Core\Csrf\Controller\Csrf::redirect('index.php?cmd=Shop' . MODULE_INDEX . '&act=products');
     // Never reached
     return true;
 }