/**
  * Returns Review info tag value
  */
 function getReviewTagValue($tag)
 {
     $output = '';
     // if productid is incorrect returns '' in any case
     if ($this->_productid_invalid) {
         return '';
     }
     switch ($tag) {
         case 'number':
             $output = modApiFunc('Customer_Reviews', 'getProductCustomerReviewNumber', $this->_productid);
             if (!$this->checkReviewAvail(6, 7)) {
                 $output = 0;
             }
             break;
         case 'averagerating':
             $output = modApiFunc('Customer_Reviews', 'getTotalProductRating', $this->_productid);
             $output = $output['total_rating'];
             if (!$this->checkReviewAvail(7)) {
                 $output = 0;
             }
             break;
         case 'link':
             $cid = modApiFunc('CProductListFilter', 'getCurrentCategoryId');
             $r = new Request();
             $r->setView('ProductInfo');
             $r->setAction('SetCurrentProduct');
             $r->setKey('prod_id', $this->_productid);
             $r->setProductID($this->_productid);
             $r->setCategoryID($cid);
             $r->setAnchor('customer_reviews_' . $this->_productid);
             return $r->getURL();
     }
     return $output;
 }
 /**
 * Gets complete product information with the id and returned as
 * associative array.<br>
 * It is used caching.
 * The array structure:
 * <code>
 * array(
 *   'attribute' => 'value' //  describe all attributes
 *  ,'attributes' => array (
 *     'attribute' => array (
 *      ,'id'       => // the attribute id
 *      ,'name'     => // the attribute name
 *      ,'size'     => // the input field size
 *      ,'min'      => // the min number of inputted characters
 *      ,'max'      => // the max number of inputted characters
 *      ,'view_tag' => // the attribute tag to use in the templates
 *      ,'group'    => array ( // info about the group, to which the
                                  attribute refers
 *         'id'   => // the id
 *        ,'name' => // the name
 *        ,'sort' => // the sorting number
 *       )
 *      ,'required' => // the flag the required input
 *      ,'visible'  => // the flag of the product visibility
 *      ,'default'  => // the default value on inputting
 *      ,'sort'     => // the sorting serial number
 *      ,'input_type_id'     => // the type id of input field
 *      ,'input_type_name'   => // the type name of input field
 *      ,'input_type_values' => array ( // ???
 *         'key' => 'value'
 *       )
 *      ,'unit_type_id'     => // the unit id
 *      ,'unit_type_name'   => // the unit name
 *      ,'unit_type_value'  => // the unit value
 *      ,'unit_type_values' => array ( // ???
 *         'key' => 'value'
 *       )
 *      ,'pa_id'    => // the attribute id for the specified product
 *      ,'value'    => // the attribute value for the specified product
 *     )
 *   )
 * )
 * </code>
 * @param integer $prod_id
 * @return array the array containing product info.
 * @see Catalog::getProductType()
 * @see Catalog::getProductTypeAttributes()
 */
 function getProductInfo($prod_id, $localized = true, $quantity = 1)
 {
     global $application;
     global $zone;
     if (!$this->isCorrectProductId($prod_id)) {
         return null;
     }
     $result = execQuery('SELECT_GENERAL_PRODUCT_ATTRIBUTES', array('prod_id' => $prod_id));
     if (sizeof($result) <= 0) {
         return null;
     }
     /**
      * Get real attribute values for the given product,
      * results are in $product_attributes.
      */
     $attr_result = execQuery('SELECT_REAL_PRODUCT_ATTRIBUTES', array('prod_id' => $prod_id));
     $product_attributes = array();
     for ($j = 0; $j < sizeof($attr_result); $j++) {
         $view_tag = $attr_result[$j]['view_tag'];
         $product_attributes[$view_tag] = $attr_result[$j];
     }
     //          SalePrice,
     //                                TaxClass.
     $tax_class_id = NULL;
     foreach ($product_attributes as $index => $attribute) {
         if (strtolower($index) == 'taxclass') {
             $tax_class_id = $product_attributes[$index]['value'];
             break;
         }
     }
     $price_including_included_taxes_if_any = NULL;
     foreach ($product_attributes as $index => $attribute) {
         if (strtolower($index) == 'saleprice') {
             if ($zone == 'CustomerZone') {
                 $membership = modApiFunc('Customer_Account', 'getCurrentSignedCustomerGroupID');
                 $fixed_price = modApiFunc('Quantity_Discounts', 'getFixedPrice', $prod_id, $quantity, $product_attributes[$index]['value'], $membership);
                 $product_attributes[$index]['value'] = $fixed_price;
             }
             $price_including_included_taxes_if_any = $product_attributes[$index]['value'];
             $product_attributes['salepriceexcludingtaxes'] = $product_attributes[$index];
             $product_attributes['salepriceexcludingtaxes']['id'] = NULL;
             $product_attributes['salepriceexcludingtaxes']['view_tag'] = NULL;
             //     TaxClass             -        ,                     .
             if ($tax_class_id !== NULL) {
                 //                                         .
                 $price_excluding_taxes = modApiFunc("Catalog", "computePriceExcludingTaxes", $product_attributes[$index]['value'], $tax_class_id, false, $quantity, $prod_id);
                 $product_attributes[$index]['value'] = $price_excluding_taxes;
                 //              _   _                         'salepriceexcludingtaxes':
                 $product_attributes['salepriceexcludingtaxes']['value'] = $price_excluding_taxes;
             }
             break;
         }
     }
     //          SalePrice,                               "          "       .
     //     TaxClass             -        ,                     .
     $display_product_price_including_taxes = modApiFunc('Settings', 'getParamValue', 'TAXES_PARAMS', "DISPLAY_PRICES_W_INCLUDED_TAXES");
     foreach ($product_attributes as $index => $attribute) {
         if (strtolower($index) == 'saleprice') {
             $product_attributes['salepriceincludingtaxes'] = $product_attributes[$index];
             $product_attributes['salepriceincludingtaxes']['id'] = NULL;
             $product_attributes['salepriceincludingtaxes']['view_tag'] = NULL;
             if ($tax_class_id !== NULL) {
                 //                                         .
                 $price_including_taxes = $price_including_included_taxes_if_any;
                 //                                             ,
                 //        ,             "          "
                 //modApiFunc("Catalog", "computePriceIncludingTaxes", $product_attributes[$index]['value'], $tax_class_id);
                 //              _c_                          'salepriceincludingtaxes':
                 $product_attributes['salepriceincludingtaxes']['value'] = $price_including_taxes;
                 if ($display_product_price_including_taxes == DB_TRUE) {
                     $product_attributes[$index]['value'] = $price_including_taxes;
                 }
             }
             break;
         }
     }
     $product = array();
     //the array of tags and their values
     $product['attributes'] = array();
     // add info with the artificial attributes
     $product['Updated'] = modApiFunc("Localization", "SQL_date_format", $result[0]['date_updated']);
     $product['Added'] = modApiFunc("Localization", "SQL_date_format", $result[0]['date_added']);
     $product['TypeID'] = $result[0]['type_id'];
     $product['TypeName'] = $result[0]['type_name'];
     //$product['Catalog_ID'] = $result[0]['catalog_id'];
     // define the attribute list or the given product type
     $product_type = $this->getProductType($result[0]['type_id']);
     // copy attributes to the product description
     foreach ($product_type['attr'] as $view_tag => $attr) {
         $product[$view_tag] = '';
         // initialize the attribute value.
         $product['attributes'][$view_tag] = array();
         $product_attribut =& $product['attributes'][$view_tag];
         $product_attribut['id'] = $attr['id'];
         $product_attribut['name'] = $attr['name'];
         $product_attribut['size'] = $attr['size'];
         $product_attribut['min'] = $attr['min'];
         $product_attribut['max'] = $attr['max'];
         $product_attribut['view_tag'] = $attr['view_tag'];
         $product_attribut['group'] = $attr['group'];
         $product_attribut['required'] = $attr['required'];
         $product_attribut['visible'] = $attr['visible'];
         $product_attribut['default'] = $attr['default'];
         $product_attribut['sort'] = $attr['sort'];
         $product_attribut['allow_html'] = $attr['allow_html'];
         $product_attribut['multilang'] = $attr['multilang'];
         $product_attribut['patt'] = $attr['patt'];
         $product_attribut['patt_type'] = $attr['patt_type'];
         $product_attribut['input_type_id'] = $attr['input_type_id'];
         $product_attribut['input_type_name'] = $attr['input_type_name'];
         $product_attribut['input_type_values'] = isset($attr['input_type_values']) ? $attr['input_type_values'] : null;
         $product_attribut['unit_type_value'] = $attr['unit_type_value'];
         $product_attribut['unit_type_values'] = isset($attr['unit_type_values']) ? $attr['unit_type_values'] : null;
         $product_attribut['unit_type_values_pattern'] = isset($attr['unit_type_values_pattern']) ? $attr['unit_type_values_pattern'] : null;
         $product_attribut['pa_id'] = null;
         $product_attribut['value'] = null;
         $product_attribut['additional_link'] = isset($attr['additional_link']) ? $attr['additional_link'] : "";
         $product_attribut['additional_link_text'] = isset($attr['additional_link_text']) ? $attr['additional_link_text'] : "";
         // add real attribute values for the given product
         if (!array_key_exists($view_tag, $product_attributes)) {
             $imagesUrl = $application->getAppIni('URL_IMAGES_DIR');
             if ($application->getCurrentProtocol() == "https" && $application->getAppIni('HTTPS_URL_IMAGES_DIR')) {
                 $imagesUrl = $application->getAppIni('HTTPS_URL_IMAGES_DIR');
             }
             if ($product_attribut['input_type_name'] == 'image') {
                 $product_attribut['value'] = array('url' => '', 'exists' => false, 'width' => 1, 'height' => 1);
                 // The image is not found. Output a standard one, if necessary.
                 $product[$view_tag] = '';
                 $product[$view_tag . 'Src'] = '';
                 //$imagesUrl.$product_attribut['value']['url'];
                 $product[$view_tag . 'Width'] = '1';
                 //$product_attribut['value']['width'];
                 $product[$view_tag . 'Height'] = '1';
                 //$product_attribut['value']['height'];
             }
         } else {
             //  the id is in the product_attributes table
             $product_attribut['pa_id'] = $product_attributes[$view_tag]['id'];
             // the attribute value
             $product_attribut['value'] = $product_attributes[$view_tag]['value'];
             if (!$product_attribut['allow_html'] && $localized) {
                 // Correct, because the HTML code is unavailable.
                 $product_attribut['value'] = prepareHTMLDisplay($product_attributes[$view_tag]['value']);
             }
             if ($localized) {
                 $product[$view_tag] = modApiFunc("Localization", "format", $product_attribut['value'], $product_attribut['patt_type']);
             } else {
                 $product[$view_tag] = $product_attribut['value'];
             }
             // determine the URL of the image  remove it later
             if ($product_attribut['input_type_name'] == 'image') {
                 $imagesUrl = $application->getAppIni('URL_IMAGES_DIR');
                 if ($application->getCurrentProtocol() == "https" && $application->getAppIni('HTTPS_URL_IMAGES_DIR')) {
                     $imagesUrl = $application->getAppIni('HTTPS_URL_IMAGES_DIR');
                 }
                 if ($product_attributes[$view_tag]['image_name'] != null && $application->isImageFileValid($product_attributes[$view_tag]['image_name'])) {
                     $product_attribut['value'] = array('url' => $product_attributes[$view_tag]['image_name'], 'exists' => true, 'width' => $product_attributes[$view_tag]['image_width'], 'height' => $product_attributes[$view_tag]['image_height']);
                 } else {
                     $product_attribut['value'] = array('url' => '', 'exists' => false, 'width' => 1, 'height' => 1);
                 }
                 // generate the values for the derived image attributes
                 if ($product_attribut['value']['exists']) {
                     $product[$view_tag] = '<img src="' . $imagesUrl . $product_attribut['value']['url'] . '" width="' . $product_attribut['value']['width'] . '" height="' . $product_attribut['value']['height'] . '" alt="' . $product_attributes['ImageAltText']['value'] . '"/>';
                     $product[$view_tag . 'Src'] = $imagesUrl . $product_attribut['value']['url'];
                     $product[$view_tag . 'Width'] = $product_attribut['value']['width'];
                     $product[$view_tag . 'Height'] = $product_attribut['value']['height'];
                 } else {
                     $product[$view_tag] = '';
                     $product[$view_tag . 'Src'] = '';
                     $product[$view_tag . 'Width'] = '1';
                     $product[$view_tag . 'Height'] = '1';
                 }
             }
             // add the Unit value, if it exists
             if ($product_attribut['patt_type'] != 'currency' && $product_attribut['unit_type_value']) {
                 $product[$view_tag] .= ' ' . $product_attribut['unit_type_value'];
             }
             // Correct the attribute value, if it is specified input_type for it.
             if (isset($product_attribut['input_type_values']) && $product_attribut['value'] != '') {
                 $product[$view_tag] = $product_attribut['input_type_values'][$product_attributes[$view_tag]['value']];
             }
         }
         // if the attribute is not visible, delete values for CZ.
         if (!$attr['visible']) {
             $product[$view_tag] = '';
         }
     }
     // image for Gift Certificate
     if ($product['TypeID'] == -1) {
         $imageInfo = modApiFunc('GiftCertificateApi', 'getImageInfo');
         if ($imageInfo['largeimage']['is_exist'] === true) {
             $product['LargeImage'] = "<img src='" . $imageInfo['largeimage']['url'] . "' width='" . $imageInfo['largeimage']['width'] . "' height='" . $imageInfo['largeimage']['height'] . "' alt='' />";
             $product['LargeImageSrc'] = $imageInfo['largeimage']['url'];
             $product['LargeImageWidth'] = $imageInfo['largeimage']['width'];
             $product['LargeImageHeight'] = $imageInfo['largeimage']['height'];
         }
         if ($imageInfo['smallimage']['is_exist'] === true) {
             $product['SmallImage'] = "<img src='" . $imageInfo['smallimage']['url'] . "' width='" . $imageInfo['smallimage']['width'] . "' height='" . $imageInfo['smallimage']['height'] . "' alt='' />";
             $product['SmallImageSrc'] = $imageInfo['smallimage']['url'];
             $product['SmallImageWidth'] = $imageInfo['smallimage']['width'];
             $product['SmallImageHeight'] = $imageInfo['smallimage']['height'];
         }
     }
     $product['ID'] = $result[0]['id'];
     $product['attributes']['ID']['value'] = $result[0]['id'];
     $product['Name'] = $localized ? prepareHTMLDisplay($result[0]['name']) : $result[0]['name'];
     $product['attributes']['Name']['value'] = $localized ? prepareHTMLDisplay($result[0]['name']) : $result[0]['name'];
     $product['salepriceincludingtaxes'] = $localized ? modApiFunc("Localization", "format", $product_attributes['salepriceincludingtaxes']['value'], 'currency') : $product_attributes['salepriceincludingtaxes']['value'];
     //                         .     SalePrice.
     $product['attributes']['salepriceincludingtaxes']['value'] = $product_attributes['salepriceincludingtaxes']['value'];
     $product['salepriceexcludingtaxes'] = $localized ? modApiFunc("Localization", "format", $product_attributes['salepriceexcludingtaxes']['value'], 'currency') : $product_attributes['salepriceexcludingtaxes']['value'];
     //                         .     SalePrice.
     $product['attributes']['salepriceexcludingtaxes']['value'] = $product_attributes['salepriceexcludingtaxes']['value'];
     #  create required references
     ### InfoLink
     $request = new Request();
     $request->setView('ProductInfo');
     $request->setAction('SetCurrentProduct');
     $request->setKey('prod_id', $product['ID']);
     //$request->setCategoryID($product['Catalog_ID']);
     $request->setProductID($product['ID']);
     $_cProductInfo = new CProductInfo($product['ID']);
     $product['InfoLink'] = $_cProductInfo->getProductTagValue('InfoLink');
     ### BuyLink
     $request = new Request();
     modApiFunc("Configuration", "getValue", "store_show_cart") ? $request->setView('CartContent') : $request->setView(CURRENT_REQUEST_URL);
     $request->setAction('AddToCart');
     $request->setKey('prod_id', $product['ID']);
     //$request->setCategoryID($product['Catalog_ID']);
     $request->setProductID($product['ID']);
     $product['BuyLink'] = $request->getURL();
     ### CategoryLink.
     /*
     $request = new Request();
     $request->setView('ProductList');
     $request->setAction( "SetCurrCat" );
     $request->setKey   ( "category_id", $product['Catalog_ID']);
     $request->setCategoryID($product['Catalog_ID']);
     $request->setProductID($product['ID']);
     $product['CategoryLink'] = $request->getURL();
     */
     #                  .                       view                                                          .
     $prodObj = new CProductInfo($product['ID']);
     $product['CategoryLink'] = $prodObj->getProductTagValue('CategoryLink');
     $product['CategoryID'] = $prodObj->getProductTagValue('CategoryID');
     return $product;
 }
 function getProductInfoLink($prod_id)
 {
     $cid = modApiFunc('CProductListFilter', 'getCurrentCategoryId');
     $r = new Request();
     $r->setView('ProductInfo');
     $r->setAction('SetCurrentProduct');
     $r->setKey('prod_id', $prod_id);
     $r->setProductID($prod_id);
     $r->setCategoryID($cid);
     return $r->getURL();
 }
 /**
  * Returns the page links line.
  *
  * @return string paginator view in the type of paginal references
  * @ finish the functions on this page
  */
 function output($pag_name, $viewname, $cat_id = -1, $prod_id = -1)
 {
     global $application;
     $viewname = CURRENT_REQUEST_URL;
     #Define whether to output the view or not
     if ($this->NoView) {
         $application->outputTagErrors(true, "PaginatorLine", "Errors");
         return "";
     }
     $this->templateFiller =& $application->getInstance('TemplateFiller');
     $this->template = $application->getBlockTemplate('PaginatorLine');
     $this->templateFiller->setTemplate($this->template);
     $retval = '';
     //Output a paginator view with the page number,
     //form the link of the type ?action=setpage&pgname=$pag_name&pgnum=$i
     $rows_per_page = modAPIFunc('Paginator', 'getPaginatorRowsPerPage', $pag_name);
     if (!$rows_per_page) {
         $rows_per_page = ROWS_PER_PAGE;
     }
     $pages = ceil(modAPIFunc('Paginator', 'getCurrentPaginatorTotalRows') / $rows_per_page);
     $lines = ceil($pages / PAGES_PER_LINE);
     $currentpage = modAPIFunc('Paginator', 'getPaginatorPage', $pag_name);
     $currentrows = modAPIFunc('Paginator', 'getPaginatorRowsPerPage', $pag_name);
     $currentline = ceil($currentpage / PAGES_PER_LINE);
     //$firstpageinline = ($currentline - 1)*PAGES_PER_LINE+1;
     $lastpageinline = $currentline * PAGES_PER_LINE;
     if ($lastpageinline > $pages) {
         $lastpageinline = $pages;
     }
     $firstpageinline = $lastpageinline - PAGES_PER_LINE + 1;
     if ($firstpageinline <= 0) {
         $firstpageinline = 1;
     }
     $this->_Data = array('Local_Items' => '', 'Local_From' => '', 'Local_To' => '', 'Local_Of' => '', 'Local_CurrentPage' => '', 'Local_PagesQty' => '', 'Local_ViewAll' => '');
     $request = new Request();
     $request->setView($viewname);
     $request->setAction('Paginator_SetPage');
     $request->setKey('pgname', $pag_name);
     $request->setKey('pgnum', $currentpage - 1);
     $request->setCategoryID($cat_id);
     $request->setProductID($prod_id);
     $this->_Data = array_merge($this->_Data, array('Local_PageLink' => $request->getURL(), 'Local_PageNumber' => ''));
     $retval = '';
     $paginator_line = '';
     if ($currentpage != 1) {
         $application->registerAttributes($this->_Data);
         $paginator_line .= $this->templateFiller->fill("Prev");
     }
     if ($firstpageinline != 1) {
         $paginator_line .= CZ_getMsg("PAGINATOR_DOTS");
     }
     for ($i = $firstpageinline; $i <= $lastpageinline; $i++) {
         $request = new Request();
         $request->setView($viewname);
         $request->setAction('Paginator_SetPage');
         $request->setKey('pgname', $pag_name);
         $request->setKey('pgnum', $i);
         $request->setCategoryID($cat_id);
         $this->_Data = array_merge($this->_Data, array('Local_PageLink' => $request->getURL(), 'Local_PageNumber' => $i));
         $application->registerAttributes($this->_Data);
         if ($i == $currentpage) {
             $paginator_line .= $this->templateFiller->fill("ItemSelected");
         } else {
             $paginator_line .= $this->templateFiller->fill("Item");
         }
     }
     if ($lastpageinline != $pages) {
         $paginator_line .= CZ_getMsg("PAGINATOR_DOTS");
     }
     $request = new Request();
     $request->setView($viewname);
     $request->setAction('Paginator_SetPage');
     $request->setKey('pgname', $pag_name);
     $request->setKey('pgnum', $currentpage + 1);
     $request->setCategoryID($cat_id);
     $this->_Data = array_merge($this->_Data, array('Local_PageLink' => $request->getURL(), 'Local_PageNumber' => ''));
     if ($currentpage != $pages && $pages != 0) {
         $paginator_line .= $this->templateFiller->fill("Next");
     }
     $request = new Request();
     $request->setView($viewname);
     $request->setAction('Paginator_SetRowsPerPage');
     $request->setKey('pgname', $pag_name);
     $request->setKey('rows', modAPIFunc('Paginator', 'getCurrentPaginatorTotalRows'));
     $request->setCategoryID($cat_id);
     $to = $currentpage * $rows_per_page;
     $total_rows = modAPIFunc('Paginator', 'getCurrentPaginatorTotalRows');
     if ($to > $total_rows) {
         $to = $total_rows;
     }
     $this->_Data = array_merge($this->_Data, array('Local_Items' => $pages > 1 ? $paginator_line : "", 'Local_From' => ($currentpage - 1) * $rows_per_page + 1, 'Local_To' => $to, 'Local_Of' => $total_rows, 'Local_CurrentPage' => $currentpage, 'Local_PagesQty' => $pages, 'Local_ViewAll' => $request->getURL()));
     $application->registerAttributes($this->_Data);
     if ($pages > 1) {
         $retval = $this->templateFiller->fill("Container");
     } else {
         $retval = $this->templateFiller->fill("Empty");
     }
     //        $retval = $this->templateFiller->fill("Container");
     return $retval;
 }
 /**
  * Adds the product to the cart.
  */
 function onAction()
 {
     global $application;
     $request = $application->getInstance('Request');
     if ($request->getValueByKey('returning') == 'yes' && modApiFunc('Session', 'is_Set', 'WishlistData')) {
         // for returning customers reading the data from the session
         $data = modApiFunc('Session', 'get', 'WishlistData');
         modApiFunc('Session', 'un_Set', 'WishlistData');
     } else {
         $prod_id = $request->getValueByKey('prod_id');
         $data = array('parent_entity' => 'product', 'entity_id' => $prod_id, 'options' => $request->getValueByKey('po'), 'qty' => $request->getValueByKey('quantity_in_cart'));
         // setting qty = 1 if not specified
         if (!$data['qty'] && $data['qty'] !== 0) {
             $data['qty'] = 1;
         }
         $options_sent = $request->getValueByKey('options_sent');
         $data['options_sent'] = $options_sent;
         if ($data['options'] == null) {
             $data['options'] = array();
         }
     }
     // if customer is not logged in keeping the data in session and
     // force customer to login...
     if (!modApiFunc('Customer_Account', 'getCurrentSignedCustomer')) {
         modApiFunc('Session', 'set', 'WishlistData', $data);
         $request = new Request();
         $request->setView(CURRENT_REQUEST_URL);
         $request->setAction('AddToWishlist');
         $request->setKey('returning', 'yes');
         modApiFunc('Session', 'set', 'toURLAfterSignIn', $request->getURL());
         $request = new Request();
         $request->setView('CustomerAccountHome');
         $application->redirect($request);
         return;
     }
     $wl_content = modApiFunc('Wishlist', 'getWishlistContent');
     if (is_array($wl_content)) {
         foreach ($wl_content as $wl) {
             if ($wl['ID'] == $data['entity_id'] && $this->compareOptions($data['options'], $wl['Options'])) {
                 modApiFunc('Wishlist', 'updateWishlistRecord', $wl['wl_id'], $wl['Quantity_In_Cart'] + $data['qty']);
                 $request = new Request();
                 $request->setView(CURRENT_REQUEST_URL);
                 $application->redirect($request);
                 return;
             }
         }
     }
     $result = modApiFunc('Cart', 'processPostedProductData', $data, $data['options_sent'], false);
     if (!$result['is_error']) {
         if (!empty($result['stock_discarded_by_warning'])) {
             modApiFunc('Session', 'set', 'StockDiscardedBy', $result['stock_discarded_by_warning']);
         }
         modApiFunc('Wishlist', 'addToWishlist', $result['data']);
         $request = new Request();
         $request->setView(CURRENT_REQUEST_URL);
         $application->redirect($request);
     } else {
         if ($result['discard_by'] != 'none') {
             modApiFunc('Session', 'set', 'OptionsDiscardedBy', $result['discard_by']);
         }
         if ($result['stock_discarded_by'] != 'none') {
             modApiFunc('Session', 'set', 'StockDiscardedBy', $result['stock_discarded_by']);
         }
         modApiFunc('Session', 'set', 'sentCombination', $result['data']['options']);
         $request = new Request();
         $request->setView('ProductInfo');
         $request->setAction('SetCurrentProduct');
         $request->setKey('prod_id', $prod_id);
         $request->setProductID($prod_id);
         $p = new CProductInfo($prod_id);
         $request->setCategoryID($p->chooseCategoryID());
         $application->redirect($request);
     }
 }
 function getProductInfoLink($product_id, $category_id)
 {
     global $zone;
     if ($zone == 'CustomerZone') {
         $request = new Request();
         $product_type_id = $this->getProductTagValue("TypeID");
         if ($product_type_id == GC_PRODUCT_TYPE_ID) {
             $request->setView('GiftCertificate');
             return $request->getURL();
         }
         $request->setView('ProductInfo');
         $request->setAction('SetCurrentProduct');
         $request->setKey('prod_id', $product_id);
         $request->setCategoryID($category_id);
         $request->setProductID($product_id);
         return $request->getURL();
     } else {
         $request = new Request();
         $request->setView('Catalog_EditProduct');
         $request->setAction('SetCurrentProduct');
         $request->setKey('prod_id', $product_id);
         $request->setCategoryID($category_id);
         $request->setProductID($product_id);
         return $request->getURL();
     }
 }
 /**
  * Adds the product to the cart.
  */
 function onAction()
 {
     global $application;
     $request = $application->getInstance('Request');
     $msgres = $application->getInstance("MessageResources", "messages");
     // checking if wishlist product is being added
     $wl_id = $request->getValueByKey('wl_id');
     if ($wl_id > 0) {
         $data = modApiFunc('Wishlist', 'getWishlistRecordCartData', $wl_id);
         if (!$data) {
             // invalid wishlist record...
             $request = new Request();
             $request->setView('Wishlist');
             $application->redirect($request);
             $this->setStatusError();
             $this->setMessage('Invalid wishlist record');
         }
         $options_sent = $data['options_sent'];
         $prod_id = $data['entity_id'];
     } else {
         $prod_id = $request->getValueByKey('prod_id');
         $data = array('parent_entity' => 'product', 'entity_id' => $prod_id, 'options' => $request->getValueByKey('po'), 'qty' => $request->getValueByKey('quantity_in_cart'), 'colorname' => $request->getValueByKey('colorname'));
         $options_sent = $request->getValueByKey('options_sent');
     }
     // setting qty=1 if quantity_in_stock is not specified
     if (!$data['qty'] && $data['qty'] !== 0) {
         $data['qty'] = 1;
     }
     if ($data['options'] == null) {
         $data['options'] = array();
     }
     $result = modApiFunc('Cart', 'processPostedProductData', $data, $options_sent);
     if (!$result['is_error']) {
         if (!empty($result['stock_discarded_by_warning'])) {
             modApiFunc('Session', 'set', 'StockDiscardedBy', $result['stock_discarded_by_warning']);
         }
         $added = modApiFunc('Cart', 'addToCart', $result['data']);
         $cc = modApiFunc('Cart', 'getCartContent');
         $cartPrice = '';
         $cart_id = $prod_id . "_" . modApiFunc("Product_Options", "getCombinationHash", $result['data']['options']);
         if (!empty($cc)) {
             foreach ($cc as $product) {
                 if ($product["CartID"] == $cart_id) {
                     $cartPrice = modApiFunc("Localization", "format", $product["CartItemSalePrice"], "currency");
                 }
             }
         }
         $this->setStatusSuccess();
         $p = new CProductInfo($prod_id);
         $message = array("<h2>" . $msgres->getMessage('CATALOG_PRODUCT_ADDED') . "</h2>" . "<div class='ajax_message_cart_prod_link'><a href='" . $p->getProductInfoLink($prod_id, $p->chooseCategoryID()) . "'>" . $p->getProductTagValue('name') . "</a></div>" . "<div class='ajax_message_cart_prod_qty'>" . $data['qty'] . "&nbsp;" . $msgres->getMessage('CATALOG_X') . "&nbsp;" . $cartPrice . "</div>");
         // if a wishlist product is being added...
         if ($wl_id > 0 && $added) {
             modApiFunc('Wishlist', 'removeFromWishlist', $wl_id);
             $message[] = 'This product was removed from your Wishlist';
         }
         $this->setMessage($message);
         $request = new Request();
         $request->setView(CURRENT_REQUEST_URL);
         $application->redirect($request);
     } else {
         $this->setStatusError();
         $message = array();
         if ($result['discard_by'] != 'none') {
             modApiFunc('Session', 'set', 'OptionsDiscardedBy', $result['discard_by']);
             $message[] = $msgres->getMessage($result['discard_by']);
         }
         if ($result['stock_discarded_by'] != 'none') {
             modApiFunc('Session', 'set', 'StockDiscardedBy', $result['stock_discarded_by']);
             $message[] = $msgres->getMessage($result['stock_discarded_by']);
         }
         modApiFunc('Session', 'set', 'sentCombination', $result['data']['options']);
         $this->setMessage($message);
         $request = new Request();
         $request->setView('ProductInfo');
         $request->setAction('SetCurrentProduct');
         $request->setKey('prod_id', $prod_id);
         $request->setProductID($prod_id);
         $p = new CProductInfo($prod_id);
         $request->setCategoryID($p->chooseCategoryID());
         $application->redirect($request);
     }
 }
 /**
  * Generates the link for menu item
  */
 function getMenuItemLink($item)
 {
     global $application;
     $result = '';
     switch ($item['item_type']) {
         case CMS_MENU_ITEM_TYPE_TEXT:
             $result = '';
             break;
         case CMS_MENU_ITEM_TYPE_URL:
         case CMS_MENU_ITEM_TYPE_EXTERNAL_URL:
             $result = $item['item_link'];
             break;
         case CMS_MENU_ITEM_TYPE_STATIC_PAGE:
             loadClass('CCMSPageInfo');
             $CMSPage = new CCMSPageInfo($item['item_link']);
             $result = $CMSPage->getCMSPageTagValue('link', array());
             break;
         case CMS_MENU_ITEM_TYPE_SYSTEM_PAGE:
             $r = new Request();
             $r->setView($application->getViewBySection($item['item_link']));
             if (_ml_strtolower($item['item_link']) == 'productlist') {
                 $r->setCategoryID($item['param1']);
                 $r->setAction('SetCurrCat');
                 $r->setKey('category_id', $item['param1']);
             }
             if (_ml_strtolower($item['item_link']) == 'productinfo') {
                 loadClass('CProductInfo');
                 $pr = new CProductInfo($item['param2']);
                 $item['param1'] = $pr->chooseCategoryID();
                 $r->setCategoryID($item['param1']);
                 $r->setProductID($item['param2']);
                 $r->setAction('SetCurrentProduct');
                 $r->setKey('prod_id', $item['param2']);
                 $r->setKey('category_id', $item['param1']);
             }
             $result = $r->getURL();
             break;
     }
     return $result;
 }
 function getLocalLink($prod_id)
 {
     if ($this->_view == CURRENT_REQUEST_URL) {
         return '#add_review_' . $prod_id;
     }
     $cid = modApiFunc('CProductListFilter', 'getCurrentCategoryId');
     $r = new Request();
     $r->setView($this->_view);
     $r->setAction('SetCurrentProduct');
     $r->setKey('prod_id', $prod_id);
     $r->setProductID($prod_id);
     $r->setCategoryID($cid);
     $r->setAnchor('add_review_' . $prod_id);
     return $r->getURL();
 }