示例#1
0
 public function getPrices()
 {
     $tmpcart = $this->cart;
     foreach ($tmpcart->products as $key1 => $product) {
         foreach ($product->allPrices as $key2 => $pricearr) {
             $tmpcart->products[$key1]->allPrices[$key2]['product_tax_id'] = "";
         }
     }
     if (!class_exists('calculationHelper')) {
         require VMPATH_ADMIN . DS . 'helpers' . DS . 'calculationh.php';
     }
     $calculator = calculationHelper::getInstance();
     $calculator->getCheckoutPrices($tmpcart, true);
     $price = $this->cart->pricesUnformatted;
     require_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_virtuemart' . DS . 'helpers' . DS . 'currencydisplay.php';
     $cdisp = CurrencyDisplay::getInstance();
     //echo json_encode($this->cart);exit;
     foreach ($price as $id => $value) {
         if (!is_array($value)) {
             continue;
         }
         $nprice["products"][$id]["subtotal_tax_amount"] = !empty($price[$id]["taxAmount"]) ? $cdisp->priceDisplay($price[$id]["taxAmount"]) : "";
         $nprice["products"][$id]["subtotal_discount"] = !empty($price[$id]["subtotal_discount"]) ? $cdisp->priceDisplay($price[$id]["discountAmount"]) : "";
         if (VmConfig::get('checkout_show_origprice', 1) && !empty($this->cart->pricesUnformatted[$id]['basePriceWithTax']) && $this->cart->pricesUnformatted[$id]['basePriceWithTax'] != $this->cart->pricesUnformatted[$id]['salesPrice']) {
             $nprice["products"][$id]["subtotal_with_tax"] = '<span class="line-through">' . $cdisp->createPriceDiv('basePriceWithTax', '', $this->cart->pricesUnformatted[$id], true, false, $this->cart->products[$id]->quantity) . '</span><br />';
         }
         $nprice["products"][$id]["subtotal_with_tax"] .= $cdisp->createPriceDiv('salesPrice', '', $this->cart->pricesUnformatted[$id], false, false, $this->cart->products[$id]->quantity);
     }
     $nprice["taxAmount"] = !empty($this->cart->pricesUnformatted["taxAmount"]) ? $cdisp->priceDisplay($this->cart->pricesUnformatted["taxAmount"]) : "";
     $nprice["discountAmount"] = !empty($this->cart->pricesUnformatted["discountAmount"]) ? $cdisp->priceDisplay($this->cart->pricesUnformatted["discountAmount"]) : "";
     $nprice["salesPrice"] = !empty($this->cart->pricesUnformatted["salesPrice"]) ? $cdisp->priceDisplay($this->cart->pricesUnformatted["salesPrice"]) : "";
     $nprice["shipmentTax"] = !empty($this->cart->pricesUnformatted["shipmentTax"]) ? $cdisp->priceDisplay($this->cart->pricesUnformatted["shipmentTax"]) : "";
     $nprice["salesPriceShipment"] = !empty($this->cart->pricesUnformatted["salesPriceShipment"]) ? $cdisp->priceDisplay($this->cart->pricesUnformatted["salesPriceShipment"]) : "";
     $nprice["paymentTax"] = !empty($this->cart->pricesUnformatted["paymentTax"]) ? $cdisp->priceDisplay($this->cart->pricesUnformatted["paymentTax"]) : "";
     $nprice["salesPricePayment"] = !empty($this->cart->pricesUnformatted["salesPricePayment"]) ? $cdisp->priceDisplay($this->cart->pricesUnformatted["salesPricePayment"]) : "";
     $nprice["billTaxAmount"] = !empty($this->cart->pricesUnformatted["billTaxAmount"]) ? $cdisp->priceDisplay($this->cart->pricesUnformatted["billTaxAmount"]) : "";
     $nprice["billDiscountAmount"] = !empty($this->cart->pricesUnformatted["billDiscountAmount"]) ? $cdisp->priceDisplay($this->cart->pricesUnformatted["billDiscountAmount"]) : "";
     $nprice["billTotal"] = !empty($this->cart->pricesUnformatted["billTotal"]) ? $cdisp->priceDisplay($this->cart->pricesUnformatted["billTotal"]) : "";
     $nprice["couponTax"] = !empty($this->cart->pricesUnformatted["couponTax"]) ? $cdisp->priceDisplay($this->cart->pricesUnformatted["couponTax"]) : "";
     $nprice["salesPriceCoupon"] = !empty($this->cart->pricesUnformatted["salesPriceCoupon"]) ? $cdisp->priceDisplay($this->cart->pricesUnformatted["salesPriceCoupon"]) : "";
     //print_r($this->cart);
     $nprice["couponCode"] = !empty($this->cart->couponCode) ? $this->cart->couponCode : "";
     $nprice["couponCode"] = empty($nprice["couponCode"]) && !empty($this->cart->cartData["couponCode"]) ? $this->cart->cartData["couponCode"] : $nprice["couponCode"];
     $nprice["couponDescr"] = !empty($this->cart->cartData["couponDescr"]) ? $this->cart->cartData["couponDescr"] : "";
     $nprice["billTotalunformat"] = $this->cart->pricesUnformatted["billTotal"];
     /*$nprice["taxAmount"]=!empty($price["taxAmount"])?$cdisp->priceDisplay($price["taxAmount"]):"";
     		$nprice["discountAmount"]=!empty($price["discountAmount"])?$cdisp->priceDisplay($price["discountAmount"]):"";
     		$nprice["salesPrice"]=!empty($price["salesPrice"])?$cdisp->priceDisplay($price["salesPrice"]):"";
     		$nprice["shipmentTax"]=!empty($price["shipmentTax"])?$cdisp->priceDisplay($price["shipmentTax"]):"";
     		$nprice["salesPriceShipment"]=!empty($price["salesPriceShipment"])?$cdisp->priceDisplay($price["salesPriceShipment"]):"";
     		$nprice["paymentTax"]=!empty($price["paymentTax"])?$cdisp->priceDisplay($price["paymentTax"]):"";
     		$nprice["salesPricePayment"]=!empty($price["salesPricePayment"])?$cdisp->priceDisplay($price["salesPricePayment"]):"";
     		$nprice["billTaxAmount"]=!empty($price["billTaxAmount"])?$cdisp->priceDisplay($price["billTaxAmount"]):"";
     		$nprice["billDiscountAmount"]=!empty($price["billDiscountAmount"])?$cdisp->priceDisplay($price["billDiscountAmount"]):"";	
     		$nprice["billTotal"]=!empty($price["billTotal"])?$cdisp->priceDisplay($price["billTotal"]):"";*/
     //echo "<pre>";print_r($nprice);exit;
     return $nprice;
 }
示例#2
0
 public static function getList($params)
 {
     if (class_exists('VirtueMartCart')) {
         $productModel = VmModel::getModel('product');
         $calculator = calculationHelper::getInstance();
         $customfields = VmModel::getModel('Customfields');
         $cart = VirtueMartCart::getCart(false);
         $cart->pricesUnformatted = $calculator->getCheckoutPrices($cart, true);
         $viewName = vRequest::getString('view', 0);
         if ($viewName == 'cart') {
             $checkAutomaticPS = true;
         } else {
             $checkAutomaticPS = false;
         }
         $cart->prepareAjaxData($checkAutomaticPS);
         $productModel->addImages($cart->products);
         ini_set('xdebug.var_display_max_depth', 10);
         return $cart;
     }
 }
示例#3
0
 function plgVmConfirmedOrder($cart, $order)
 {
     $avaTaxRule = 0;
     if (isset($order['calc_rules'])) {
         foreach ($order['calc_rules'] as $rule) {
             if ($rule->calc_mathop == 'avalara') {
                 $avaTaxRule = $rule;
                 break;
             }
         }
     }
     if ($avaTaxRule !== 0) {
         if (!empty($avaTaxRule->calc_params)) {
             VmTable::bindParameterable($avaTaxRule, $this->_xParams, $this->_varsToPushParam);
             vmdebug('$avaTaxRule', $avaTaxRule);
             if ($rule->activated == 0) {
                 return false;
             }
             if (empty($this->addresses)) {
                 $this->addresses = $this->fillValidateAvalaraAddress($rule);
             }
             if ($this->addresses) {
                 if (!class_exists('calculationHelper')) {
                     require JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'calculationh.php';
                 }
                 vmdebug('$order', $order);
                 $orderModel = VmModel::getModel('orders');
                 $invoiceNumber = 'onr_' . $order['details']['BT']->order_number;
                 $orderModel->createInvoiceNumber($order['details']['BT'], $invoiceNumber);
                 $calculator = calculationHelper::getInstance();
                 $tax = $this->getTax($calculator, $rule, 0, $invoiceNumber);
                 //	vmdebug('tax',$tax);
             }
         }
     }
     /*	VmTable::bindParameterable ($rule, $this->_xParams, $this->_varsToPushParam);
     		if($rule->activated==0) return $price;
     		if(empty($this->addresses)){
     			$this->addresses = $this->fillValidateAvalaraAddress($rule);
     		}
     		if($this->addresses){
     			$tax = $this->getTax( $calculationHelper,$rule,$price,true);
     		}*/
 }
示例#4
0
 function setCartPrices(VirtueMartCart $cart, &$cart_prices, $method)
 {
     if (!class_exists('calculationHelper')) {
         require JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'calculationh.php';
     }
     if (!class_exists('calculationHelper')) {
         require JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'calculationh.php';
     }
     $calculator = calculationHelper::getInstance();
     $_psType = ucfirst($this->_psType);
     if (isset($method->tax_id) and (int) $method->tax_id === -1) {
     } else {
         if (!empty($method->tax_id)) {
             $cart_prices[$this->_psType . '_calc_id'] = $method->tax_id;
             $db = JFactory::getDBO();
             $q = 'SELECT * FROM #__virtuemart_calcs WHERE `virtuemart_calc_id`="' . $method->tax_id . '" ';
             $db->setQuery($q);
             $taxrules = $db->loadAssocList();
         } else {
             //This construction makes trouble, if there are products with different vats in the cart
             //on the other side, it is very unlikely to have different vats in the cart and simultaneous it is not possible to use a fixed tax rule for the shipment
             if (!empty($calculator->_cartData['VatTax']) and count($calculator->_cartData['VatTax']) == 1) {
                 $taxrules = $calculator->_cartData['VatTax'];
                 foreach ($taxrules as &$rule) {
                     $rule['subTotal'] = $cart_prices[$this->_psType . 'Value'];
                 }
             } else {
                 $taxrules = $calculator->_cartData['taxRulesBill'];
                 foreach ($taxrules as &$rule) {
                     unset($rule['subTotal']);
                 }
             }
         }
     }
     $cartTotalAmount = $cart_prices['salesPrice'] + $cart_prices['salesPriceShipment'] - $cart_prices['salesPriceCoupon'];
     if (isset($method->cost_percent_total)) {
         if (preg_match('/%$/', $method->cost_percent_total)) {
             $cost_percent_total = substr($method->cost_percent_total, 0, -1) * 0.01;
         } else {
             $cost_percent_total = $method->cost_percent_total * 0.01;
         }
     } else {
         $cost_percent_total = 0;
     }
     if (isset($method->cost_per_transaction)) {
         $cost_per_transaction = $method->cost_per_transaction;
     } else {
         $cost_per_transaction = 0;
     }
     if (count($taxrules) > 0) {
         $cost_percent_total_vat = $calculator->executeCalculation($taxrules, $cost_percent_total, true);
         $cost_per_transaction_vat = $calculator->executeCalculation($taxrules, $cost_per_transaction, true);
         $NewTotalAmount = ($cartTotalAmount + $cost_per_transaction_vat) / (1 - $cost_percent_total_vat);
         $feeWithVat = $NewTotalAmount - $cartTotalAmount;
         $calculator->setRevert(true);
         $feeNoVat = $calculator->roundInternal($calculator->executeCalculation($taxrules, $feeWithVat, true), 'salesPrice');
         $calculator->setRevert(false);
         $cart_prices[$this->_psType . 'Tax'] = $feeWithVat - $feeNoVat;
         $cart_prices['salesPrice' . $_psType] = $feeWithVat;
         $cart_prices[$_psType . 'Value'] = $feeNoVat;
         reset($taxrules);
         $taxrule = current($taxrules);
         $cart_prices[$this->_psType . '_calc_id'] = $taxrule['virtuemart_calc_id'];
     } else {
         $NewTotalAmount = ($cartTotalAmount + $method->cost_per_transaction) / (1 - $cost_percent_total);
         $fee = $NewTotalAmount - $cartTotalAmount;
         $cart_prices['salesPrice' . $_psType] = $fee;
         $cart_prices[$this->_psType . 'Tax'] = 0;
         $cart_prices[$this->_psType . '_calc_id'] = 0;
     }
     return $cart_prices['salesPrice' . $_psType];
 }
 /**
  *  TODO This is html and view stuff and MUST NOT be in the model, notice by Max
  * render custom fields display cart FE
  */
 public function CustomsFieldCartDisplay($priceKey, $product)
 {
     static $calculator;
     if (empty($calculator)) {
         JLoader::register('calculationHelper', JPATH_VM_ADMINISTRATOR . '/helpers/calculationh.php');
         $calculator = calculationHelper::getInstance();
     }
     vmdebug('CustomsFieldCartDisplay ', $priceKey);
     $variantmods = $calculator->parseModifier($priceKey);
     return self::customFieldDisplay($product, $variantmods, '<div class="vm-customfield-cart">', 'plgVmOnViewCart');
 }
 public function getCartPrices($checkAutomaticSelected = true)
 {
     JLoader::register('calculationHelper', JPATH_VM_ADMINISTRATOR . '/helpers/calculationh.php');
     $calculator = calculationHelper::getInstance();
     $this->pricesUnformatted = $calculator->getCheckoutPrices($this, $checkAutomaticSelected);
     return $this->pricesUnformatted;
 }
示例#7
0
 function setKlarnaCartPrices(VirtueMartCart $cart, &$cart_prices, $method)
 {
     $this->_getCartAddressCountryCode(NULL, $country, $countryId);
     $invoice_fee = KlarnaHandler::getInvoiceFee($method, $country);
     $invoice_tax_id = KlarnaHandler::getInvoiceTaxId($method, $country);
     $_psType = ucfirst($this->_psType);
     $cart_prices[$this->_psType . 'Value'] = $invoice_fee;
     $taxrules = array();
     if (!empty($invoice_tax_id)) {
         $db = JFactory::getDBO();
         $q = 'SELECT * FROM #__virtuemart_calcs WHERE `virtuemart_calc_id`="' . $invoice_tax_id . '" ';
         $db->setQuery($q);
         $taxrules = $db->loadAssocList();
     }
     if (!class_exists('calculationHelper')) {
         require JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'calculationh.php';
     }
     $calculator = calculationHelper::getInstance();
     if (count($taxrules) > 0) {
         $cart_prices['salesPrice' . $_psType] = $calculator->roundInternal($calculator->executeCalculation($taxrules, $cart_prices[$this->_psType . 'Value']));
         $cart_prices[$this->_psType . 'Tax'] = $calculator->roundInternal($cart_prices['salesPrice' . $_psType]) - $cart_prices[$this->_psType . 'Value'];
     } else {
         $cart_prices['salesPrice' . $_psType] = $invoice_fee;
         $cart_prices[$this->_psType . 'Tax'] = 0;
     }
 }
示例#8
0
 /**
  * calculateSalesPrice
  * overrides default function to remove currency conversion
  * @author Zasilkovna
  */
 function calculateSalesPrice($cart, $method, $cart_prices)
 {
     $value = $this->getCosts($cart, $method, $cart_prices);
     $tax_id = @$method->tax_id;
     $vendor_id = $cart->vendorId;
     if (empty($vendor_id)) {
         $vendor_id = 1;
     }
     $vendor_currency = VirtueMartModelVendor::getVendorCurrency($vendor_id);
     $db = JFactory::getDBO();
     $calculator = calculationHelper::getInstance();
     $currency = CurrencyDisplay::getInstance();
     $taxrules = array();
     if (!empty($tax_id)) {
         $q = 'SELECT * FROM #__virtuemart_calcs WHERE `virtuemart_calc_id`="' . $tax_id . '" ';
         $db->setQuery($q);
         $taxrules = $db->loadAssocList();
     }
     if (count($taxrules) > 0) {
         $salesPrice = $calculator->roundInternal($calculator->executeCalculation($taxrules, $value));
     } else {
         $salesPrice = $value;
     }
     return $salesPrice;
 }
示例#9
0
 function createStandardRequest($calc, $products, $sign = 1)
 {
     if (!class_exists('TaxServiceSoap')) {
         require VMAVALARA_CLASS_PATH . DS . 'TaxServiceSoap.class.php';
     }
     if (!class_exists('DocumentType')) {
         require VMAVALARA_CLASS_PATH . DS . 'DocumentType.class.php';
     }
     if (!class_exists('DetailLevel')) {
         require VMAVALARA_CLASS_PATH . DS . 'DetailLevel.class.php';
     }
     if (!class_exists('Line')) {
         require VMAVALARA_CLASS_PATH . DS . 'Line.class.php';
     }
     if (!class_exists('ServiceMode')) {
         require VMAVALARA_CLASS_PATH . DS . 'ServiceMode.class.php';
     }
     if (!class_exists('Line')) {
         require VMAVALARA_CLASS_PATH . DS . 'Line.class.php';
     }
     if (!class_exists('GetTaxRequest')) {
         require VMAVALARA_CLASS_PATH . DS . 'GetTaxRequest.class.php';
     }
     if (!class_exists('GetTaxResult')) {
         require VMAVALARA_CLASS_PATH . DS . 'GetTaxResult.class.php';
     }
     if (!class_exists('Address')) {
         require VMAVALARA_CLASS_PATH . DS . 'Address.class.php';
     }
     if (is_object($calc)) {
         $calc = get_object_vars($calc);
     }
     $request = new GetTaxRequest();
     $origin = new Address();
     //In Virtuemart we have not differenct warehouses, but we have a shipment address
     //So when the vendor has a shipment address, we assume that it is his warehouse
     //Later we can combine products with shipment addresses for different warehouse (yehye, future music)
     //But for now we just use the BT address
     if (!class_exists('VirtueMartModelVendor')) {
         require JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'vendor.php';
     }
     $userId = VirtueMartModelVendor::getUserIdByVendorId($calc['virtuemart_vendor_id']);
     $userModel = VmModel::getModel('user');
     $virtuemart_userinfo_id = $userModel->getBTuserinfo_id($userId);
     // this is needed to set the correct user id for the vendor when the user is logged
     $userModel->getVendor($calc['virtuemart_vendor_id']);
     $vendorFieldsArray = $userModel->getUserInfoInUserFields('mail', 'BT', $virtuemart_userinfo_id, FALSE, TRUE);
     $vendorFields = $vendorFieldsArray[$virtuemart_userinfo_id];
     $origin->setLine1($vendorFields['fields']['address_1']['value']);
     $origin->setLine2($vendorFields['fields']['address_2']['value']);
     $origin->setCity($vendorFields['fields']['city']['value']);
     $origin->setCountry($vendorFields['fields']['virtuemart_country_id']['country_2_code']);
     $origin->setRegion($vendorFields['fields']['virtuemart_state_id']['state_2_code']);
     $origin->setPostalCode($vendorFields['fields']['zip']['value']);
     $request->setOriginAddress($origin);
     //Address
     if (isset($this->addresses[0])) {
         $destination = $this->addresses[0];
     } else {
         return FALSE;
     }
     if (!class_exists('calculationHelper')) {
         require JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'calculationh.php';
     }
     $calculator = calculationHelper::getInstance();
     $request->setCurrencyCode($calculator->_currencyDisplay->_vendorCurrency_code_3);
     //CurrencyCode
     $request->setDestinationAddress($destination);
     //Address
     $request->setCompanyCode($calc['company_code']);
     // Your Company Code From the Dashboard
     $request->setDocDate(date('Y-m-d'));
     //date, checked
     $request->setCustomerCode(self::$vmadd['customer_number']);
     //string Required
     if (isset(self::$vmadd['tax_usage_type'])) {
         $request->setCustomerUsageType(self::$vmadd['tax_usage_type']);
         //string   Entity Usage
     }
     if (isset(self::$vmadd['tax_exemption_number'])) {
         $request->setExemptionNo(self::$vmadd['tax_exemption_number']);
         //string   if not using ECMS which keys on customer code
     }
     if (isset(self::$vmadd['taxOverride'])) {
         $request->setTaxOverride(self::$vmadd['taxOverride']);
         avadebug('I set tax override ', self::$vmadd['taxOverride']);
     }
     $setAllDiscounted = false;
     if (isset($products['discountAmount'])) {
         if (!empty($products['discountAmount'])) {
             //$request->setDiscount($sign * $products['discountAmount'] * (-1));            //decimal
             $request->setDiscount($sign * $products['discountAmount']);
             //decimal
             vmdebug('We sent as discount ' . $request->getDiscount());
             $setAllDiscounted = true;
         }
         unset($products['discountAmount']);
     }
     $request->setDetailLevel('Tax');
     //Summary or Document or Line or Tax or Diagnostic
     $lines = array();
     $n = 0;
     $this->_lineNumbersToCartProductId = array();
     foreach ($products as $k => $product) {
         $n++;
         $this->_lineNumbersToCartProductId[$n] = $k;
         $line = new Line();
         $line->setNo($n);
         //string  // line Number of invoice
         $line->setItemCode($product['product_sku']);
         //string
         $line->setDescription($product['product_name']);
         //product description, like in cart, atm only the name, todo add customfields
         if (!empty($product['categories'])) {
             //avadebug('AvaTax setTaxCode Product has categories !',$catNames);
             if (!class_exists('TableCategories')) {
                 require JPATH_VM_ADMINISTRATOR . DS . 'tables' . DS . 'categories.php';
             }
             $db = JFactory::getDbo();
             $catTable = new TableCategories($db);
             foreach ($product['categories'] as $cat) {
                 $catTable->load($cat);
                 $catslug = $catTable->slug;
                 if (strpos($catslug, 'avatax-') !== FALSE) {
                     $taxCode = substr($catslug, 7);
                     if (!empty($taxCode)) {
                         $line->setTaxCode($taxCode);
                     } else {
                         vmError('AvaTax setTaxCode, category could not be parsed ' . $catslug);
                     }
                     break;
                 }
             }
         }
         //$line->setTaxCode("");             //string
         $line->setQty($product['amount']);
         //decimal
         $line->setAmount($sign * $product['price'] * $product['amount']);
         //decimal // TotalAmmount
         if ($setAllDiscounted or !empty($product['discount'])) {
             $line->setDiscounted(1);
         } else {
             $line->setDiscounted(0);
         }
         $line->setRevAcct("");
         //string
         $line->setRef1("");
         //string
         $line->setRef2("");
         //string
         if (isset(self::$vmadd['tax_usage_type'])) {
             $line->setCustomerUsageType(self::$vmadd['tax_usage_type']);
             //string   Entity Usage
         }
         if (isset(self::$vmadd['tax_exemption_number'])) {
             $line->setExemptionNo(self::$vmadd['tax_exemption_number']);
             //string   if not using ECMS which keys on customer code
         }
         if (isset(self::$vmadd['taxOverride'])) {
             //create new TaxOverride Object set
             //$line->setTaxOverride(self::$vmadd['taxOverride']);
         }
         $lines[] = $line;
     }
     $this->newATConfig($calc);
     $request->setLines($lines);
     return $request;
 }
示例#10
0
 /**
  * calculateSalesPrice
  *
  * @param $value
  * @param $tax_id: tax id
  * @return $salesPrice
  */
 protected function calculateSalesPrice($cart, $method, $cart_prices)
 {
     $value = $this->getCosts($cart, $method, $cart_prices);
     $tax_id = @$method->tax_id;
     if (!class_exists('calculationHelper')) {
         require JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'calculationh.php';
     }
     if (!class_exists('CurrencyDisplay')) {
         require JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'currencydisplay.php';
     }
     if (!class_exists('VirtueMartModelVendor')) {
         require JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'vendor.php';
     }
     $vendor_id = 1;
     $vendor_currency = VirtueMartModelVendor::getVendorCurrency($vendor_id);
     $db = JFactory::getDBO();
     $calculator = calculationHelper::getInstance();
     $currency = CurrencyDisplay::getInstance();
     $value = $currency->convertCurrencyTo($vendor_currency->virtuemart_currency_id, $value);
     $taxrules = array();
     if (!empty($tax_id)) {
         $q = 'SELECT * FROM #__virtuemart_calcs WHERE `virtuemart_calc_id`="' . $tax_id . '" ';
         $db->setQuery($q);
         $taxrules = $db->loadAssocList();
     }
     if (count($taxrules) > 0) {
         $salesPrice = $calculator->roundInternal($calculator->executeCalculation($taxrules, $value));
     } else {
         $salesPrice = $value;
     }
     return $salesPrice;
 }
示例#11
0
 function fetchElement($name, $value, &$node, $control_name)
 {
     //Load languages
     $language = JFactory::getLanguage();
     $language->load('plg_k2_k2mart', JPATH_ADMINISTRATOR);
     $language->load('com_virtuemart', JPATH_ADMINISTRATOR);
     //Get params
     $params = JComponentHelper::getParams('com_k2mart');
     $mainframe = JFactory::getApplication();
     $db = JFactory::getDBO();
     //Add scripts and styles
     $document = JFactory::getDocument();
     $document->addStyleSheet(JURI::root(true) . '/plugins/k2/k2mart/tmpl/admin/css/admin.style.css');
     $document->addStyleSheet(JURI::root(true) . '/administrator/components/com_k2mart/css/chosen.css');
     $document->addScript(JURI::root(true) . '/plugins/k2/k2mart/includes/js/admin.k2mart.js');
     $document->addScript(JURI::root(true) . '/administrator/components/com_k2mart/js/chosen.jquery.min.js');
     $document->addScript(JURI::root(true) . '/components/com_virtuemart/assets/js/fancybox/jquery.fancybox-1.3.4.js');
     $document->addScript(JURI::root(true) . '/administrator/components/com_virtuemart/assets/js/vm2admin.js');
     $document->addScript(JURI::root(true) . '/administrator/components/com_virtuemart/assets/js/jquery.coookie.js');
     //Get K2 Item
     $itemID = JRequest::getInt('cid');
     $productID = 0;
     if ($itemID) {
         $query = "SELECT referenceID FROM #__k2mart WHERE baseID = {$itemID}";
         $db->setQuery($query);
         $productID = $db->loadResult();
     }
     //Include Virtuemart classes
     require_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_virtuemart' . DS . 'helpers' . DS . 'config.php';
     $config = VmConfig::loadConfig();
     require_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_virtuemart' . DS . 'helpers' . DS . 'shopfunctions.php';
     require_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_virtuemart' . DS . 'helpers' . DS . 'html.php';
     JModel::addIncludePath(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_virtuemart' . DS . 'models');
     //Get product
     $model = JModel::getInstance('Product', 'VirtuemartModel');
     $product = $model->getProductSingle($productID, false);
     //Get product children
     $product->children = method_exists($model, 'getProductChilds') ? $model->getProductChilds($productID) : $model->getProductChildIds($productID);
     //Get product parent
     JModel::addIncludePath(JPATH_SITE . DS . 'components' . DS . 'com_k2' . DS . 'models');
     $K2Model = JModel::getInstance('Itemlist', 'K2Model');
     $tree = $K2Model->getCategoryTree($params->get('catalogRoot', 0));
     $query = "SELECT id AS value, title AS text FROM #__k2_items WHERE catid IN(" . implode(',', $tree) . ")";
     $db->setQuery($query);
     $items = $db->loadObjectList();
     $option = new JObject();
     $option->value = 0;
     $option->text = JText::_('K2MART_NONE');
     array_unshift($items, $option);
     $parent = 0;
     if ($product->product_parent_id) {
         $query = "SELECT baseID FROM #__k2mart WHERE referenceID = {$product->product_parent_id}";
         $db->setQuery($query);
         $parent = $db->loadResult();
     }
     $lists['product_parent_id'] = JHTML::_('select.genericlist', $items, 'product_parent_id', 'class="inputbox"', 'value', 'text', $parent);
     //Get category tree
     if (isset($product->categories)) {
         $lists['categories'] = ShopFunctions::categoryListTree($product->categories);
     } else {
         $lists['categories'] = ShopFunctions::categoryListTree();
     }
     //Get vendors
     if (Vmconfig::get('multix', 'none') !== 'none') {
         $lists['vendors'] = Shopfunctions::renderVendorList($product->virtuemart_vendor_id);
     }
     //Get images
     $model->addImages($product);
     if (is_array($product->images) && isset($product->images[0])) {
         $product->image = $product->images[0];
     } else {
         $product->image = new JObject();
         $product->image->virtuemart_media_id = 0;
         $product->image->file_title = '';
         $product->image->file_description = '';
         $product->image->file_meta = '';
         $product->image->file_url = '';
         $product->image->file_url_thumb = '';
         $product->image->file_title = '';
     }
     //Get manufacturers
     $model = JModel::getInstance('Manufacturer', 'VirtuemartModel');
     $manufacturers = $model->getManufacturerDropdown($product->virtuemart_manufacturer_id);
     if (count($manufacturers) > 0) {
         $lists['manufacturers'] = JHTML::_('select.genericlist', $manufacturers, 'virtuemart_manufacturer_id', 'class="inputbox"', 'value', 'text', $product->virtuemart_manufacturer_id);
     }
     //Get shopper groups
     if (isset($product->shoppergroups)) {
         $lists['shopperGroups'] = ShopFunctions::renderShopperGroupList($product->shoppergroups, true);
     }
     //Get product price
     require_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_virtuemart' . DS . 'helpers' . DS . 'calculationh.php';
     $calculator = calculationHelper::getInstance();
     $product->prices = $calculator->getProductPrices($product);
     // Get product price override options
     $options = array(0 => 'Disabled', 1 => 'Overwrite final', -1 => 'Overwrite price to tax');
     $lists['price_override_options'] = VmHtml::radioList('override', $product->override, $options);
     // Get tax rules
     $dbTax = '';
     foreach ($calculator->rules['DBTax'] as $rule) {
         $dbTax .= $rule['calc_name'] . '<br />';
     }
     $dbTaxRules = $dbTax;
     $tax = JText::_('COM_VIRTUEMART_TAX_EFFECTING');
     foreach ($calculator->rules['Tax'] as $rule) {
         $tax .= $rule['calc_name'] . '<br />';
     }
     $taxRules = $tax;
     $daTax = '';
     foreach ($calculator->rules['DATax'] as $rule) {
         $daTax .= $rule['calc_name'] . '<br />';
     }
     $daTaxRules = $daTax;
     // Removed in VM 2.0.4
     //$override = $calculator->override;
     //$product_override_price = $calculator->product_override_price;
     if (!isset($product->product_tax_id)) {
         $product->product_tax_id = 0;
     }
     $lists['taxrates'] = ShopFunctions::renderTaxList($product->product_tax_id, 'product_tax_id');
     // Discounts
     if (!isset($product->product_discount_id)) {
         $product->product_discount_id = 0;
     }
     require_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_virtuemart' . DS . 'models' . DS . 'calc.php';
     $discounts = VirtueMartModelCalc::getDiscounts();
     $discountrates = array();
     $discountrates[] = JHTML::_('select.option', '-1', JText::_('COM_VIRTUEMART_PRODUCT_DISCOUNT_NONE'), 'product_discount_id');
     $discountrates[] = JHTML::_('select.option', '0', JText::_('COM_VIRTUEMART_PRODUCT_DISCOUNT_NO_SPECIAL'), 'product_discount_id');
     foreach ($discounts as $discount) {
         $discountrates[] = JHTML::_('select.option', $discount->virtuemart_calc_id, $discount->calc_name, 'product_discount_id');
     }
     $lists['discounts'] = JHTML::_('select.genericlist', $discountrates, 'product_discount_id', '', 'product_discount_id', 'text', $product->product_discount_id);
     //Define Virtuemart image path
     if (is_Dir(VmConfig::get('vmtemplate') . DS . 'images' . DS . 'availability' . DS)) {
         $imagePath = VmConfig::get('vmtemplate') . '/images/availability/';
     } else {
         $imagePath = '/components/com_virtuemart/assets/images/availability/';
     }
     // Get currencies
     $model = JModel::getInstance('Currency', 'VirtuemartModel');
     $vendorModel = JModel::getInstance('Vendor', 'VirtuemartModel');
     $vendorModel->setId(1);
     $vendor = $vendorModel->getVendor();
     if (empty($product->product_currency)) {
         $product->product_currency = $vendor->vendor_currency;
     }
     $lists['currencies'] = JHTML::_('select.genericlist', $model->getCurrencies(), 'product_currency', '', 'virtuemart_currency_id', 'currency_name', $product->product_currency);
     $currency = $model->getCurrency($product->product_currency);
     $productCurrency = $currency->currency_symbol;
     $currency = $model->getCurrency($vendor->vendor_currency);
     $vendorCurrency = $currency->currency_symbol;
     //Get dimensions
     $lists['product_weight_uom'] = ShopFunctions::renderWeightUnitList('product_weight_uom', !isset($product->product_weight_uom) ? $config->get('weight_unit_default') : $product->product_weight_uom);
     $lists['product_lwh_uom'] = ShopFunctions::renderLWHUnitList('product_lwh_uom', !isset($product->product_lwh_uom) ? $config->get('lwh_unit_default') : $product->product_lwh_uom);
     //Get custom fields
     $model = JModel::getInstance('CustomFields', 'VirtuemartModel');
     $fieldTypes = $model->getField_types();
     $customsList = JHTML::_('select.genericlist', $model->getCustomsList(), 'customlist');
     if (!isset($product->customfields)) {
         $product->customfields = array();
     }
     //Set some script variables
     $document->addScriptDeclaration('var k2martVmImagePath="' . JURI::root(true) . $imagePath . '"; var tip_image="' . JURI::root(true) . '/components/com_virtuemart/assets/js/images/vtip_arrow.png"; var k2martVmCustomFieldsNum = "' . count($product->customfields) . '";');
     //Edit icon
     $application = JFactory::getApplication('admin');
     $editIcon = JURI::root(true) . '/administrator/templates/' . $application->getTemplate() . '/images/menu/icon-16-edit.png';
     //Output
     ob_start();
     include JPATH_SITE . DS . 'plugins' . DS . 'k2' . DS . 'k2mart' . DS . 'tmpl' . DS . 'admin' . DS . 'form.php';
     $contents = ob_get_clean();
     return $contents;
 }
示例#12
0
 function display($tpl = null)
 {
     // Get the task
     $task = JRequest::getWord('task');
     // Load helpers
     $this->loadHelper('currencydisplay');
     $this->loadHelper('html');
     $this->loadHelper('image');
     //$category_model = VmModel::getModel('category');
     $model = VmModel::getModel();
     // Handle any publish/unpublish
     switch ($task) {
         case 'add':
         case 'edit':
             //this was in the controller for the edit tasks, I dont know if it is still needed,
             $this->addTemplatePath(JPATH_COMPONENT_ADMINISTRATOR . DS . 'views' . DS . 'product' . DS . 'tmpl');
             $virtuemart_product_id = JRequest::getVar('virtuemart_product_id', array());
             if (is_array($virtuemart_product_id) && count($virtuemart_product_id) > 0) {
                 $virtuemart_product_id = (int) $virtuemart_product_id[0];
             } else {
                 $virtuemart_product_id = (int) $virtuemart_product_id;
             }
             $product = $model->getProductSingle($virtuemart_product_id, false);
             $product_parent = $model->getProductParent($product->product_parent_id);
             $mf_model = VmModel::getModel('manufacturer');
             $manufacturers = $mf_model->getManufacturerDropdown($product->virtuemart_manufacturer_id);
             $this->assignRef('manufacturers', $manufacturers);
             // Get the category tree
             if (isset($product->categories)) {
                 $category_tree = ShopFunctions::categoryListTree($product->categories);
             } else {
                 $category_tree = ShopFunctions::categoryListTree();
             }
             $this->assignRef('category_tree', $category_tree);
             //Get the shoppergoup list - Cleanshooter Custom Shopper Visibility
             if (isset($product->shoppergroups)) {
                 $shoppergroupList = ShopFunctions::renderShopperGroupList($product->shoppergroups, true);
             }
             $this->assignRef('shoppergroupList', $shoppergroupList);
             // Load the product price
             if (!class_exists('calculationHelper')) {
                 require JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'calculationh.php';
             }
             $calculator = calculationHelper::getInstance();
             $product->prices = $calculator->getProductPrices($product);
             $product_childIds = $model->getProductChildIds($virtuemart_product_id);
             $product_childs = array();
             foreach ($product_childIds as $id) {
                 $product_childs[] = $model->getProductSingle($id, false);
             }
             $this->assignRef('product_childs', $product_childs);
             $DBTax = '';
             //JText::_('COM_VIRTUEMART_RULES_EFFECTING') ;
             foreach ($calculator->rules['DBTax'] as $rule) {
                 $DBTax .= $rule['calc_name'] . '<br />';
             }
             $this->assignRef('DBTaxRules', $DBTax);
             $tax = '';
             //JText::_('COM_VIRTUEMART_TAX_EFFECTING').'<br />';
             foreach ($calculator->rules['Tax'] as $rule) {
                 $tax .= $rule['calc_name'] . '<br />';
             }
             foreach ($calculator->rules['VatTax'] as $rule) {
                 $tax .= $rule['calc_name'] . '<br />';
             }
             $this->assignRef('taxRules', $tax);
             $DATax = '';
             //JText::_('COM_VIRTUEMART_RULES_EFFECTING');
             foreach ($calculator->rules['DATax'] as $rule) {
                 $DATax .= $rule['calc_name'] . '<br />';
             }
             $this->assignRef('DATaxRules', $DATax);
             // 				$this->assignRef('override', $calculator->override);
             // 				$this->assignRef('product_override_price', $calculator->product_override_price);
             if (!isset($product->product_tax_id)) {
                 $product->product_tax_id = 0;
             }
             $lists['taxrates'] = ShopFunctions::renderTaxList($product->product_tax_id, 'product_tax_id');
             if (!isset($product->product_discount_id)) {
                 $product->product_discount_id = 0;
             }
             $lists['discounts'] = $this->renderDiscountList($product->product_discount_id);
             if (!class_exists('VirtueMartModelConfig')) {
                 require JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'config.php';
             }
             $productLayouts = VirtueMartModelConfig::getLayoutList('productdetails');
             $this->assignRef('productLayouts', $productLayouts);
             // Load Images
             $model->addImages($product);
             if (is_Dir(VmConfig::get('vmtemplate') . DS . 'images' . DS . 'availability' . DS)) {
                 $imagePath = VmConfig::get('vmtemplate') . '/images/availability/';
             } else {
                 $imagePath = '/components/com_virtuemart/assets/images/availability/';
             }
             $this->assignRef('imagePath', $imagePath);
             // Load the vendors
             $vendor_model = VmModel::getModel('vendor');
             // 				$vendors = $vendor_model->getVendors();
             // 				$lists['vendors'] = JHTML::_('select.genericlist', $vendors, 'virtuemart_vendor_id', '', 'virtuemart_vendor_id', 'vendor_name', $product->virtuemart_vendor_id);
             if (Vmconfig::get('multix', 'none') !== 'none') {
                 $lists['vendors'] = Shopfunctions::renderVendorList($product->virtuemart_vendor_id);
             }
             // Load the currencies
             $currency_model = VmModel::getModel('currency');
             $vendor_model->setId(1);
             $vendor = $vendor_model->getVendor();
             if (empty($product->product_currency)) {
                 $product->product_currency = $vendor->vendor_currency;
             }
             $currencies = JHTML::_('select.genericlist', $currency_model->getCurrencies(), 'product_currency', '', 'virtuemart_currency_id', 'currency_name', $product->product_currency);
             $currency = $currency_model->getCurrency($product->product_currency);
             $this->assignRef('product_currency', $currency->currency_symbol);
             $currency = $currency_model->getCurrency($vendor->vendor_currency);
             $this->assignRef('vendor_currency', $currency->currency_symbol);
             if (count($manufacturers) > 0) {
                 $lists['manufacturers'] = JHTML::_('select.genericlist', $manufacturers, 'virtuemart_manufacturer_id', 'class="inputbox"', 'value', 'text', $product->virtuemart_manufacturer_id);
             }
             $lists['product_weight_uom'] = ShopFunctions::renderWeightUnitList('product_weight_uom', $task == 'add' ? VmConfig::get('weight_unit_default') : $product->product_weight_uom);
             $lists['product_lwh_uom'] = ShopFunctions::renderLWHUnitList('product_lwh_uom', $task == 'add' ? VmConfig::get('lwh_unit_default') : $product->product_lwh_uom);
             if (empty($product->product_available_date)) {
                 $product->product_available_date = date("Y-m-d");
             }
             $waitinglistmodel = VmModel::getModel('waitinglist');
             /* Load waiting list */
             if ($product->virtuemart_product_id) {
                 //$waitinglist = $this->get('waitingusers', 'waitinglist');
                 $waitinglist = $waitinglistmodel->getWaitingusers($product->virtuemart_product_id);
                 $this->assignRef('waitinglist', $waitinglist);
             }
             $bookedUsers = $waitinglistmodel->getProductShoppersByStatus($product->virtuemart_product_id, array('S'));
             $this->assignRef('customers', $bookedUsers);
             $orderstatusModel = VmModel::getModel('orderstatus');
             $lists['OrderStatus'] = $orderstatusModel->renderOrderStatusList(true, array('S'));
             $field_model = VmModel::getModel('customfields');
             $fieldTypes = $field_model->getField_types();
             $this->assignRef('fieldTypes', $fieldTypes);
             /* Load product types lists */
             $customsList = $field_model->getCustomsList();
             $this->assignRef('customsList', JHTML::_('select.genericlist', $customsList, 'customlist'));
             $ChildCustomRelation = $field_model->getProductChildCustomRelation();
             $this->assignRef('ChildCustomRelation', $ChildCustomRelation);
             /* Set up labels */
             if ($product->product_parent_id > 0) {
                 $info_label = JText::_('COM_VIRTUEMART_PRODUCT_FORM_ITEM_INFO_LBL');
                 $status_label = JText::_('COM_VIRTUEMART_PRODUCT_FORM_ITEM_STATUS_LBL');
                 $dim_weight_label = JText::_('COM_VIRTUEMART_PRODUCT_FORM_ITEM_DIM_WEIGHT_LBL');
                 $images_label = JText::_('COM_VIRTUEMART_PRODUCT_FORM_ITEM_IMAGES_LBL');
                 $delete_message = JText::_('COM_VIRTUEMART_PRODUCT_FORM_DELETE_ITEM_MSG');
             } else {
                 if ($task == 'add') {
                     $action = JText::_('COM_VIRTUEMART_PRODUCT_FORM_NEW_PRODUCT_LBL');
                 } else {
                     $action = JText::_('COM_VIRTUEMART_PRODUCT_FORM_UPDATE_ITEM_LBL');
                 }
                 $info_label = JText::_('COM_VIRTUEMART_PRODUCT_FORM_PRODUCT_INFO_LBL');
                 $status_label = JText::_('COM_VIRTUEMART_PRODUCT_FORM_PRODUCT_STATUS_LBL');
                 $dim_weight_label = JText::_('COM_VIRTUEMART_PRODUCT_FORM_PRODUCT_DIM_WEIGHT_LBL');
                 $images_label = JText::_('COM_VIRTUEMART_PRODUCT_FORM_PRODUCT_IMAGES_LBL');
                 $delete_message = JText::_('COM_VIRTUEMART_PRODUCT_FORM_DELETE_PRODUCT_MSG');
             }
             $config = JFactory::getConfig();
             $tzoffset = $config->getValue('config.offset');
             $this->assignRef('tzoffset', $tzoffset);
             // Assign the values
             $this->assignRef('pane', $pane);
             $this->assignRef('editor', $editor);
             $this->assignRef('product', $product);
             $this->assignRef('currencies', $currencies);
             //no need moved to top $this->assignRef('manufacturers', $manufacturers);
             $this->assignRef('related_products', $related_products);
             $this->assignRef('product_parent', $product_parent);
             /* Assign label values */
             $this->assignRef('action', $action);
             $this->assignRef('info_label', $info_label);
             $this->assignRef('status_label', $status_label);
             $this->assignRef('dim_weight_label', $dim_weight_label);
             $this->assignRef('images_label', $images_label);
             $this->assignRef('delete_message', $delete_message);
             $this->assignRef('lists', $lists);
             // Toolbar
             $text = "";
             if ($task == 'edit') {
                 if ($product->product_sku) {
                     $sku = ' (' . $product->product_sku . ')';
                 } else {
                     $sku = "";
                 }
                 if (!empty($product->virtuemart_product_id)) {
                     $text = '<a href="' . juri::root() . 'index.php?option=com_virtuemart&view=productdetails&virtuemart_product_id=' . $product->virtuemart_product_id . '" target="_blank" >' . $product->product_name . $sku . '<span class="vm2-modallink"></span></a>';
                 } else {
                     $text = $product->product_name . $sku;
                 }
             }
             $this->SetViewTitle('PRODUCT', $text);
             //JToolBarHelper::custom('sentproductemailtocustomer', 'email_32', 'email_32',  'COM_VIRTUEMART_PRODUCT_EMAILTOSHOPPER' ,false);
             $this->addStandardEditViewCommands($product->virtuemart_product_id);
             break;
         default:
             if ($product_parent_id = JRequest::getInt('product_parent_id', false)) {
                 $product_parent = $model->getProduct($product_parent_id);
                 $title = 'PRODUCT_CHILDREN_LIST';
                 $link_to_parent = JHTML::_('link', JRoute::_('index.php?view=product&task=edit&virtuemart_product_id=' . $product_parent->virtuemart_product_id . '&option=com_virtuemart'), $product_parent->product_name, array('title' => JText::_('COM_VIRTUEMART_EDIT_PARENT') . ' ' . $product_parent->product_name));
                 $msg = JText::_('COM_VIRTUEMART_PRODUCT_OF') . " " . $link_to_parent;
             } else {
                 $title = 'PRODUCT';
                 $msg = "";
             }
             $this->db = JFactory::getDBO();
             $this->SetViewTitle($title, $msg);
             $this->addStandardDefaultViewLists($model, 'created_on');
             /* Get the list of products */
             $productlist = $model->getProductListing(false, false, false, false, true);
             //The pagination must now always set AFTER the model load the listing
             $pagination = $model->getPagination();
             $this->assignRef('pagination', $pagination);
             /* Get the category tree */
             $categoryId = $model->virtuemart_category_id;
             //OSP switched to filter in model, was JRequest::getInt('virtuemart_category_id');
             $category_tree = ShopFunctions::categoryListTree(array($categoryId));
             $this->assignRef('category_tree', $category_tree);
             // Check for Media Items and Reviews, set the price
             $media = VmModel::getModel('media');
             $productreviews = VmModel::getModel('ratings');
             /* Load the product price */
             if (!class_exists('calculationHelper')) {
                 require JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'calculationh.php';
             }
             $vendor_model = VmModel::getModel('vendor');
             foreach ($productlist as $virtuemart_product_id => $product) {
                 $product->mediaitems = count($product->virtuemart_media_id);
                 $product->reviews = $productreviews->countReviewsForProduct($product->virtuemart_product_id);
                 $vendor_model->setId($product->virtuemart_vendor_id);
                 $vendor = $vendor_model->getVendor();
                 $currencyDisplay = CurrencyDisplay::getInstance($vendor->vendor_currency, $vendor->virtuemart_vendor_id);
                 if (!empty($product->product_price) && !empty($product->product_currency)) {
                     $product->product_price_display = $currencyDisplay->priceDisplay($product->product_price, (int) $product->product_currency, 1, true);
                 }
                 /* Write the first 5 categories in the list */
                 $product->categoriesList = shopfunctions::renderGuiList('virtuemart_category_id', '#__virtuemart_product_categories', 'virtuemart_product_id', $product->virtuemart_product_id, 'category_name', '#__virtuemart_categories', 'virtuemart_category_id', 'category');
             }
             $mf_model = VmModel::getModel('manufacturer');
             $manufacturers = $mf_model->getManufacturerDropdown();
             $this->assignRef('manufacturers', $manufacturers);
             /* add Search filter in lists*/
             /* Search type */
             $options = array('' => JText::_('COM_VIRTUEMART_LIST_EMPTY_OPTION'), 'parent' => JText::_('COM_VIRTUEMART_PRODUCT_LIST_SEARCH_BY_PARENT_PRODUCT'), 'product' => JText::_('COM_VIRTUEMART_PRODUCT_LIST_SEARCH_BY_DATE_TYPE_PRODUCT'), 'price' => JText::_('COM_VIRTUEMART_PRODUCT_LIST_SEARCH_BY_DATE_TYPE_PRICE'), 'withoutprice' => JText::_('COM_VIRTUEMART_PRODUCT_LIST_SEARCH_BY_DATE_TYPE_WITHOUTPRICE'));
             $this->lists['search_type'] = VmHTML::selectList('search_type', JRequest::getVar('search_type'), $options);
             /* Search order */
             $options = array('bf' => JText::_('COM_VIRTUEMART_PRODUCT_LIST_SEARCH_BY_DATE_BEFORE'), 'af' => JText::_('COM_VIRTUEMART_PRODUCT_LIST_SEARCH_BY_DATE_AFTER'));
             $this->lists['search_order'] = VmHTML::selectList('search_order', JRequest::getVar('search_order'), $options);
             // Toolbar
             JToolBarHelper::save('sentproductemailtoshoppers', JText::_('COM_VIRTUEMART_PRODUCT_EMAILTOSHOPPERS'));
             JToolBarHelper::custom('createchild', 'new', 'new', JText::_('COM_VIRTUEMART_PRODUCT_CHILD'), true);
             JToolBarHelper::custom('cloneproduct', 'copy', 'copy', JText::_('COM_VIRTUEMART_PRODUCT_CLONE'), true);
             JToolBarHelper::custom('addrating', 'default', '', JText::_('COM_VIRTUEMART_ADD_RATING'), true);
             $this->addStandardDefaultViewCommands();
             $this->assignRef('productlist', $productlist);
             $this->assignRef('virtuemart_category_id', $categoryId);
             $this->assignRef('model', $model);
             break;
     }
     parent::display($tpl);
 }
 /**
  * Calcule final price to product
  *
  * @param VirtueMartCart $cart
  * @param $key
  * @return float
  */
 private function calculePrice(VirtueMartCart $cart, $key)
 {
     if (!class_exists('calculationHelper')) {
         require JPATH_VM_ADMINISTRATOR . DS . 'components' . DS . 'virtuemart' . DS . 'helpers' . DS . 'calculationh.php';
     }
     $calculator = calculationHelper::getInstance();
     $cart_prices = $calculator->getCheckoutPrices($cart);
     $sales_price = $cart->products[$key]->product_price;
     foreach ($cart_prices as $prices_key => $prices) {
         if ($key === $prices_key) {
             $sales_price = $prices["salesPrice"];
         }
     }
     return $sales_price;
 }
示例#14
0
 public static function getInstance()
 {
     if (!is_object(self::$_instance)) {
         self::$_instance = new calculationHelper();
     } else {
         $jnow = JFactory::getDate();
         self::$_instance->_now = $jnow->toMySQL();
     }
     return self::$_instance;
 }
示例#15
0
文件: product.php 项目: lenard112/cms
 /**
  * Gets the price for a variant
  *
  * @author Max Milbers
  */
 public function getPrice($product, $quantity)
 {
     $db = JFactory::getDBO();
     // 		vmdebug('strange',$product);
     if (!is_object($product)) {
         $product = $this->getProduct($product, TRUE, FALSE, TRUE, $quantity);
     }
     //if (empty($product->customfields) and !empty($product->virtuemart_customfield_id)) {
     if (empty($product->customfields)) {
         $customfieldsModel = VmModel::getModel('Customfields');
         $product->customfields = $customfieldsModel->getCustomEmbeddedProductCustomFields($product->allIds);
     }
     // Loads the product price details
     if (!class_exists('calculationHelper')) {
         require JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'calculationh.php';
     }
     $calculator = calculationHelper::getInstance();
     // Calculate the modificator
     $customfieldsModel = VmModel::getModel('Customfields');
     $variantPriceModification = $customfieldsModel->calculateModificators($product);
     //$variantPriceModification = $calculator->calculateModificators ($product, $customVariant);
     $prices = $calculator->getProductPrices($product, $variantPriceModification, $quantity);
     return $prices;
 }
示例#16
0
 /**
  * Gets the price for a variant
  *
  * @author Max Milbers
  */
 public function getPrice($product, $customVariant, $quantity)
 {
     $this->_db = JFactory::getDBO();
     // 		vmdebug('strange',$product);
     if (!is_object($product)) {
         // 		vmError('deprecated use of getPrice');
         $product = $this->getProduct($product, TRUE, FALSE, TRUE, $quantity);
         // 		return false;
     }
     // Loads the product price details
     if (!class_exists('calculationHelper')) {
         require JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'calculationh.php';
     }
     $calculator = calculationHelper::getInstance();
     // Calculate the modificator
     $variantPriceModification = $calculator->calculateModificators($product, $customVariant);
     $prices = $calculator->getProductPrices($product, $variantPriceModification, $quantity);
     return $prices;
 }
 /**
  * Get product prices
  * 
  * @copyright 
  * @author 		RolandD
  * @todo 
  * @see 
  * @access 		public
  * @param		int	$product_id	the ID of the product 
  * @return 
  * @since 		4.0
  */
 private function _getProductPrice($product_id)
 {
     if (!isset($this->_prices[$product_id])) {
         // Define VM constant to make the classes work
         if (!defined('JPATH_VM_ADMINISTRATOR')) {
             define('JPATH_VM_ADMINISTRATOR', JPATH_ADMINISTRATOR . '/components/com_virtuemart/');
         }
         // Load the configuration for the currency formatting
         require_once JPATH_ADMINISTRATOR . '/components/com_virtuemart/helpers/config.php';
         // Include the calculation helper
         require_once JPATH_ADMINISTRATOR . '/components/com_virtuemart/helpers/calculationh.php';
         $calc = calculationHelper::getInstance();
         // Include the version class to compare
         require_once JPATH_ADMINISTRATOR . '/components/com_virtuemart/version.php';
         // Do a version check due to changed core code
         if (vmVersion::$RELEASE > '2.0.6') {
             require_once JPATH_ADMINISTRATOR . '/components/com_virtuemart/models/product.php';
             $product = $this->getInstance('Product', 'VirtueMartModel');
             $prices = $calc->getProductPrices($product->getProductSingle($product_id));
         } else {
             $prices = $calc->getProductPrices($product_id);
         }
         if (is_array($prices)) {
             $this->_prices[$product_id] = array_change_key_case($prices, CASE_LOWER);
         } else {
             $this->_prices[$product_id] = array();
         }
     }
     return $this->_prices[$product_id];
 }
示例#18
0
 public static function setShopperGroupsController($cart = null)
 {
     // we need to alter shopper group for business when set to:
     $is_business = JRequest::getVar('opc_is_business', 0);
     $remove = array();
     //require_once(JPATH_OPC.DS.'helpers'.DS.'loader.php');
     OPCShopperGroups::getSetShopperGroup();
     if (!class_exists('VirtueMartModelShopperGroup')) {
         if (file_exists(JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'shoppergroup.php')) {
             require JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'shoppergroup.php';
         } else {
             return;
         }
     }
     if (!method_exists('VirtueMartModelShopperGroup', 'appendShopperGroups')) {
         return 1;
     }
     include JPATH_ROOT . DS . 'components' . DS . 'com_onepage' . DS . 'config' . DS . 'onepage.cfg.php';
     if (!empty($business_shopper_group) || !empty($visitor_shopper_group)) {
         if (class_exists('VirtueMartModelShopperGroup')) {
             $shoppergroupmodel = new VirtueMartModelShopperGroup();
             if (method_exists($shoppergroupmodel, 'removeSessionSgrps')) {
                 if (method_exists($shoppergroupmodel, 'appendShopperGroups')) {
                     if (!empty($is_business)) {
                         // we will differenciate between default and anonymous shopper group
                         // default is used for non-logged users
                         // anononymous is used for logged in users as guests
                         OPCShopperGroups::setShopperGroups($business_shopper_group);
                         $remove[] = $visitor_shopper_group;
                         // function appendShopperGroups(&$shopperGroups,$user,$onlyPublished = FALSE,$vendorId=1){
                         // remove previous:
                         /*
                         $session = JFactory::getSession();
                         $shoppergroup_ids = $session->get('vm_shoppergroups_add',array(),'vm');
                         $shoppergroupmodel->removeSessionSgrps($shoppergroup_ids); 
                         $new_shoppergroups = array(); 
                         $new_shoppergroups[] = $business_shopper_group;  
                         $shoppergroup_ids = $session->set('vm_shoppergroups_add',$new_shoppergroups,'vm');
                         $shoppergroupmodel->appendShopperGroups($new_shoppergroups, null); 
                         
                         JRequest::setVar('virtuemart_shoppergroup_id', $new_shoppergroups, 'post');
                         */
                         //appendShopperGroups
                     } else {
                         OPCShopperGroups::setShopperGroups($visitor_shopper_group);
                         $remove[] = $business_shopper_group;
                         /*
                         	 $shoppergroupmodel = new VirtueMartModelShopperGroup(); 
                         	 // function appendShopperGroups(&$shopperGroups,$user,$onlyPublished = FALSE,$vendorId=1){
                         	 // remove previous: 
                         	 $session = JFactory::getSession();
                         	 $shoppergroup_ids = $session->get('vm_shoppergroups_add',array(),'vm');
                         	 $shoppergroupmodel->removeSessionSgrps($shoppergroup_ids); 
                         	 $new_shoppergroups = array(); 
                         	 $new_shoppergroups[] = $visitor_shopper_group; 
                         	 $shoppergroup_ids = $session->set('vm_shoppergroups_add',$new_shoppergroups,'vm');
                         	 $shoppergroupmodel->appendShopperGroups($new_shoppergroups, null); 
                         	 JRequest::setVar('virtuemart_shoppergroup_id', $new_shoppergroups, 'post');
                         */
                     }
                 }
             }
         }
     }
     // EU VAT shopper group:
     if (!empty($euvat_shopper_group)) {
         $removeu = true;
         $session = JFactory::getSession();
         $vatids = $session->get('opc_vat', array());
         if (!is_array($vatids)) {
             $vatids = @unserialize($vatids);
         }
         //BIT vat checker:
         if (!empty($vatids['field'])) {
             $euvat = JRequest::getVar($vatids['field'], '');
             $euvat = preg_replace("/[^a-zA-Z0-9]/", "", $euvat);
             $euvat = strtoupper($euvat);
             if (!empty($cart)) {
                 $address = $cart->ST == 0 ? $cart->BT : $cart->ST;
                 $country = $address['virtuemart_country_id'];
             } else {
                 $country = JRequest::getVar('virtuemart_country_id');
             }
             $vathash = $country . '_' . $euvat;
             $home = 'NL';
             if (!class_exists('ShopFunctions')) {
                 require JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'shopfunctions.php';
             }
             $country_2_code = shopFunctions::getCountryByID($country, 'country_2_code');
             $home = explode(',', $home_vat_countries);
             $list = array();
             if (is_array($home)) {
                 foreach ($home as $k => $v) {
                     $list[] = strtoupper(trim($v));
                 }
             } else {
                 $list[] = $v;
             }
             if (!in_array($country_2_code, $list)) {
                 if (!empty($euvat)) {
                     $euvat = strtoupper($euvat);
                     if (!empty($vatids[$vathash])) {
                         //change OPC VAT shopper group:
                         OPCShopperGroups::setShopperGroups($euvat_shopper_group);
                         $removeu = false;
                     }
                 }
             }
         }
         if ($removeu) {
             $remove[] = $euvat_shopper_group;
         }
     }
     OPCShopperGroups::setShopperGroups(-1, $remove);
     if (class_exists('calculationHelper')) {
         calculationHelper::$_instance = null;
     }
     $session = JFactory::getSession();
     $shoppergroup_ids = $session->get('vm_shoppergroups_add', array(), 'vm');
 }
示例#19
0
 /**
  * update the plugin cart_prices
  *
  * @author Valérie Isaksen
  *
  * @param $cart_prices: $cart_prices['salesPricePayment'] and $cart_prices['paymentTax'] updated. Displayed in the cart.
  * @param $value :   fee
  * @param $tax_id :  tax id
  */
 function setCartPrices(VirtueMartCart $cart, &$cart_prices, $method, $progressive = true)
 {
     if (!class_exists('calculationHelper')) {
         require VMPATH_ADMIN . DS . 'helpers' . DS . 'calculationh.php';
     }
     $_psType = ucfirst($this->_psType);
     $calculator = calculationHelper::getInstance();
     $cart_prices[$this->_psType . 'Value'] = $calculator->roundInternal($this->getCosts($cart, $method, $cart_prices), 'salesPrice');
     if (!isset($cart_prices[$this->_psType . 'Value'])) {
         $cart_prices[$this->_psType . 'Value'] = 0.0;
     }
     if (!isset($cart_prices[$this->_psType . 'Tax'])) {
         $cart_prices[$this->_psType . 'Tax'] = 0.0;
     }
     if ($this->_psType == 'payment') {
         $cartTotalAmountOrig = $this->getCartAmount($cart_prices);
         if (!$progressive) {
             //Simple
             $cartTotalAmount = ($cartTotalAmountOrig + $method->cost_per_transaction) * (1 + $method->cost_percent_total * 0.01);
             //vmdebug('Simple $cartTotalAmount = ('.$cartTotalAmountOrig.' + '.$method->cost_per_transaction.') * (1 + ('.$method->cost_percent_total.' * 0.01)) = '.$cartTotalAmount );
             //vmdebug('Simple $cartTotalAmount = '.($cartTotalAmountOrig + $method->cost_per_transaction).' * '. (1 + $method->cost_percent_total * 0.01) .' = '.$cartTotalAmount );
         } else {
             //progressive
             $cartTotalAmount = ($cartTotalAmountOrig + $method->cost_per_transaction) / (1 - $method->cost_percent_total * 0.01);
             //vmdebug('Progressive $cartTotalAmount = ('.$cartTotalAmountOrig.' + '.$method->cost_per_transaction.') / (1 - ('.$method->cost_percent_total.' * 0.01)) = '.$cartTotalAmount );
             //vmdebug('Progressive $cartTotalAmount = '.($cartTotalAmountOrig + $method->cost_per_transaction) .' / '. (1 - $method->cost_percent_total * 0.01) .' = '.$cartTotalAmount );
         }
         $cart_prices[$this->_psType . 'Value'] = $cartTotalAmount - $cartTotalAmountOrig;
     }
     if (!isset($cart_prices['salesPrice' . $_psType])) {
         $cart_prices['salesPrice' . $_psType] = $cart_prices[$this->_psType . 'Value'];
     }
     $taxrules = array();
     if (isset($method->tax_id) and (int) $method->tax_id === -1) {
     } else {
         if (!empty($method->tax_id)) {
             $cart_prices[$this->_psType . '_calc_id'] = $method->tax_id;
             $db = JFactory::getDBO();
             $q = 'SELECT * FROM #__virtuemart_calcs WHERE `virtuemart_calc_id`="' . $method->tax_id . '" ';
             $db->setQuery($q);
             $taxrules = $db->loadAssocList();
             if (!empty($taxrules)) {
                 foreach ($taxrules as &$rule) {
                     if (!isset($rule['subTotal'])) {
                         $rule['subTotal'] = 0;
                     }
                     if (!isset($rule['taxAmount'])) {
                         $rule['taxAmount'] = 0;
                     }
                     $rule['subTotalOld'] = $rule['subTotal'];
                     $rule['taxAmountOld'] = $rule['taxAmount'];
                     $rule['taxAmount'] = 0;
                     $rule['subTotal'] = $cart_prices[$this->_psType . 'Value'];
                     $cart_prices[$this->_psType . 'TaxPerID'][$rule['virtuemart_calc_id']] = $calculator->roundInternal($calculator->roundInternal($calculator->interpreteMathOp($rule, $rule['subTotal'])) - $rule['subTotal'], 'salesPrice');
                     $cart_prices[$this->_psType . 'Tax'] += $cart_prices[$this->_psType . 'TaxPerID'][$rule['virtuemart_calc_id']];
                 }
             }
         } else {
             $taxrules = array_merge($cart->cartData['VatTax'], $cart->cartData['taxRulesBill']);
             if (!empty($taxrules)) {
                 $denominator = 0.0;
                 foreach ($taxrules as &$rule) {
                     //Quickn dirty
                     if (!isset($rule['calc_kind'])) {
                         $rule = (array) VmModel::getModel('calc')->getCalc($rule['virtuemart_calc_id']);
                     }
                     if (!isset($rule['subTotal'])) {
                         $rule['subTotal'] = 0;
                     }
                     if (!isset($rule['taxAmount'])) {
                         $rule['taxAmount'] = 0;
                     }
                     $denominator += $rule['subTotal'] - $rule['taxAmount'];
                     $rule['subTotalOld'] = $rule['subTotal'];
                     $rule['subTotal'] = 0;
                     $rule['taxAmountOld'] = $rule['taxAmount'];
                     $rule['taxAmount'] = 0;
                 }
                 if (empty($denominator)) {
                     $denominator = 1;
                 }
                 foreach ($taxrules as &$rule) {
                     $frac = ($rule['subTotalOld'] - $rule['taxAmountOld']) / $denominator;
                     $rule['subTotal'] = $cart_prices[$this->_psType . 'Value'] * $frac;
                     if (!isset($cart_prices[$this->_psType . 'Tax'])) {
                         $cart_prices[$this->_psType . 'Tax'] = 0.0;
                     }
                     $cart_prices[$this->_psType . 'TaxPerID'][$rule['virtuemart_calc_id']] = $calculator->roundInternal($calculator->roundInternal($calculator->interpreteMathOp($rule, $rule['subTotal'])) - $rule['subTotal'], 'salesPrice');
                     $cart_prices[$this->_psType . 'Tax'] += $cart_prices[$this->_psType . 'TaxPerID'][$rule['virtuemart_calc_id']];
                 }
             }
         }
     }
     if (empty($method->cost_per_transaction)) {
         $method->cost_per_transaction = 0.0;
     }
     if (empty($method->cost_percent_total)) {
         $method->cost_percent_total = 0.0;
     }
     if (count($taxrules) > 0) {
         $cart_prices['salesPrice' . $_psType] = $calculator->roundInternal($calculator->executeCalculation($taxrules, $cart_prices[$this->_psType . 'Value'], true, false), 'salesPrice');
         //			$cart_prices[$this->_psType . 'Tax'] = $calculator->roundInternal (($cart_prices['salesPrice' . $_psType] -  $cart_prices[$this->_psType . 'Value']), 'salesPrice');
         reset($taxrules);
         foreach ($taxrules as &$rule) {
             if (!isset($cart_prices[$this->_psType . '_calc_id']) or !is_array($cart_prices[$this->_psType . '_calc_id'])) {
                 $cart_prices[$this->_psType . '_calc_id'] = array();
             }
             $cart_prices[$this->_psType . '_calc_id'][] = $rule['virtuemart_calc_id'];
             if (isset($rule['subTotalOld'])) {
                 $rule['subTotal'] += $rule['subTotalOld'];
             }
             if (isset($rule['taxAmountOld'])) {
                 $rule['taxAmount'] += $rule['taxAmountOld'];
             }
         }
     } else {
         $cart_prices['salesPrice' . $_psType] = $cart_prices[$this->_psType . 'Value'];
         $cart_prices[$this->_psType . 'Tax'] = 0;
         $cart_prices[$this->_psType . '_calc_id'] = 0;
     }
     return $cart_prices['salesPrice' . $_psType];
 }
示例#20
0
 /**
  * prepare display of cart
  *
  * @author RolandD
  * @author Max Milbers
  * @access public
  */
 public function prepareCartData($checkAutomaticSelected = true)
 {
     // Get the products for the cart
     // 		$prices = array();
     $product_prices = $this->getCartPrices($checkAutomaticSelected);
     if (empty($product_prices)) {
         return null;
     }
     if (!class_exists('CurrencyDisplay')) {
         require JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'currencydisplay.php';
     }
     $currency = CurrencyDisplay::getInstance();
     if (!class_exists('calculationHelper')) {
         require JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'calculationh.php';
     }
     $calculator = calculationHelper::getInstance();
     // 		$this->prices = $prices;
     $this->pricesCurrency = $currency->getCurrencyForDisplay();
     if (!class_exists('vmPSPlugin')) {
         require JPATH_VM_PLUGINS . DS . 'vmpsplugin.php';
     }
     JPluginHelper::importPlugin('vmpayment');
     $dispatcher = JDispatcher::getInstance();
     $returnValues = $dispatcher->trigger('plgVmgetPaymentCurrency', array($this->virtuemart_paymentmethod_id, &$this->paymentCurrency));
     $cartData = $calculator->getCartData();
     // 		$this->setCartIntoSession();
     return $cartData;
 }
 /**
  *  TODO This is html and view stuff and MUST NOT be in the model, notice by Max
  * render custom fields display cart FE
  */
 public static function CustomsFieldCartDisplay($priceKey, $product)
 {
     if (empty($calculator)) {
         if (!class_exists('calculationHelper')) {
             require JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'calculationh.php';
         }
         $calculator = calculationHelper::getInstance();
     }
     $variantmods = $calculator->parseModifier($priceKey);
     return self::customFieldDisplay($product, $variantmods, '<div class="vm-customfield-cart">', 'plgVmOnViewCart');
 }
示例#22
0
 static function getCheckoutPrices(&$cart, $auto, &$vm2015, $other = null)
 {
     $cart->virtuemart_shipmentmethod_id = (int) $cart->virtuemart_shipmentmethod_id;
     $cart->virtuemart_paymentmethod_id = (int) $cart->virtuemart_paymentmethod_id;
     $saved_id = $cart->virtuemart_shipmentmethod_id;
     $payment_id = $cart->virtuemart_paymentmethod_id;
     $savedcoupon = $cart->couponCode;
     if (!class_exists('calculationHelper')) {
         require JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'calculationh.php';
     }
     // support for vm2.0.2 where getInstance returned fatal error
     if (isset(calculationHelper::$_instance) && is_object(calculationHelper::$_instance)) {
         $calc = calculationHelper::$_instance;
     } else {
         $calc = calculationHelper::getInstance();
     }
     if (method_exists($calc, 'setCartPrices')) {
         $vm2015 = true;
     } else {
         $vm2015 = false;
     }
     if ($vm2015) {
         //$calc->_cartData = null;
         //$ref->cart->cartData = null;
         $calc->setCartPrices(array());
     }
     $prices = $calc->getCheckoutPrices($cart, false, $other);
     if (is_null($prices)) {
         $prices = $calc->_cart->cartPrices;
     }
     if (method_exists($calc, 'getCartData')) {
         $cart->OPCCartData = $calc->getCartData();
     }
     $cart->virtuemart_shipmentmethod_id = $saved_id;
     $cart->couponCode = $savedcoupon;
     $cart->virtuemart_paymentmethod_id = $payment_id;
     // =  $cart->virtuemart_paymentmethod_id;
     return $prices;
 }
示例#23
0
 public static function getInstance()
 {
     if (!is_object(self::$_instance)) {
         self::$_instance = new calculationHelper();
     } else {
         //We store in UTC and use here of course also UTC
         $jnow = JFactory::getDate();
         self::$_instance->_now = $jnow->toMySQL();
     }
     return self::$_instance;
 }
示例#24
0
 /**
  * Gets the price for a variant
  *
  * @author Max Milbers
  */
 public function getPrice($product, $quantity)
 {
     if (!is_object($product)) {
         $product = $this->getProduct($product, TRUE, FALSE, TRUE, $quantity);
     }
     if (empty($product->customfields) and !empty($product->allIds)) {
         $customfieldsModel = VmModel::getModel('Customfields');
         $product->modificatorSum = null;
         $product->customfields = $customfieldsModel->getCustomEmbeddedProductCustomFields($product->allIds);
     }
     // Loads the product price details
     if (!class_exists('calculationHelper')) {
         require VMPATH_ADMIN . DS . 'helpers' . DS . 'calculationh.php';
     }
     $calculator = calculationHelper::getInstance();
     // Calculate the modificator
     $customfieldsModel = VmModel::getModel('Customfields');
     $variantPriceModification = $customfieldsModel->calculateModificators($product);
     $prices = $calculator->getProductPrices($product, $variantPriceModification, $quantity);
     return $prices;
 }
示例#25
0
 public function getCartPrices($checkAutomaticSelected = true)
 {
     if (!class_exists('calculationHelper')) {
         require JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'calculationh.php';
     }
     $calculator = calculationHelper::getInstance();
     $this->pricesUnformatted = $calculator->getCheckoutPrices($this, $checkAutomaticSelected);
     return $this->pricesUnformatted;
 }
示例#26
0
 /**
  * @author Max Milbers
  * @param $product
  * @param $customfield
  */
 public function displayProductCustomfieldFE(&$product, &$customfields)
 {
     if (!class_exists('calculationHelper')) {
         require VMPATH_ADMIN . DS . 'helpers' . DS . 'calculationh.php';
     }
     $calculator = calculationHelper::getInstance();
     $selectList = array();
     $dynChilds = 1;
     //= array();
     $session = JFactory::getSession();
     $virtuemart_category_id = $session->get('vmlastvisitedcategoryid', 0, 'vm');
     foreach ($customfields as $k => &$customfield) {
         if (!isset($customfield->display)) {
             $customfield->display = '';
         }
         $calculator->_product = $product;
         if (!class_exists('vmCustomPlugin')) {
             require VMPATH_PLUGINLIBS . DS . 'vmcustomplugin.php';
         }
         if ($customfield->field_type == "E") {
             JPluginHelper::importPlugin('vmcustom');
             $dispatcher = JDispatcher::getInstance();
             $ret = $dispatcher->trigger('plgVmOnDisplayProductFEVM3', array(&$product, &$customfield));
             continue;
         }
         $fieldname = 'field[' . $product->virtuemart_product_id . '][' . $customfield->virtuemart_customfield_id . '][customfield_value]';
         $customProductDataName = 'customProductData[' . $product->virtuemart_product_id . '][' . $customfield->virtuemart_custom_id . ']';
         //This is a kind of fallback, setting default of custom if there is no value of the productcustom
         $customfield->customfield_value = empty($customfield->customfield_value) ? $customfield->custom_value : $customfield->customfield_value;
         $type = $customfield->field_type;
         $idTag = (int) $product->virtuemart_product_id . '-' . $customfield->virtuemart_customfield_id;
         $idTag = $idTag . 'customProductData';
         $idTag = VmHtml::ensureUniqueId($idTag);
         if (!class_exists('CurrencyDisplay')) {
             require VMPATH_ADMIN . DS . 'helpers' . DS . 'currencydisplay.php';
         }
         $currency = CurrencyDisplay::getInstance();
         switch ($type) {
             case 'C':
                 $html = '';
                 $dropdowns = array();
                 if (isset($customfield->options->{$product->virtuemart_product_id})) {
                     $productSelection = $customfield->options->{$product->virtuemart_product_id};
                 } else {
                     $productSelection = false;
                 }
                 $ignore = array();
                 foreach ($customfield->options as $product_id => $variants) {
                     foreach ($variants as $k => $variant) {
                         //if(in_array($variant,$ignore)){ vmdebug('Product to ignore, continue',$product_id,$k,$variant);continue;}
                         if (!isset($dropdowns[$k]) or !is_array($dropdowns[$k])) {
                             $dropdowns[$k] = array();
                         }
                         if (!in_array($variant, $dropdowns[$k])) {
                             if ($k == 0 or !$productSelection) {
                                 $dropdowns[$k][] = $variant;
                             } else {
                                 if ($k > 0 and $productSelection[$k - 1] == $variants[$k - 1]) {
                                     $break = false;
                                     for ($h = 1; $h <= $k; $h++) {
                                         if ($productSelection[$h - 1] != $variants[$h - 1]) {
                                             //$ignore[] = $variant;
                                             $break = true;
                                         }
                                     }
                                     if (!$break) {
                                         $dropdowns[$k][] = $variant;
                                     }
                                 } else {
                                     //	break;
                                 }
                             }
                         }
                     }
                 }
                 $tags = array();
                 foreach ($customfield->selectoptions as $k => $soption) {
                     $options = array();
                     $selected = false;
                     foreach ($dropdowns[$k] as $i => $elem) {
                         $elem = trim((string) $elem);
                         $text = $elem;
                         if ($soption->clabel != '' and in_array($soption->voption, self::$dimensions)) {
                             $rd = $soption->clabel;
                             if (is_numeric($rd) and is_numeric($elem)) {
                                 $text = number_format(round((double) $elem, (int) $rd), $rd);
                             }
                             //vmdebug('($dropdowns[$k] in DIMENSION value = '.$elem.' r='.$rd.' '.$text);
                         } else {
                             if ($soption->voption === 'clabels' and $soption->clabel != '') {
                                 $text = vmText::_($elem);
                             }
                         }
                         if ($elem == '0') {
                             $text = vmText::_('COM_VIRTUEMART_LIST_EMPTY_OPTION');
                         }
                         $options[] = array('value' => $elem, 'text' => $text);
                         if ($productSelection and $productSelection[$k] == $elem) {
                             $selected = $elem;
                         }
                     }
                     if (empty($selected)) {
                         $product->orderable = false;
                     }
                     $idTagK = $idTag . 'cvard' . $k;
                     if ($customfield->showlabels) {
                         if (in_array($soption->voption, self::$dimensions)) {
                             $soption->slabel = vmText::_('COM_VIRTUEMART_' . strtoupper($soption->voption));
                         } else {
                             if (!empty($soption->clabel) and !in_array($soption->voption, self::$dimensions)) {
                                 $soption->slabel = vmText::_($soption->clabel);
                             }
                         }
                         if (isset($soption->slabel)) {
                             $html .= '<span class="vm-cmv-label" >' . $soption->slabel . '</span>';
                         }
                     }
                     $attribs = array('class' => 'vm-chzn-select cvselection no-vm-bind', 'data-dynamic-update' => '1');
                     if ('productdetails' != vRequest::getCmd('view')) {
                         $attribs['reload'] = '1';
                     }
                     $html .= JHtml::_('select.genericlist', $options, $fieldname, $attribs, "value", "text", $selected, $idTagK);
                     $tags[] = $idTagK;
                 }
                 $Itemid = vRequest::getInt('Itemid', '');
                 // '&Itemid=127';
                 if (!empty($Itemid)) {
                     $Itemid = '&Itemid=' . $Itemid;
                 }
                 //create array for js
                 $jsArray = array();
                 $url = '';
                 foreach ($customfield->options as $product_id => $variants) {
                     $url = JRoute::_('index.php?option=com_virtuemart&view=productdetails&virtuemart_category_id=' . $virtuemart_category_id . '&virtuemart_product_id=' . $product_id . $Itemid);
                     $jsArray[] = '["' . $url . '","' . implode('","', $variants) . '"]';
                 }
                 vmJsApi::addJScript('cvfind', false, false);
                 $jsVariants = implode(',', $jsArray);
                 $j = "\n\t\t\t\t\t\tjQuery('#" . implode(',#', $tags) . "').off('change',Virtuemart.cvFind);\n\t\t\t\t\t\tjQuery('#" . implode(',#', $tags) . "').on('change', { variants:[" . $jsVariants . "] },Virtuemart.cvFind);\n\t\t\t\t\t";
                 $hash = md5(implode('', $tags));
                 vmJsApi::addJScript('cvselvars' . $hash, $j, false);
                 //Now we need just the JS to reload the correct product
                 $customfield->display = $html;
                 break;
             case 'A':
                 $html = '';
                 //if($selectedFound) continue;
                 $options = array();
                 $productModel = VmModel::getModel('product');
                 //Note by Jeremy Magne (Daycounts) 2013-08-31
                 //Previously the the product model is loaded but we need to ensure the correct product id is set because the getUncategorizedChildren does not get the product id as parameter.
                 //In case the product model was previously loaded, by a related product for example, this would generate wrong uncategorized children list
                 $productModel->setId($customfield->virtuemart_product_id);
                 $uncatChildren = $productModel->getUncategorizedChildren($customfield->withParent);
                 if (!$customfield->withParent or $customfield->withParent and $customfield->parentOrderable) {
                     $options[0] = array('value' => JRoute::_('index.php?option=com_virtuemart&view=productdetails&virtuemart_category_id=' . $virtuemart_category_id . '&virtuemart_product_id=' . $customfield->virtuemart_product_id, FALSE), 'text' => vmText::_('COM_VIRTUEMART_ADDTOCART_CHOOSE_VARIANT'));
                 }
                 $selected = vRequest::getInt('virtuemart_product_id', 0);
                 $selectedFound = false;
                 if (empty($calculator) and $customfield->wPrice) {
                     if (!class_exists('calculationHelper')) {
                         require VMPATH_ADMIN . DS . 'helpers' . DS . 'calculationh.php';
                     }
                     $calculator = calculationHelper::getInstance();
                 }
                 $parentStock = 0;
                 foreach ($uncatChildren as $k => $child) {
                     if (!isset($child[$customfield->customfield_value])) {
                         vmdebug('The child has no value at index ' . $customfield->customfield_value, $customfield, $child);
                     } else {
                         $productChild = $productModel->getProduct((int) $child['virtuemart_product_id'], false);
                         if (!$productChild) {
                             continue;
                         }
                         $available = $productChild->product_in_stock - $productChild->product_ordered;
                         if (VmConfig::get('stockhandle', 'none') == 'disableit_children' and $available <= 0) {
                             continue;
                         }
                         $parentStock += $available;
                         $priceStr = '';
                         if ($customfield->wPrice) {
                             //$product = $productModel->getProductSingle((int)$child['virtuemart_product_id'],false);
                             $productPrices = $calculator->getProductPrices($productChild);
                             $priceStr = ' (' . $currency->priceDisplay($productPrices['salesPrice']) . ')';
                         }
                         $options[] = array('value' => JRoute::_('index.php?option=com_virtuemart&view=productdetails&virtuemart_category_id=' . $virtuemart_category_id . '&virtuemart_product_id=' . $child['virtuemart_product_id']), 'text' => $child[$customfield->customfield_value] . $priceStr);
                         if ($selected == $child['virtuemart_product_id']) {
                             $selectedFound = true;
                             vmdebug($customfield->virtuemart_product_id . ' $selectedFound by vRequest ' . $selected);
                         }
                         //vmdebug('$child productId ',$child['virtuemart_product_id'],$customfield->customfield_value,$child);
                     }
                 }
                 if (!$selectedFound) {
                     $pos = array_search($customfield->virtuemart_product_id, $product->allIds);
                     if (isset($product->allIds[$pos - 1])) {
                         $selected = $product->allIds[$pos - 1];
                         //vmdebug($customfield->virtuemart_product_id.' Set selected to - 1 allIds['.($pos-1).'] = '.$selected.' and count '.$dynChilds);
                         //break;
                     } elseif (isset($product->allIds[$pos])) {
                         $selected = $product->allIds[$pos];
                         //vmdebug($customfield->virtuemart_product_id.' Set selected to allIds['.$pos.'] = '.$selected.' and count '.$dynChilds);
                     } else {
                         $selected = $customfield->virtuemart_product_id;
                         //vmdebug($customfield->virtuemart_product_id.' Set selected to $customfield->virtuemart_product_id ',$selected,$product->allIds);
                     }
                 }
                 $url = 'index.php?option=com_virtuemart&view=productdetails&virtuemart_category_id=' . $virtuemart_category_id . '&virtuemart_product_id=' . $selected;
                 $html .= JHtml::_('select.genericlist', $options, $fieldname, 'onchange="window.top.location.href=this.options[this.selectedIndex].value" size="1" class="vm-chzn-select no-vm-bind" data-dynamic-update="1" ', "value", "text", JRoute::_($url, false), $idTag);
                 vmJsApi::chosenDropDowns();
                 if ($customfield->parentOrderable == 0) {
                     if ($product->product_parent_id == 0) {
                         $product->orderable = FALSE;
                     } else {
                         $product->product_in_stock = $parentStock;
                     }
                 } else {
                 }
                 $dynChilds++;
                 $customfield->display = $html;
                 break;
                 /*Date variant*/
             /*Date variant*/
             case 'D':
                 if (empty($customfield->custom_value)) {
                     $customfield->custom_value = 'LC2';
                 }
                 //Customer selects date
                 if ($customfield->is_input) {
                     $customfield->display = '<span class="product_custom_date">' . vmJsApi::jDate($customfield->customfield_value, $customProductDataName) . '</span>';
                     //vmJsApi::jDate($field->custom_value, 'field['.$row.'][custom_value]','field_'.$row.'_customvalue').$priceInput;
                 } else {
                     $customfield->display = '<span class="product_custom_date">' . vmJsApi::date($customfield->customfield_value, $customfield->custom_value, TRUE) . '</span>';
                 }
                 break;
                 /* text area or editor No vmText, only displayed in BE */
             /* text area or editor No vmText, only displayed in BE */
             case 'X':
             case 'Y':
                 $customfield->display = $customfield->customfield_value;
                 break;
                 /* string or integer */
             /* string or integer */
             case 'B':
             case 'S':
             case 'M':
                 if ($type == 'M') {
                     $selectType = 'select.radiolist';
                     $class = '';
                 } else {
                     $selectType = 'select.genericlist';
                     if (!empty($customfield->is_input)) {
                         vmJsApi::chosenDropDowns();
                         $class = 'class="vm-chzn-select"';
                     }
                 }
                 if ($customfield->is_list and $customfield->is_list != 2) {
                     if (!empty($customfield->is_input)) {
                         $options = array();
                         $values = explode(';', $customfield->custom_value);
                         foreach ($values as $key => $val) {
                             if ($type == 'M') {
                                 $tmp = array('value' => $val, 'text' => $this->displayCustomMedia($val, 'product', $customfield->width, $customfield->height));
                                 $options[] = (object) $tmp;
                             } else {
                                 $options[] = array('value' => $val, 'text' => vmText::_($val));
                             }
                         }
                         $currentValue = $customfield->customfield_value;
                         $customfield->display = JHtml::_($selectType, $options, $customProductDataName . '[' . $customfield->virtuemart_customfield_id . ']', $class, 'value', 'text', $currentValue, $idTag);
                     } else {
                         if ($type == 'M') {
                             $customfield->display = $this->displayCustomMedia($customfield->customfield_value, 'product', $customfield->width, $customfield->height);
                         } else {
                             $customfield->display = vmText::_($customfield->customfield_value);
                         }
                     }
                 } else {
                     if (!empty($customfield->is_input)) {
                         if (!isset($selectList[$customfield->virtuemart_custom_id])) {
                             $tmpField = clone $customfield;
                             $tmpField->options = null;
                             $customfield->options[$customfield->virtuemart_customfield_id] = $tmpField;
                             $selectList[$customfield->virtuemart_custom_id] = $k;
                             $customfield->customProductDataName = $customProductDataName;
                         } else {
                             $customfields[$selectList[$customfield->virtuemart_custom_id]]->options[$customfield->virtuemart_customfield_id] = $customfield;
                             unset($customfields[$k]);
                             //$customfield->options[$customfield->virtuemart_customfield_id] = $customfield;
                         }
                         $default = reset($customfields[$selectList[$customfield->virtuemart_custom_id]]->options);
                         foreach ($customfields[$selectList[$customfield->virtuemart_custom_id]]->options as &$productCustom) {
                             $price = self::_getCustomPrice($productCustom->customfield_price, $currency, $calculator);
                             if ($type == 'M') {
                                 $productCustom->text = $this->displayCustomMedia($productCustom->customfield_value, 'product', $customfield->width, $customfield->height) . ' ' . $price;
                             } else {
                                 $trValue = vmText::_($productCustom->customfield_value);
                                 if ($productCustom->customfield_value != $trValue and strpos($trValue, '%1') !== false) {
                                     $productCustom->text = vmText::sprintf($productCustom->customfield_value, $price);
                                 } else {
                                     $productCustom->text = $trValue . ' ' . $price;
                                 }
                             }
                         }
                         $customfields[$selectList[$customfield->virtuemart_custom_id]]->display = JHtml::_($selectType, $customfields[$selectList[$customfield->virtuemart_custom_id]]->options, $customfields[$selectList[$customfield->virtuemart_custom_id]]->customProductDataName, $class, 'virtuemart_customfield_id', 'text', $default->customfield_value, $idTag);
                         //*/
                     } else {
                         if ($type == 'M') {
                             $customfield->display = $this->displayCustomMedia($customfield->customfield_value, 'product', $customfield->width, $customfield->height);
                         } else {
                             $customfield->display = vmText::_($customfield->customfield_value);
                         }
                     }
                 }
                 break;
             case 'Z':
                 if (empty($customfield->customfield_value)) {
                     break;
                 }
                 $html = '';
                 $q = 'SELECT * FROM `#__virtuemart_categories_' . VmConfig::$vmlang . '` as l INNER JOIN `#__virtuemart_categories` AS c using (`virtuemart_category_id`) WHERE `published`=1 AND l.`virtuemart_category_id`= "' . (int) $customfield->customfield_value . '" ';
                 $db = JFactory::getDBO();
                 $db->setQuery($q);
                 if ($category = $db->loadObject()) {
                     if (empty($category->virtuemart_category_id)) {
                         break;
                     }
                     $q = 'SELECT `virtuemart_media_id` FROM `#__virtuemart_category_medias`WHERE `virtuemart_category_id`= "' . $category->virtuemart_category_id . '" ';
                     $db->setQuery($q);
                     $thumb = '';
                     if ($media_id = $db->loadResult()) {
                         $thumb = $this->displayCustomMedia($media_id, 'category', $customfield->width, $customfield->height);
                     }
                     $customfield->display = JHtml::link(JRoute::_('index.php?option=com_virtuemart&view=category&virtuemart_category_id=' . $category->virtuemart_category_id), $thumb . ' ' . $category->category_name, array('title' => $category->category_name, 'target' => '_blank'));
                 }
                 break;
             case 'R':
                 if (empty($customfield->customfield_value)) {
                     $customfield->display = 'customfield related product has no value';
                     break;
                 }
                 $pModel = VmModel::getModel('product');
                 $related = $pModel->getProduct((int) $customfield->customfield_value, TRUE, $customfield->wPrice, TRUE, 1);
                 if (!$related) {
                     break;
                 }
                 $thumb = '';
                 if ($customfield->wImage) {
                     if (!empty($related->virtuemart_media_id[0])) {
                         $thumb = $this->displayCustomMedia($related->virtuemart_media_id[0], 'product', $customfield->width, $customfield->height) . ' ';
                     } else {
                         $thumb = $this->displayCustomMedia(0, 'product', $customfield->width, $customfield->height) . ' ';
                     }
                 }
                 $customfield->display = shopFunctionsF::renderVmSubLayout('related', array('customfield' => $customfield, 'related' => $related, 'thumb' => $thumb));
                 break;
         }
     }
 }
示例#27
0
 /**
  * Create the ordered item records
  *
  * @author Oscar van Eijk
  * @author Kohl Patrick
  * @param integer $_id integer Order ID
  * @param object $_cart array The cart data
  * @return boolean True on success
  */
 private function _createOrderLines($_id, $_cart)
 {
     $_orderItems = $this->getTable('order_items');
     //		$_lineCount = 0;
     foreach ($_cart->products as $priceKey => $_prod) {
         if (!is_int($priceKey)) {
             if (!class_exists('calculationHelper')) {
                 require JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'calculationh.php';
             }
             $calculator = calculationHelper::getInstance();
             $variantmods = $calculator->parseModifier($priceKey);
             $row = 0;
             //$product_id = (int)$priceKey;
             $_prod->product_attribute = '';
             $product_attribute = array();
             //MarkerVarMods
             //foreach($variantmods as $variant=>$selected){
             foreach ($variantmods as $selected => $variant) {
                 if ($selected) {
                     if (!class_exists('VirtueMartModelCustomfields')) {
                         require JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'customfields.php';
                     }
                     $productCustom = VirtueMartModelCustomfields::getProductCustomField($selected);
                     //vmdebug('$_prod,$productCustom',$productCustom );
                     if ($productCustom->field_type == "E") {
                         if (!class_exists('vmCustomPlugin')) {
                             require JPATH_VM_PLUGINS . DS . 'vmcustomplugin.php';
                         }
                         //We need something like this
                         $product_attribute[$selected] = $productCustom->virtuemart_custom_id;
                         //but seems we are forced to use this
                         //$product_attribute[$selected] = $selected;
                         if (!empty($_prod->param)) {
                             foreach ($_prod->param as $k => $plg) {
                                 if ($k == $selected) {
                                     //TODO productCartId
                                     $product_attribute[$selected] = $plg;
                                 }
                             }
                         }
                     } else {
                         //ALCON
                         $product_attribute[0] = ' <span class="costumTitle">Misura: </span><span class="costumValue" >' . $productCustom->custom_value . '</span>';
                         //	$product_attribute[$selected] = ' <span class="costumTitle">'.$productCustom->custom_title.'</span><span class="costumValue" >'.$productCustom->custom_value.'</span>';
                         //$product_attribute[$variant] = ' <span class="costumTitle">'.$productCustom->custom_title.'</span><span class="costumValue" >'.$productCustom->custom_value.'</span>';
                     }
                 }
                 $row++;
             }
             //if (isset($_prod->userfield )) $_prod->product_attribute .= '<br/ > <b>'.$_prod->userfield.' : </b>';
             //			$_orderItems->product_attribute = json_encode($product_attribute);
             $_orderItems->product_attribute = $product_attribute[0];
             //print_r($product_attribute);
         } else {
             $_orderItems->product_attribute = null;
         }
         // TODO: add fields for the following data:
         //    * [double] basePrice = 38.48
         //    * [double] basePriceVariant = 38.48
         //    * [double] basePriceWithTax = 42.04
         //    * [double] discountedPriceWithoutTax = 36.48
         //    * [double] priceBeforeTax = 36.48
         //    * [double] salesPrice = 39.85
         //    * [double] salesPriceTemp = 39.85
         //    * [double] taxAmount = 3.37
         //    * [double] salesPriceWithDiscount = 0
         //    * [double] discountAmount = 2.19
         //    * [double] priceWithoutTax = 36.48
         //    * [double] variantModification = 0
         $_orderItems->virtuemart_order_item_id = null;
         $_orderItems->virtuemart_order_id = $_id;
         // 			$_orderItems->virtuemart_userinfo_id = 'TODO'; //$_cart['BT']['virtuemart_userinfo_id']; // TODO; Add it in the cart... but where is this used? Obsolete?
         $_orderItems->virtuemart_vendor_id = $_prod->virtuemart_vendor_id;
         $_orderItems->virtuemart_product_id = $_prod->virtuemart_product_id;
         $_orderItems->order_item_sku = $_prod->product_sku;
         $_orderItems->order_item_name = $_prod->product_name;
         //TODO Patrick
         $_orderItems->product_quantity = $_prod->quantity;
         $_orderItems->product_item_price = $_cart->pricesUnformatted[$priceKey]['basePrice'];
         $_orderItems->product_basePriceWithTax = $_cart->pricesUnformatted[$priceKey]['basePriceWithTax'];
         //$_orderItems->product_tax = $_cart->pricesUnformatted[$priceKey]['subtotal_tax_amount'];
         $_orderItems->product_tax = $_cart->pricesUnformatted[$priceKey]['taxAmount'];
         $_orderItems->product_final_price = $_cart->pricesUnformatted[$priceKey]['salesPrice'];
         $_orderItems->product_subtotal_discount = $_cart->pricesUnformatted[$priceKey]['subtotal_discount'];
         $_orderItems->product_subtotal_with_tax = $_cart->pricesUnformatted[$priceKey]['subtotal_with_tax'];
         //			$_orderItems->order_item_currency = $_prices[$_lineCount]['']; // TODO Currency
         $_orderItems->order_status = 'P';
         if (!$_orderItems->check()) {
             vmError($this->getError());
             return false;
         }
         // Save the record to the database
         if (!$_orderItems->store()) {
             vmError($this->getError());
             return false;
         }
         $_prod->virtuemart_order_item_id = $_orderItems->virtuemart_order_item_id;
         // 			vmdebug('_createOrderLines',$_prod);
         $this->handleStockAfterStatusChangedPerProduct($_orderItems->order_status, 'N', $_orderItems, $_orderItems->product_quantity);
     }
     //jExit();
     return true;
 }
示例#28
0
文件: SotVm.php 项目: sergy444/joomla
		/**
		 * Gets the price for a variant
		 *
		 * @author Max Milbers
		 */
		public function getPrice($product,$customVariant,$quantity){
		
			
			// 		vmdebug('strange',$product);
			if(!is_object($product)){
				$product = $this->getProduct($product,true,false,true);
			}
		
			// Loads the product price details
			if(!class_exists('calculationHelper')) require(JPATH_VM_ADMINISTRATOR.DS.'helpers'.DS.'calculationh.php');
			$calculator = calculationHelper::getInstance();
		
			// Calculate the modificator
			$variantPriceModification = $calculator->calculateModificators($product,$customVariant);
		
			$prices = $calculator->getProductPrices($product,$product->categories,$variantPriceModification,$quantity);
			return $prices;
		
		}
}
$this->i = 0;
$rowColor = 0;
if (!class_exists('calculationHelper')) {
    require JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'calculationh.php';
}
$calculator = calculationHelper::getInstance();
$currency_model = VmModel::getModel('currency');
$currencies = $currency_model->getCurrencies();
$nbPrice = count($this->product->prices);
$this->priceCounter = 0;
$this->product->prices[$nbPrice] = $this->product_empty_price;
if (!class_exists('calculationHelper')) {
    require JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'calculationh.php';
}
$calculator = calculationHelper::getInstance();
?>
			    <table border="0" width="100%" cellpadding="2" cellspacing="3" id="mainPriceTable" class="adminform">
			        <tbody id="productPriceBody">
					<?php 
foreach ($this->product->prices as $sPrices) {
    if (count($sPrices) == 0) {
        continue;
    }
    if (empty($sPrices['virtuemart_product_price_id'])) {
        $sPrices['virtuemart_product_price_id'] = '';
    }
    $sPrices = (array) $sPrices;
    $this->tempProduct = (object) array_merge((array) $this->product, $sPrices);
    $this->calculatedPrices = $calculator->getProductPrices($this->tempProduct);
    if ((string) $sPrices['product_price'] === '0' or (string) $sPrices['product_price'] === '') {
示例#30
0
 /**
  * Function Description
  *
  * @author Max Milbers
  * @access public
  * @param array $cart the cart to get the products for
  * @return array of product objects
  */
 public function getCartPrices($force = false)
 {
     if (empty($this->cartPrices) or !$this->_calculated or $force) {
         if (!class_exists('calculationHelper')) {
             require VMPATH_ADMIN . DS . 'helpers' . DS . 'calculationh.php';
         }
         $calculator = calculationHelper::getInstance();
         $this->pricesCurrency = $calculator->_currencyDisplay->getCurrencyForDisplay();
         $calculator->getCheckoutPrices($this);
         //Fallback for old extensions
         $this->pricesUnformatted = $this->cartPrices;
         //We must do this here, otherwise if we have a product more than one time in the cart
         //it has always the same price
         foreach ($this->products as $k => $product) {
             $this->products[$k]->prices =& $product->allPrices[$product->selectedPrice];
         }
         $this->_calculated = true;
     }
     return $this->cartPrices;
 }