예제 #1
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('"', '"', 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'] . ' ' . 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() . ' ' . Currency::getActiveCurrencySymbol()));
         if (Vat::isIncluded()) {
             $objTemplate->setVariable(array('SHOP_GRAND_TOTAL_EXCL_TAX' => Currency::formatPrice(self::get_price() - self::get_vat_amount()) . ' ' . 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']);
     }
 }
예제 #2
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;
 }