예제 #1
0
 /**
  * Returns the HTML dropdown menu string for the User account
  * validity period.
  * @param   integer   $selectedValidity   The selected validity period
  *                                        in days.  Defaults to 0 (zero).
  * @param   string    $attrs              Additional attributes for the
  *                                        menu, to be included in the
  *                                        <SELECT> tag.
  * @return  string                        The HTML dropdown menu code
  */
 public static function getValidityMenuOptions($selectedValidity = 0, $attrs = '')
 {
     $strOptions = '';
     foreach (User_Setting::getUserValidities() as $validity) {
         $strValidity = FWUser::getValidityString($validity);
         $strOptions .= '<option value="' . $validity . '"' . ($selectedValidity == $validity ? ' selected="selected"' : '') . (empty($attrs) ? '' : ' ' . $attrs) . '>' . $strValidity . '</option>';
     }
     return $strOptions;
 }
 protected function getValidityMenu($validity, $expirationDate)
 {
     //TODO:Use own methods instead of \FWUser::getValidityString() and \FWUser::getValidityMenuOptions()
     $menu = '<select name="downloads_download_validity" ' . ($validity && $expirationDate < time() ? 'onchange="this.style.color = this.value == \'current\' ? \'#f00\' : \'#000\'"' : null) . ' style="width:300px;' . ($validity && $expirationDate < time() ? 'color:#f00;font-weight:normal;' : 'color:#000;') . '">';
     if ($validity) {
         $menu .= '<option value="current" selected="selected" style="border-bottom:1px solid #000;' . ($expirationDate < time() ? 'color:#f00;font-weight:normal;' : null) . '">' . \FWUser::getValidityString($validity) . ' (' . date(ASCMS_DATE_FORMAT_DATE, $expirationDate) . ')</option>';
     }
     $menu .= \FWUser::getValidityMenuOptions(null, 'style="color:#000; font-weight:normal;"');
     $menu .= '</select>';
     return $menu;
 }
예제 #3
0
 /**
  * View of this Orders' items
  * @global  ADONewConnection    $objDatabase
  * @global  array               $_ARRAYLANG
  * @param   HTML_Template_Sigma $objTemplate    The template
  * @param   type                $edit           If true, items are editable
  * @param   type                $total_weight   Initial value for the
  *                                              total item weight, by
  *                                              reference.
  *                                              Usually empty or zero
  * @param   type                $i              Initial value for the row
  *                                              count, by reference.
  *                                              Usually empty or zero.
  * @return  float                               The net item sum on success,
  *                                              false otherwise
  */
 function view_items($objTemplate, $edit, &$total_weight = 0, $i = 0)
 {
     global $objDatabase, $_ARRAYLANG;
     // Order items
     // c_sp
     // Mind the custom price calculation
     $objCustomer = Customer::getById($this->customer_id);
     if (!$objCustomer) {
         \Message::error(sprintf($_ARRAYLANG['TXT_SHOP_ORDER_ERROR_MISSING_CUSTOMER'], $this->customer_id));
         $objCustomer = new Customer();
     }
     $query = "\n            SELECT `id`, `product_id`, `product_name`,\n                   `price`, `quantity`, `vat_rate`, `weight`\n              FROM `" . DBPREFIX . "module_shop" . MODULE_INDEX . "_order_items`\n             WHERE `order_id`=?";
     $objResult = $objDatabase->Execute($query, array($this->id));
     if (!$objResult) {
         return self::errorHandler();
     }
     $arrProductOptions = $this->getOptionArray();
     $total_vat_amount = 0;
     $total_net_price = 0;
     // Orders with Attributes cannot currently be edited
     // (this would spoil all the options!)
     //        $have_option = false;
     while (!$objResult->EOF) {
         $item_id = $objResult->fields['id'];
         $name = $objResult->fields['product_name'];
         $price = $objResult->fields['price'];
         $quantity = $objResult->fields['quantity'];
         $vat_rate = $objResult->fields['vat_rate'];
         $product_id = $objResult->fields['product_id'];
         // Get missing product details
         $objProduct = Product::getById($product_id);
         if (!$objProduct) {
             \Message::warning(sprintf($_ARRAYLANG['TXT_SHOP_PRODUCT_NOT_FOUND'], $product_id));
             $objProduct = new Product('', 0, $name, '', $price, 0, 0, 0, $product_id);
         }
         $code = $objProduct->code();
         $distribution = $objProduct->distribution();
         if (isset($arrProductOptions[$item_id])) {
             if ($edit) {
                 // Edit options
             } else {
                 //DBG::log("Order::view_items(): Item ID $item_id, Attributes: ".var_export($arrProductOptions[$item_id], true));
                 // Verify that options are properly shown
                 foreach ($arrProductOptions[$item_id] as $attribute_id => $attribute) {
                     //DBG::log("Order::view_items(): Added option, price: $options_price");
                     foreach ($attribute as $a) {
                         $name .= '<i><br />- ' . $attribute_id . ': ' . $a['name'] . ' (' . $a['price'] . ')</i>';
                         $price += $a['price'];
                     }
                 }
             }
         }
         // c_sp
         $row_net_price = $price * $quantity;
         $row_price = $row_net_price;
         // VAT added later, if applicable
         $total_net_price += $row_net_price;
         // Here, the VAT has to be recalculated before setting up the
         // fields.  If the VAT is excluded, it must be added here.
         // Note: the old Order.vat_amount field is no longer valid,
         // individual shop_order_items *MUST* have been UPDATEd by the
         // time PHP parses this line.
         // Also note that this implies that the vat_id and
         // country_id can be ignored, as they are considered when the
         // order is placed and the VAT is applied to the order
         // accordingly.
         // Calculate the VAT amount per row, included or excluded
         $row_vat_amount = Vat::amount($vat_rate, $row_net_price);
         //\DBG::log("$row_vat_amount = Vat::amount($vat_rate, $row_net_price)");
         // and add it to the total VAT amount
         $total_vat_amount += $row_vat_amount;
         if (!Vat::isIncluded()) {
             // Add tax to price
             $row_price += $row_vat_amount;
         }
         //else {
         // VAT is disabled.
         // There shouldn't be any non-zero percentages in the order_items!
         // but if there are, there probably has been a change and we *SHOULD*
         // still treat them as if VAT had been enabled at the time the order
         // was placed!
         // That's why the else {} block is commented out.
         //}
         $weight = '-';
         if ($distribution != 'download') {
             $weight = $objResult->fields['weight'];
             if (intval($weight) > 0) {
                 $total_weight += $weight * $quantity;
             }
         }
         $itemHasOptions = !empty($arrProductOptions[$item_id]);
         $objTemplate->setVariable(array('SHOP_PRODUCT_ID' => $product_id, 'SHOP_ROWCLASS' => 'row' . (++$i % 2 + 1), 'SHOP_QUANTITY' => $quantity, 'SHOP_PRODUCT_NAME' => $name, 'SHOP_PRODUCT_PRICE' => Currency::formatPrice($price), 'SHOP_PRODUCT_SUM' => Currency::formatPrice($row_net_price), 'SHOP_P_ID' => $edit ? $item_id : $objResult->fields['product_id'], 'SHOP_PRODUCT_CODE' => $code, 'SHOP_PRODUCT_TAX_RATE' => $edit ? $vat_rate : Vat::format($vat_rate), 'SHOP_PRODUCT_TAX_AMOUNT' => Currency::formatPrice($row_vat_amount), 'SHOP_PRODUCT_WEIGHT' => Weight::getWeightString($weight), 'SHOP_ACCOUNT_VALIDITY' => \FWUser::getValidityString($weight)));
         // Get a product menu for each Product if $edit-ing.
         // Preselect the current Product ID.
         if ($edit) {
             if ($itemHasOptions && $objTemplate->blockExists('order_item_product_options_tooltip')) {
                 $objTemplate->touchBlock('order_item_product_options_tooltip');
             }
             $objTemplate->setVariable('SHOP_PRODUCT_IDS_MENU', Products::getMenuoptions($product_id, null, +$_ARRAYLANG['TXT_SHOP_PRODUCT_MENU_FORMAT'], false));
         }
         $objTemplate->parse('order_item');
         $objResult->MoveNext();
     }
     return $total_net_price;
 }