function outputFsRuleEffectiveAreaDetails($affected, $cat_num, $prod_num)
 {
     global $application;
     if ($cat_num == 0 && $prod_num == 0) {
         return '';
     }
     $cat_list = array();
     $cat_str = '';
     if ($cat_num != 0) {
         loadClass("CCategoryInfo");
         foreach ($affected['cats'] as $cat) {
             $obj = new CCategoryInfo($cat);
             // CCategoryInfo::isCategoryIdCorrect() does not exist
             if ($obj->_fCategoryIDIsIncorrect !== true) {
                 $cat_list[] = $obj->getCategoryTagValue('Name');
             }
         }
         $cat_str = implode('<br />', $cat_list);
     }
     $prod_list = array();
     $prod_str = '';
     if ($prod_num != 0) {
         loadClass("CProductInfo");
         foreach ($affected['prods'] as $prod) {
             $obj = new CProductInfo($prod);
             if ($obj->isProductIdCorrect()) {
                 $prod_list[] = $obj->getProductTagValue('Name');
             }
         }
         $prod_str = implode('<br />', $prod_list);
     }
     $this->_Template_Contents = array("CategoriesAffectedList" => $cat_str, "ProductsAffectedList" => $prod_str);
     $application->registerAttributes($this->_Template_Contents);
     return $this->mTmplFiller->fill("shipping_cost_calculator/edit_fs_rule/", "fs_rule_effective_area_details.tpl.html", array());
 }
 function out_ProductList()
 {
     $html_code = '';
     if (!empty($this->affected['prods'])) {
         global $application;
         foreach ($this->affected['prods'] as $pr_id) {
             $obj = new CProductInfo($pr_id);
             if ($obj->isProductIdCorrect()) {
                 $tags = array('ProductID' => $pr_id, 'ProductName' => $obj->getProductTagValue('Name'), 'jsControlPListFunc' => ' ' . str_replace(array('%PID%'), array($pr_id), $this->pb_obj->getControlPListFunction()));
                 $this->_Template_Contents = $tags;
                 $application->registerAttributes($this->_Template_Contents);
                 $this->mTmplFiller =& $application->getInstance('TmplFiller');
                 $html_code .= $this->mTmplFiller->fill("shipping_cost_calculator/edit_fs_rule_area/", "prod_item.tpl.html", array());
             }
         }
     }
     return $html_code;
 }
 function getTag($tag)
 {
     global $application;
     $value = null;
     switch ($tag) {
         case 'Local_AddPromoCode_URL':
             $request = new Request();
             $request->setView(CURRENT_REQUEST_URL);
             $request->setAction('AddPromoCode');
             #$request->setKey( 'promo_code', '' );
             $value = $request->getURL();
             break;
         case 'Local_AddPromoCode_Error':
             $AddPromoCodeError = modApiFunc("PromoCodes", "getAddPromoCodeError");
             modApiFunc("PromoCodes", "setAddPromoCodeError", "");
             if (!empty($AddPromoCodeError)) {
                 $value = getMsg('SYS', $AddPromoCodeError);
             } else {
                 $value = "";
             }
             break;
         case 'Local_RemovePromoCode_URL':
             $request = new Request();
             $request->setView(CURRENT_REQUEST_URL);
             $request->setAction('RemovePromoCode');
             $value = $request->getURL();
             break;
         case 'Local_PromoCode':
             $value = '';
             if ($this->pc_info !== false) {
                 $value = prepareHTMLDisplay($this->pc_info["promo_code"]);
             }
             break;
         case 'Local_PromoCodeDiscountedItemsListForCZ':
             $value = '';
             if ($this->pc_info !== false && $this->applicable === true) {
                 $home_present = false;
                 $cat_names = array();
                 $prod_names = array();
                 if ($this->pc_info['cats'] != null) {
                     $cats = explode('|', $this->pc_info['cats']);
                     foreach ($cats as $cid) {
                         $cat_obj = new CCategoryInfo($cid);
                         if ($cat_obj->_fCategoryIDIsIncorrect === true) {
                             continue;
                         }
                         // Home category present, we do not need anything else
                         if ($cid == 1) {
                             $home_present = true;
                             $cat_names = array();
                             $cat_names[] = cz_getMsg('PROMOCODE_HOME_CATEGORY_NAME_SUBST');
                             break;
                         } else {
                             $cat_names[] = $cat_obj->getCategoryTagValue('Name');
                         }
                     }
                 }
                 if ($this->pc_info['prods'] != null && !$home_present) {
                     $prods = explode('|', $this->pc_info['prods']);
                     foreach ($prods as $pid) {
                         $obj = new CProductInfo($pid);
                         if (!$obj->isProductIdCorrect()) {
                             continue;
                         }
                         $prod_names[] = $obj->getProductTagValue('Name');
                     }
                 }
                 if ($cat_names) {
                     $cat_names_str = implode(', ', $cat_names);
                     if ($home_present) {
                         $value .= $cat_names_str;
                     } else {
                         if (count($cat_names) == 1) {
                             $value .= cz_getMsg("PROMOCODE_CATEGORY_LABEL") . $cat_names_str;
                         } else {
                             $value .= cz_getMsg("PROMOCODE_CATEGORIES_LABEL") . $cat_names_str;
                         }
                     }
                     if ($prod_names) {
                         $value .= cz_getMsg("PROMOCODE_AND_LABEL");
                     }
                 }
                 if ($prod_names) {
                     $prod_names_str = implode(', ', $prod_names);
                     if (count($prod_names) == 1) {
                         $value .= cz_getMsg("PROMOCODE_PRODUCT_LABEL") . $prod_names_str;
                     } else {
                         $value .= cz_getMsg("PROMOCODE_PRODUCTS_LABEL") . $prod_names_str;
                     }
                 }
             }
             break;
         case 'Local_PromoCodeMinSubtotal':
             $value = '';
             if ($this->pc_info !== false && $this->applicable === true && $this->pc_info["min_subtotal"] != 0) {
                 $min_subtotal = modApiFunc("Localization", "currency_format", $this->pc_info["min_subtotal"]);
                 $value = str_replace('{MINSUBTOTAL}', $min_subtotal, cz_getMsg('PROMOCODE_MINSUBTOTAL_NEEDED'));
             }
             break;
         case 'Local_PromoCodeDiscount':
             $value = '';
             if ($this->pc_info !== false && $this->applicable === true) {
                 $o_subtotal = modApiFunc("Checkout", "getOrderPrice", "Subtotal", modApiFunc("Localization", "getMainStoreCurrency"));
                 $value = modApiFunc("Localization", "currency_format", modApiFunc("PromoCodes", "getPromoCodeDiscount", $o_subtotal, modApiFunc("PromoCodes", "getPromoCodeId"), array()));
             }
             if ($value == "") {
                 $value = modApiFunc("Localization", "currency_format", PRICE_N_A);
             }
             break;
         case 'Local_PromoCodeDiscountText':
             //        "10%"     "$2"          ,
             //               .
             $value = "";
             if ($this->pc_info !== false && $this->applicable === true) {
                 switch ($this->pc_info["discount_cost_type_id"]) {
                     case 1:
                         $value = modApiFunc("Localization", "currency_format", $this->pc_info["discount_cost"]);
                         break;
                     case 2:
                         $value = modApiFunc("Localization", "num_format", $this->pc_info["discount_cost"]) . "%";
                         break;
                     default:
                         //: report error.
                         exit(1);
                 }
             }
             break;
         case 'Local_PromoCodeStrictCartAttitude':
             $value = '';
             if ($this->pc_info && $this->pc_info['strict_cart'] == PROMO_CODE_STRICT_CART) {
                 // get product IDs and their categories' IDs
                 $prod = $coupon_cart = array();
                 $promo_codes = $application->getInstance('PromoCodes');
                 $order_cart = modApiFunc("Cart", "getCartContentExt");
                 foreach ($order_cart as $product) {
                     $coupon_cart[] = array('id' => $product["ID"], 'cat' => $product['CategoryID'], 'total' => $product['TotalExcludingTaxes']);
                 }
                 // coupon not applicable due to not meeting coupon conditions
                 if (false == $promo_codes->isPromoCodeAreaApplicable($this->pc_info, $coupon_cart)) {
                     $value = cz_getMsg('PROMOCODE_STRICT_CART_NEEDED');
                 }
             }
             break;
         case 'Local_PromoCodeShippingAttitude':
             $value = '';
             if ($this->pc_info !== false && $this->applicable === true) {
                 if ($this->pc_info['free_shipping'] == PROMO_CODE_FORBIDS_FREE_SHIPPING) {
                     $value = cz_getMsg('PROMOCODE_FREE_SHIPPING_FORBIDDEN');
                 } else {
                     if ($this->pc_info['free_shipping'] == PROMO_CODE_GRANTS_FREE_SHIPPING) {
                         $value = cz_getMsg('PROMOCODE_FREE_SHIPPING_GRANTED');
                     }
                 }
             }
             break;
         case 'Local_PromoCodeHandlingAttitude':
             $value = '';
             if ($this->pc_info !== false && $this->applicable === true) {
                 if ($this->pc_info['free_handling'] == PROMO_CODE_FORBIDS_FREE_HANDLING) {
                     $value = cz_getMsg('PROMOCODE_FREE_HANDLING_FORBIDDEN');
                 } else {
                     if ($this->pc_info['free_handling'] == PROMO_CODE_GRANTS_FREE_HANDLING) {
                         $value = cz_getMsg('PROMOCODE_FREE_HANDLING_GRANTED');
                     }
                 }
             }
             break;
         case 'Local_PromoCodeGlobalDiscountIgnored':
             $value = '';
             if ($this->pc_info !== false && $this->applicable === true) {
                 if ($this->pc_info['b_ignore_other_discounts'] == 1) {
                     // ignore global discount
                     $value = cz_getMsg('PROMOCODE_GLOBAL_DISCOUNT_IGNORED');
                 }
             }
             break;
         default:
             $value = NULL;
             break;
     }
     return $value;
 }
 /**
  * Updates the cart contents.
  */
 function onAction()
 {
     global $application;
     $request = $application->getInstance('Request');
     $msgres = $application->getInstance("MessageResources", "messages");
     $cart_id = $request->getValueByKey('cart_id');
     $quantity_in_cart = $request->getValueByKey('quantity_in_cart');
     if (!is_array($cart_id)) {
         $cart_id = array(0 => $cart_id);
     }
     if (!is_array($quantity_in_cart)) {
         $quantity_in_cart = array(0 => $quantity_in_cart);
     }
     if (is_array($cart_id)) {
         for ($i = 0; $i < sizeof($cart_id); $i++) {
             $obj_cart =& $application->getInstance('Cart');
             if (!isset($obj_cart->CartContent[$cart_id[$i]])) {
                 continue;
             }
             $quantity_in_cart[$i] *= 1;
             if (is_int($quantity_in_cart[$i]) && $quantity_in_cart[$i] > 0 && is_string($cart_id[$i]) && _ml_strlen($cart_id[$i]) > 2) {
                 list($prod_id) = explode('_', $cart_id[$i]);
                 $obj_product = new CProductInfo($prod_id);
                 if ($obj_product->isProductIdCorrect() == false) {
                     continue;
                 }
                 $stock_method = $obj_product->whichStockControlMethod();
                 $qty_in_stock = $obj_product->getProductTagValue('QuantityInStock', PRODUCTINFO_NOT_LOCALIZED_DATA);
                 $sum_qty = $quantity_in_cart[$i];
                 //                          -        Stock.
                 if ($stock_method == PRODUCT_QUANTITY_IN_STOCK_ATTRIBUTE) {
                     //          ,                                    ,
                     if ($qty_in_stock != '' && $qty_in_stock < $sum_qty && modApiFunc("Configuration", "getValue", SYSCONFIG_STORE_ALLOW_BUY_MORE_THAN_STOCK) === false) {
                         modApiFunc("Session", 'set', 'ShoppingCartResultMessage', cz_getMsg("ERR_NOT_ALLOWED_TO_BUY_MORE_THAN_IN_STOCK"));
                     } else {
                         //         ,               "min order"               -                                       .
                         $min_order = $obj_product->getProductTagValue('MinQuantity', PRODUCTINFO_NOT_LOCALIZED_DATA);
                         if ($min_order != '' && $min_order > $sum_qty) {
                             modApiFunc("Session", 'set', 'ShoppingCartResultMessage', $msgres->getMessage("ERR_NOT_ALLOWED_TO_BUY_LESS_THAN_MIN_ORDER", array($obj_product->getProductTagValue('MinQuantity'))));
                         } else {
                             modApiFunc('Cart', 'updateQuantityInCart', $cart_id[$i], $quantity_in_cart[$i]);
                         }
                     }
                 } else {
                     //          ,                                    ,
                     $obj_cart =& $application->getInstance('Cart');
                     $options = $obj_cart->CartContent[$cart_id[$i]]['options'];
                     $inv_id = modApiFunc("Product_Options", "getInventoryIDByCombination", 'product', $prod_id, $options);
                     if ($inv_id != null) {
                         $options_settings = modApiFunc("Product_Options", "getOptionsSettingsForEntity", 'product', $prod_id);
                         $inv_info = modApiFunc('Product_Options', 'getInventoryInfo', $inv_id);
                         if ($options_settings['AANIS'] == 'N' && $inv_info['quantity'] < $sum_qty && modApiFunc("Configuration", "getValue", SYSCONFIG_STORE_ALLOW_BUY_MORE_THAN_STOCK) === false) {
                             modApiFunc("Session", 'set', 'ShoppingCartResultMessage', cz_getMsg("ERR_NOT_ALLOWED_TO_BUY_MORE_THAN_IN_STOCK", $obj_product->getProductTagValue('MinQuantity')));
                         } else {
                             modApiFunc('Cart', 'updateQuantityInCart', $cart_id[$i], $quantity_in_cart[$i]);
                         }
                     } else {
                         $options_settings = modApiFunc("Product_Options", "getOptionsSettingsForEntity", 'product', $prod_id);
                         if ($options_settings['AANIC'] == 'Y') {
                             modApiFunc('Cart', 'updateQuantityInCart', $cart_id[$i], $quantity_in_cart[$i]);
                         }
                     }
                 }
             }
         }
     }
     $request = new Request();
     $request->setView(CURRENT_REQUEST_URL);
     $application->redirect($request);
 }