Ejemplo n.º 1
0
 /**
  * Initialize shippers and shipment conditions
  *
  * Use $all=true for the backend settings.
  * Reads the shipping options from the shipper (s) and shipment_cost (c)
  * tables.  For each shipper, creates array entries like:
  * arrShippers[s.id] = array (
  *      name => s.name,
  *      status => s.status
  * )
  * arrShipments[s.id][c.id] = array (
  *      max_weight => c.max_weight,
  *      free_from => c.free_from,
  *      fee => c.fee
  * )
  * Note that the table module_shop_shipment has been replaced by
  * module_shop_shipper (id, name, status) and
  * module_shop_shipment_cost (id, shipper_id, max_weight, fee, free_from)
  * as of version 1.1.
  * @global  ADONewConnection
  * @param   boolean   $all        If true, includes inactive records.
  *                                Defaults to false.
  * @return  void
  * @since   1.1
  */
 static function init($all = false)
 {
     global $objDatabase;
     //DBG::log("Shipment::init(): language ID ".FRONTEND_LANG_ID);
     $arrSqlName = \Text::getSqlSnippets('`shipper`.`id`', FRONTEND_LANG_ID, 'Shop', array('name' => self::TEXT_NAME));
     $objResult = $objDatabase->Execute("\n            SELECT `shipper`.`id`, `shipper`.`active`, " . $arrSqlName['field'] . "\n              FROM `" . DBPREFIX . "module_shop" . MODULE_INDEX . "_shipper` AS `shipper`" . $arrSqlName['join'] . ($all ? '' : ' WHERE `shipper`.`active`=1') . "\n             ORDER BY `shipper`.`id` ASC");
     if (!$objResult) {
         return self::errorHandler();
     }
     while (!$objResult->EOF) {
         $shipper_id = $objResult->fields['id'];
         $strName = $objResult->fields['name'];
         // Replace Text in a missing language by another, if available
         if ($strName === null) {
             $objText = \Text::getById($shipper_id, 'Shop', self::TEXT_NAME);
             if ($objText) {
                 $strName = $objText->content();
             }
         }
         self::$arrShippers[$shipper_id] = array('id' => $objResult->fields['id'], 'name' => $strName, 'active' => $objResult->fields['active']);
         $objResult->MoveNext();
     }
     // Now get the associated shipment conditions from shipment_cost
     $objResult = $objDatabase->Execute("\n            SELECT `shipment`.`id`, `shipment`.`shipper_id`,\n                   `shipment`.`max_weight`, `shipment`.`fee`, `shipment`.`free_from`\n              FROM `" . DBPREFIX . "module_shop" . MODULE_INDEX . "_shipment_cost` AS `shipment`\n             INNER JOIN `" . DBPREFIX . "module_shop" . MODULE_INDEX . "_shipper` AS `shipper`\n                ON `shipper`.`id`=`shipper_id`");
     if (!$objResult) {
         return self::errorHandler();
     }
     while (!$objResult->EOF) {
         self::$arrShipments[$objResult->fields['shipper_id']][$objResult->fields['id']] = array('max_weight' => Weight::getWeightString($objResult->fields['max_weight']), 'free_from' => $objResult->fields['free_from'], 'fee' => $objResult->fields['fee']);
         $objResult->MoveNext();
     }
     return true;
 }
Ejemplo n.º 2
0
 /**
  * Generates an overview of the Order for the Customer to confirm
  *
  * Forward her to the processing of the Order after the button has been
  * clicked.
  * @return  boolean             True on success, false otherwise
  */
 static function confirm()
 {
     global $_ARRAYLANG;
     // If the cart or address is missing, return to the shop
     if (!self::verifySessionAddress()) {
         \Cx\Core\Csrf\Controller\Csrf::redirect(\Cx\Core\Routing\Url::fromModuleAndCmd('Shop', ''));
     }
     self::$show_currency_navbar = false;
     // The Customer clicked the confirm button; this must not be the case
     // the first time this method is called.
     if (isset($_POST['process'])) {
         return self::process();
     }
     // Show confirmation page.
     self::$objTemplate->hideBlock('shopProcess');
     self::$objTemplate->setGlobalVariable($_ARRAYLANG);
     // It may be necessary to refresh the cart here, as the customer
     // may return to the cart, then press "Back".
     self::_initPaymentDetails();
     foreach (Cart::get_products_array() as $arrProduct) {
         $objProduct = Product::getById($arrProduct['id']);
         if (!$objProduct) {
             // TODO: Implement a proper method
             //                unset(Cart::get_product_id($cart_id]);
             continue;
         }
         $price_options = 0;
         $attributes = Attributes::getAsStrings($arrProduct['options'], $price_options);
         $attributes = $attributes[0];
         // Note:  The Attribute options' price is added
         // to the price here!
         $price = $objProduct->get_custom_price(self::$objCustomer, $price_options, $arrProduct['quantity']);
         // Test the distribution method for delivery
         $productDistribution = $objProduct->distribution();
         $weight = $productDistribution == 'delivery' ? Weight::getWeightString($objProduct->weight()) : '-';
         $vatId = $objProduct->vat_id();
         $vatRate = Vat::getRate($vatId);
         $vatPercent = Vat::getShort($vatId);
         $vatAmount = Vat::amount($vatRate, $price * $arrProduct['quantity']);
         self::$objTemplate->setVariable(array('SHOP_PRODUCT_ID' => $arrProduct['id'], 'SHOP_PRODUCT_CUSTOM_ID' => $objProduct->code(), 'SHOP_PRODUCT_TITLE' => contrexx_raw2xhtml($objProduct->name()), 'SHOP_PRODUCT_PRICE' => Currency::formatPrice($price * $arrProduct['quantity']), 'SHOP_PRODUCT_QUANTITY' => $arrProduct['quantity'], 'SHOP_PRODUCT_ITEMPRICE' => Currency::formatPrice($price), 'SHOP_UNIT' => Currency::getActiveCurrencySymbol()));
         if ($attributes && self::$objTemplate->blockExists('attributes')) {
             self::$objTemplate->setVariable('SHOP_PRODUCT_OPTIONS', $attributes);
         }
         if (\Cx\Core\Setting\Controller\Setting::getValue('weight_enable', 'Shop')) {
             self::$objTemplate->setVariable(array('SHOP_PRODUCT_WEIGHT' => $weight, 'TXT_WEIGHT' => $_ARRAYLANG['TXT_WEIGHT']));
         }
         if (Vat::isEnabled()) {
             self::$objTemplate->setVariable(array('SHOP_PRODUCT_TAX_RATE' => $vatPercent, 'SHOP_PRODUCT_TAX_AMOUNT' => Currency::formatPrice($vatAmount) . ' ' . Currency::getActiveCurrencySymbol()));
         }
         self::$objTemplate->parse("shopCartRow");
     }
     $total_discount_amount = 0;
     if (Cart::get_discount_amount()) {
         $total_discount_amount = Cart::get_discount_amount();
         self::$objTemplate->setVariable(array('SHOP_DISCOUNT_COUPON_TOTAL' => $_ARRAYLANG['TXT_SHOP_DISCOUNT_COUPON_AMOUNT_TOTAL'], 'SHOP_DISCOUNT_COUPON_TOTAL_AMOUNT' => Currency::formatPrice(-$total_discount_amount)));
     }
     self::$objTemplate->setVariable(array('SHOP_UNIT' => Currency::getActiveCurrencySymbol(), 'SHOP_TOTALITEM' => Cart::get_item_count(), 'SHOP_PAYMENT_PRICE' => Currency::formatPrice($_SESSION['shop']['payment_price']), 'SHOP_TOTALPRICE' => Currency::formatPrice(Cart::get_price()), 'SHOP_PAYMENT' => Payment::getProperty($_SESSION['shop']['paymentId'], 'name'), 'SHOP_GRAND_TOTAL' => Currency::formatPrice($_SESSION['shop']['grand_total_price']), 'SHOP_COMPANY' => stripslashes($_SESSION['shop']['company']), 'SHOP_TITLE' => stripslashes($_SESSION['shop']['gender']), 'SHOP_GENDER' => stripslashes($_SESSION['shop']['gender']), 'SHOP_LASTNAME' => stripslashes($_SESSION['shop']['lastname']), 'SHOP_FIRSTNAME' => stripslashes($_SESSION['shop']['firstname']), 'SHOP_ADDRESS' => stripslashes($_SESSION['shop']['address']), 'SHOP_ZIP' => stripslashes($_SESSION['shop']['zip']), 'SHOP_CITY' => stripslashes($_SESSION['shop']['city']), 'SHOP_COUNTRY' => \Cx\Core\Country\Controller\Country::getNameById($_SESSION['shop']['countryId']), 'SHOP_EMAIL' => stripslashes($_SESSION['shop']['email']), 'SHOP_PHONE' => stripslashes($_SESSION['shop']['phone']), 'SHOP_FAX' => stripslashes($_SESSION['shop']['fax'])));
     if (!empty($_SESSION['shop']['lastname2'])) {
         self::$objTemplate->setVariable(array('SHOP_COMPANY2' => stripslashes($_SESSION['shop']['company2']), 'SHOP_TITLE2' => stripslashes($_SESSION['shop']['gender2']), 'SHOP_LASTNAME2' => stripslashes($_SESSION['shop']['lastname2']), 'SHOP_FIRSTNAME2' => stripslashes($_SESSION['shop']['firstname2']), 'SHOP_ADDRESS2' => stripslashes($_SESSION['shop']['address2']), 'SHOP_ZIP2' => stripslashes($_SESSION['shop']['zip2']), 'SHOP_CITY2' => stripslashes($_SESSION['shop']['city2']), 'SHOP_COUNTRY2' => \Cx\Core\Country\Controller\Country::getNameById($_SESSION['shop']['countryId2']), 'SHOP_PHONE2' => stripslashes($_SESSION['shop']['phone2'])));
     }
     if (!empty($_SESSION['shop']['note'])) {
         self::$objTemplate->setVariable(array('SHOP_CUSTOMERNOTE' => $_SESSION['shop']['note']));
     }
     if (Vat::isEnabled()) {
         self::$objTemplate->setVariable(array('TXT_TAX_RATE' => $_ARRAYLANG['TXT_SHOP_VAT_RATE'], 'SHOP_TAX_PRICE' => Currency::formatPrice($_SESSION['shop']['vat_price']), 'SHOP_TAX_PRODUCTS_TXT' => $_SESSION['shop']['vat_products_txt'], 'SHOP_TAX_GRAND_TXT' => $_SESSION['shop']['vat_grand_txt'], 'TXT_TAX_PREFIX' => Vat::isIncluded() ? $_ARRAYLANG['TXT_SHOP_VAT_PREFIX_INCL'] : $_ARRAYLANG['TXT_SHOP_VAT_PREFIX_EXCL']));
         if (Vat::isIncluded()) {
             self::$objTemplate->setVariable(array('SHOP_GRAND_TOTAL_EXCL_TAX' => Currency::formatPrice($_SESSION['shop']['grand_total_price'] - $_SESSION['shop']['vat_price'])));
         }
     }
     // TODO: Make sure in payment() that those two are either both empty or
     // both non-empty!
     if (!Cart::needs_shipment() && empty($_SESSION['shop']['shipperId'])) {
         if (self::$objTemplate->blockExists('shipping_address')) {
             self::$objTemplate->hideBlock('shipping_address');
         }
     } else {
         // Shipment is required, so
         if (empty($_SESSION['shop']['shipperId'])) {
             \Cx\Core\Csrf\Controller\Csrf::redirect(\Cx\Core\Routing\Url::fromModuleAndCmd('Shop', 'payment'));
         }
         self::$objTemplate->setVariable(array('SHOP_SHIPMENT_PRICE' => Currency::formatPrice($_SESSION['shop']['shipment_price']), 'SHOP_SHIPMENT' => Shipment::getShipperName($_SESSION['shop']['shipperId'])));
     }
     // Custom.
     // Enable if Discount class is customized and in use.
     //self::showCustomerDiscount(Cart::get_price());
     return true;
 }
Ejemplo n.º 3
0
 static function getJavascriptArray($groupCustomerId = 0, $isReseller = false)
 {
     global $objDatabase;
     // create javascript array containing all products;
     // used to update the display when changing the product ID.
     // we need the VAT rate in there as well in order to be able to correctly change the products,
     // and the flag indicating whether the VAT is included in the prices already.
     $strJsArrProduct = 'var vat_included = ' . intval(Vat::isIncluded()) . ";\nvar arrProducts = new Array();\n";
     $arrSql = \Text::getSqlSnippets('`product`.`id`', FRONTEND_LANG_ID, 'Shop', array('name' => Product::TEXT_NAME, 'code' => Product::TEXT_CODE));
     $query = "\n            SELECT `product`.`id`,\n                   `product`.`resellerprice`, `product`.`normalprice`,\n                   `product`.`discountprice`, `product`.`discount_active`,\n                   `product`.`weight`, `product`.`vat_id`,\n                   `product`.`distribution`,\n                   `product`.`group_id`, `product`.`article_id`, " . $arrSql['field'] . "\n              FROM `" . DBPREFIX . "module_shop" . MODULE_INDEX . "_products` AS `product`" . $arrSql['join'] . "\n             WHERE `product`.`active`=1";
     $objResult = $objDatabase->Execute($query);
     if (!$objResult) {
         return Product::errorHandler();
     }
     while (!$objResult->EOF) {
         $id = $objResult->fields['id'];
         $distribution = $objResult->fields['distribution'];
         $strCode = $objResult->fields['code'];
         if ($strCode === null) {
             $strCode = \Text::getById($id, 'Shop', Product::TEXT_CODE)->content();
         }
         $strName = $objResult->fields['name'];
         if ($strName === null) {
             $strName = \Text::getById($id, 'Shop', Product::TEXT_NAME)->content();
         }
         $price = $objResult->fields['normalprice'];
         if ($objResult->fields['discount_active']) {
             $price = $objResult->fields['discountprice'];
         } elseif ($isReseller) {
             $price = $objResult->fields['resellerprice'];
         }
         // Determine discounted price from customer and article group matrix
         $discountCustomerRate = Discount::getDiscountRateCustomer($groupCustomerId, $objResult->fields['article_id']);
         $price -= $price * $discountCustomerRate * 0.01;
         // Determine prices for various count discounts, if any
         $arrDiscountCountRate = Discount::getDiscountCountRateArray($objResult->fields['group_id']);
         //\DBG::log("Products::getJavascriptArray($groupCustomerId, $isReseller): Discount rate array: ".var_export($arrDiscountCountRate, true));
         // Order the counts in reverse, from highest to lowest
         $strJsArrPrice = '';
         if (is_array($arrDiscountCountRate)) {
             foreach ($arrDiscountCountRate as $count => $rate) {
                 // Deduct the customer type discount right away
                 //\DBG::log("Products::getJavascriptArray(): price $price, rate $rate");
                 $discountPrice = $price - $price * $rate * 0.01;
                 $strJsArrPrice .= ($strJsArrPrice ? ',' : '') . $count . ',' . Currency::getCurrencyPrice($discountPrice);
             }
         }
         $strJsArrPrice .= ($strJsArrPrice ? ',' : '') . '0,' . Currency::getCurrencyPrice($price);
         $strJsArrProduct .= 'arrProducts[' . $id . '] = {' . 'id:' . $id . ',' . 'code:"' . $strCode . '",' . 'title:"' . htmlspecialchars($strName, ENT_QUOTES, CONTREXX_CHARSET) . '",' . 'percent:' . Vat::getRate($objResult->fields['vat_id']) . ',' . 'weight:' . ($distribution == 'delivery' ? '"' . Weight::getWeightString($objResult->fields['weight']) . '"' : '0') . ',' . 'price:[' . $strJsArrPrice . "]};\n";
         $objResult->MoveNext();
     }
     return $strJsArrProduct;
 }
Ejemplo n.º 4
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']);
     }
 }
Ejemplo n.º 5
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;
 }
Ejemplo n.º 6
0
 /**
  * Manage products
  *
  * Add and edit products
  * @access  public
  * @return  string
  * @author  Reto Kohli <*****@*****.**> (parts)
  */
 function view_product_edit()
 {
     global $_ARRAYLANG;
     self::store_product();
     $product_id = isset($_REQUEST['id']) ? intval($_REQUEST['id']) : 0;
     $objProduct = null;
     self::$objTemplate->addBlockfile('SHOP_PRODUCTS_FILE', 'shop_products_block', 'module_shop_product_manage.html');
     self::$objTemplate->setGlobalVariable($_ARRAYLANG);
     $cx = \Cx\Core\Core\Controller\Cx::instanciate();
     self::$objTemplate->setVariable(array('SHOP_DELETE_ICON' => $cx->getCodeBaseCoreWebPath() . '/Core/View/Media/icons/delete.gif', 'SHOP_NO_PICTURE_ICON' => self::$defaultImage));
     if ($product_id > 0) {
         $objProduct = Product::getById($product_id);
     }
     if (!$objProduct) {
         $objProduct = new Product('', 0, '', '', 0, 1, 0, 0);
     }
     $this->viewpart_product_attributes($product_id);
     $arrImages = Products::get_image_array_from_base64($objProduct->pictures());
     // Virtual Categories are disabled FTTB
     //        $flagsSelection =
     //            ShopCategories::getVirtualCategoriesSelectionForFlags(
     //                $objProduct->flags()
     //            );
     //        if ($flagsSelection) {
     //            self::$objTemplate->setVariable(
     //                'SHOP_FLAGS_SELECTION', $flagsSelection);
     //        }
     //
     // media browser
     $mediaBrowserOptions = array('type' => 'button', 'data-cx-mb-startmediatype' => 'shop', 'data-cx-mb-views' => 'filebrowser', 'id' => 'media_browser_shop', 'style' => 'display:none');
     self::$objTemplate->setVariable(array('MEDIABROWSER_BUTTON' => self::getMediaBrowserButton($mediaBrowserOptions, 'setSelectedImage')));
     $distribution = $objProduct->distribution();
     // Available active frontend groups, and those assigned to the product
     $objGroup = \FWUser::getFWUserObject()->objGroup->getGroups(array('type' => 'frontend', 'is_active' => true), array('group_id' => 'asc'));
     $usergroup_ids = $objProduct->usergroup_ids();
     $arrAssignedFrontendGroupId = explode(',', $usergroup_ids);
     $strActiveFrontendGroupOptions = '';
     $strAssignedFrontendGroupOptions = '';
     while ($objGroup && !$objGroup->EOF) {
         $strOption = '<option value="' . $objGroup->getId() . '">' . htmlentities($objGroup->getName(), ENT_QUOTES, CONTREXX_CHARSET) . '</option>';
         if (in_array($objGroup->getId(), $arrAssignedFrontendGroupId)) {
             $strAssignedFrontendGroupOptions .= $strOption;
         } else {
             $strActiveFrontendGroupOptions .= $strOption;
         }
         $objGroup->next();
     }
     $discount_group_count_id = $objProduct->group_id();
     $discount_group_article_id = $objProduct->article_id();
     $keywords = $objProduct->keywords();
     //die($objProduct->category_id());
     // Product assigned to multiple Categories
     $arrAssignedCategories = ShopCategories::getAssignedShopCategoriesMenuoptions($objProduct->category_id());
     // Date format for Datepicker:
     // Clear the date if none is set; there's no point in displaying
     // "01/01/1970" instead
     $start_date = $end_date = '';
     $start_time = strtotime($objProduct->date_start());
     // Note that the check for ">0" is necessary, as some systems return
     // crazy values for empty dates (it may even fail like this)!
     if ($start_time > 0) {
         $start_date = date(ASCMS_DATE_FORMAT_DATE, $start_time);
     }
     $end_time = strtotime($objProduct->date_end());
     if ($end_time > 0) {
         $end_date = date(ASCMS_DATE_FORMAT_DATE, $end_time);
     }
     //DBG::log("Dates from ".$objProduct->date_start()." ($start_time, $start_date) to ".$objProduct->date_start()." ($end_time, $end_date)");
     $websiteImagesShopPath = $cx->getWebsiteImagesShopPath() . '/';
     $websiteImagesShopWebPath = $cx->getWebsiteImagesShopWebPath() . '/';
     self::$objTemplate->setVariable(array('SHOP_PRODUCT_ID' => isset($_REQUEST['new']) ? 0 : $objProduct->id(), 'SHOP_PRODUCT_CODE' => contrexx_raw2xhtml($objProduct->code()), 'SHOP_PRODUCT_NAME' => contrexx_raw2xhtml($objProduct->name()), 'SHOP_CATEGORIES_ASSIGNED' => $arrAssignedCategories['assigned'], 'SHOP_CATEGORIES_AVAILABLE' => $arrAssignedCategories['available'], 'SHOP_CUSTOMER_PRICE' => contrexx_raw2xhtml(Currency::formatPrice($objProduct->price())), 'SHOP_RESELLER_PRICE' => contrexx_raw2xhtml(Currency::formatPrice($objProduct->resellerprice())), 'SHOP_DISCOUNT' => contrexx_raw2xhtml(Currency::formatPrice($objProduct->discountprice())), 'SHOP_SPECIAL_OFFER' => $objProduct->discount_active() ? \Html::ATTRIBUTE_CHECKED : '', 'SHOP_VAT_MENUOPTIONS' => Vat::getMenuoptions($objProduct->vat_id(), true), 'SHOP_SHORT_DESCRIPTION' => new \Cx\Core\Wysiwyg\Wysiwyg('short', $objProduct->short()), 'SHOP_DESCRIPTION' => new \Cx\Core\Wysiwyg\Wysiwyg('long', $objProduct->long(), 'full'), 'SHOP_STOCK' => $objProduct->stock(), 'SHOP_MIN_ORDER_QUANTITY' => $objProduct->minimum_order_quantity(), 'SHOP_MANUFACTURER_URL' => contrexx_raw2xhtml($objProduct->uri()), 'SHOP_DATE_START' => \Html::getDatepicker('date_start', array('defaultDate' => $start_date), ''), 'SHOP_DATE_END' => \Html::getDatepicker('date_end', array('defaultDate' => $end_date), ''), 'SHOP_ARTICLE_ACTIVE' => $objProduct->active() ? \Html::ATTRIBUTE_CHECKED : '', 'SHOP_B2B' => $objProduct->b2b() ? \Html::ATTRIBUTE_CHECKED : '', 'SHOP_B2C' => $objProduct->b2c() ? \Html::ATTRIBUTE_CHECKED : '', 'SHOP_STOCK_VISIBILITY' => $objProduct->stock_visible() ? \Html::ATTRIBUTE_CHECKED : '', 'SHOP_MANUFACTURER_MENUOPTIONS' => Manufacturer::getMenuoptions($objProduct->manufacturer_id()), 'SHOP_PICTURE1_IMG_SRC' => !empty($arrImages[1]['img']) && is_file(\ImageManager::getThumbnailFilename($websiteImagesShopPath . $arrImages[1]['img'])) ? contrexx_raw2encodedUrl(\ImageManager::getThumbnailFilename($websiteImagesShopWebPath . $arrImages[1]['img'])) : self::$defaultImage, 'SHOP_PICTURE2_IMG_SRC' => !empty($arrImages[2]['img']) && is_file(\ImageManager::getThumbnailFilename($websiteImagesShopPath . $arrImages[2]['img'])) ? contrexx_raw2encodedUrl(\ImageManager::getThumbnailFilename($websiteImagesShopWebPath . $arrImages[2]['img'])) : self::$defaultImage, 'SHOP_PICTURE3_IMG_SRC' => !empty($arrImages[3]['img']) && is_file(\ImageManager::getThumbnailFilename($websiteImagesShopPath . $arrImages[3]['img'])) ? contrexx_raw2encodedUrl(\ImageManager::getThumbnailFilename($websiteImagesShopWebPath . $arrImages[3]['img'])) : self::$defaultImage, 'SHOP_PICTURE1_IMG_SRC_NO_THUMB' => !empty($arrImages[1]['img']) && is_file($websiteImagesShopPath . $arrImages[1]['img']) ? $websiteImagesShopWebPath . $arrImages[1]['img'] : self::$defaultImage, 'SHOP_PICTURE2_IMG_SRC_NO_THUMB' => !empty($arrImages[2]['img']) && is_file($websiteImagesShopPath . $arrImages[2]['img']) ? $websiteImagesShopWebPath . $arrImages[2]['img'] : self::$defaultImage, 'SHOP_PICTURE3_IMG_SRC_NO_THUMB' => !empty($arrImages[3]['img']) && is_file($websiteImagesShopPath . $arrImages[3]['img']) ? $websiteImagesShopWebPath . $arrImages[3]['img'] : self::$defaultImage, 'SHOP_PICTURE1_IMG_WIDTH' => $arrImages[1]['width'], 'SHOP_PICTURE1_IMG_HEIGHT' => $arrImages[1]['height'], 'SHOP_PICTURE2_IMG_WIDTH' => $arrImages[2]['width'], 'SHOP_PICTURE2_IMG_HEIGHT' => $arrImages[2]['height'], 'SHOP_PICTURE3_IMG_WIDTH' => $arrImages[3]['width'], 'SHOP_PICTURE3_IMG_HEIGHT' => $arrImages[3]['height'], 'SHOP_DISTRIBUTION_MENU' => Distribution::getDistributionMenu($objProduct->distribution(), 'distribution', 'distributionChanged();', 'style="width: 220px"'), 'SHOP_WEIGHT' => $distribution == 'delivery' ? Weight::getWeightString($objProduct->weight()) : '0 g', 'SHOP_GROUPS_AVAILABLE' => $strActiveFrontendGroupOptions, 'SHOP_GROUPS_ASSIGNED' => $strAssignedFrontendGroupOptions, 'SHOP_ACCOUNT_VALIDITY_OPTIONS' => \FWUser::getValidityMenuOptions($distribution == 'download' ? $objProduct->weight() : 0), 'SHOP_CREATE_ACCOUNT_YES_CHECKED' => empty($usergroup_ids) ? '' : \Html::ATTRIBUTE_CHECKED, 'SHOP_CREATE_ACCOUNT_NO_CHECKED' => empty($usergroup_ids) ? \Html::ATTRIBUTE_CHECKED : '', 'SHOP_DISCOUNT_GROUP_COUNT_MENU_OPTIONS' => Discount::getMenuOptionsGroupCount($discount_group_count_id), 'SHOP_DISCOUNT_GROUP_ARTICLE_MENU_OPTIONS' => Discount::getMenuOptionsGroupArticle($discount_group_article_id), 'SHOP_KEYWORDS' => contrexx_raw2xhtml($keywords), 'SHOP_WEIGHT_ENABLED' => \Cx\Core\Setting\Controller\Setting::getValue('weight_enable', 'Shop') ? 1 : 0));
     return true;
 }