Ejemplo n.º 1
0
 /**
  * generate BillSafe informations from basket
  * @return array criterion for billSafe
  */
 private function getBasketDetails()
 {
     $user = JFactory::getUser();
     $cart = VirtueMartCart::getCart(false);
     $items = $cart->products;
     $prices = $cart->cartPrices;
     $params = array();
     if ($items) {
         $i = 0;
         //	ITEMS
         foreach ($items as $key => $item) {
             $i++;
             $prefix = 'CRITERION.POS_' . sprintf('%02d', $i);
             $params[$prefix . '.POSITION'] = $i;
             $params[$prefix . '.QUANTITY'] = (int) $item->quantity;
             if (empty($item->product_unit)) {
                 $item->product_unit = 'Stk.';
             }
             $params[$prefix . '.UNIT'] = $item->product_unit;
             #price in cents
             $params[$prefix . '.AMOUNT_UNIT_GROSS'] = $prices[$key]['basePriceWithTax'] * 100;
             $params[$prefix . '.AMOUNT_GROSS'] = $prices[$key]['subtotal_with_tax'] * 100;
             $item->product_name = preg_replace('/%/', 'Proz.', $item->product_name);
             $item->product_name = preg_replace('/("|\'|!|$|=)/', ' ', $item->product_name);
             $params[$prefix . '.TEXT'] = strlen($item->product_name) > 100 ? substr($item->product_name, 0, 90) . '...' : $item->product_name;
             $params[$prefix . '.ARTICLE_NUMBER'] = $item->product_sku;
             $params[$prefix . '.PERCENT_VAT'] = sprintf('%1.2f', $prices[$key]['VatTax'][$item->product_tax_id]['1']);
             $params[$prefix . '.ARTICLE_TYPE'] = 'goods';
         }
         //	SHIPPING
         require VMPATH_ADMIN . DS . 'models' . DS . 'shipmentmethod.php';
         $vmms = new VirtueMartModelShipmentmethod();
         $shipmentInfo = $vmms->getShipments();
         foreach ($shipmentInfo as $skey => $svalue) {
             if ($svalue->virtuemart_shipmentmethod_id == $cart->virtuemart_shipmentmethod_id) {
                 $shipmentData = array();
                 foreach (explode("|", $svalue->shipment_params) as $line) {
                     list($key, $value) = explode('=', $line, 2);
                     $shipmentData[$key] = str_replace('"', '', $value);
                 }
                 $shipmentTaxId = $shipmentData['tax_id'];
                 $shipmentTax = sprintf('%1.2f', $cart->cartData['VatTax'][$shipmentTaxId]['calc_value']);
             }
         }
         $i++;
         $prefix = 'CRITERION.POS_' . sprintf('%02d', $i);
         $params[$prefix . '.POSITION'] = $i;
         $params[$prefix . '.QUANTITY'] = '1';
         $params[$prefix . '.UNIT'] = 'Stk.';
         $params[$prefix . '.AMOUNT_UNIT_GROSS'] = $prices['salesPriceShipment'] * 100;
         $params[$prefix . '.AMOUNT_GROSS'] = $prices['salesPriceShipment'] * 100;
         $params[$prefix . '.TEXT'] = 'Shipping';
         $params[$prefix . '.ARTICLE_NUMBER'] = 'Shipping';
         $params[$prefix . '.PERCENT_VAT'] = $shipmentTax;
         $params[$prefix . '.ARTICLE_TYPE'] = 'shipment';
         //	COUPON
         if (isset($prices['couponValue']) && $prices['couponValue'] != '') {
             $i++;
             $prefix = 'CRITERION.POS_' . sprintf('%02d', $i);
             $params[$prefix . '.POSITION'] = $i;
             $params[$prefix . '.QUANTITY'] = '1';
             $params[$prefix . '.UNIT'] = 'Stk.';
             $params[$prefix . '.AMOUNT_UNIT_GROSS'] = $prices['couponValue'] * 100;
             $params[$prefix . '.AMOUNT_GROSS'] = $prices['couponValue'] * 100;
             $params[$prefix . '.TEXT'] = 'Coupon';
             $params[$prefix . '.ARTICLE_NUMBER'] = 'Coupon';
             $params[$prefix . '.PERCENT_VAT'] = $prices['couponTax'];
             $params[$prefix . '.ARTICLE_TYPE'] = 'voucher';
         }
     }
     return $params;
 }
Ejemplo n.º 2
0
}
$cat = new VirtuemartModelCategory();
$product = new VirtueMartModelProduct();
$image = new VirtueMartModelMedia();
$currency = new VirtueMartModelCurrency();
$config =& JFactory::getConfig();
if ($hasShipping && $add_shipping == "on") {
    $shipment = new VirtueMartModelShipmentmethod();
    $defaultFrontEndLang = explode("-", $config->getValue('config.language'));
    $db = $shipment->getDbo();
    $db->setQuery("SELECT virtuemart_country_id FROM #__virtuemart_countries WHERE country_2_code = '{$defaultFrontEndLang[1]}'");
    $result = $db->loadAssoc();
    $defaultFrontEndCountryCode = $result['virtuemart_country_id'];
    $db->setQuery("SELECT virtuemart_shoppergroup_id FROM #__virtuemart_shoppergroups WHERE `default` = 1");
    $defaultShopperGroup = $db->loadObject();
    $shippings = $shipment->getShipments();
    $availableShippingMethods = array();
    if (!empty($shippings) && $shippings !== null) {
        $pattern = '/countries=(\\[.*("' . $defaultFrontEndCountryCode . '").*\\])?("")?\\|zip_start=""\\|zip_stop=""\\|/';
        foreach ($shippings as $shipping) {
            if ($shipping->published == 1 && preg_match($pattern, $shipping->shipment_params) && (in_array($defaultShopperGroup->virtuemart_shoppergroup_id, $shipping->virtuemart_shoppergroup_ids) || empty($shipping->virtuemart_shoppergroup_ids))) {
                $shipping->nbproducts_start = preg_replace('/(^.*nbproducts_start=")(.*)(".*$)/U', '\\2', $shipping->shipment_params);
                $shipping->nbproducts_stop = preg_replace('/(^.*nbproducts_stop=")(.*)(".*$)/U', '\\2', $shipping->shipment_params);
                $shipping->orderamount_start = preg_replace('/(^.*orderamount_start=")(.*)(".*$)/U', '\\2', $shipping->shipment_params);
                $shipping->orderamount_stop = preg_replace('/(^.*orderamount_stop=")(.*)(".*$)/U', '\\2', $shipping->shipment_params);
                $shipping->package_fee = preg_replace('/(^.*package_fee=")(.*)(".*$)/U', '\\2', $shipping->shipment_params);
                $shipping->free_shipment = preg_replace('/(^.*free_shipment=")(.*)(".*$)/U', '\\2', $shipping->shipment_params);
                $shipping->weight_unit = preg_replace('/(^.*weight_unit\\=")(.*)(".*$)/U', '\\2', $shipping->shipment_params);
                $shipping->weight_start = preg_replace('/(^.*weight_start=")(.*)(".*$)/U', '\\2', $shipping->shipment_params);
                $shipping->weight_stop = preg_replace('/(^.*weight_stop=")(.*)(".*$)/U', '\\2', $shipping->shipment_params);
                $shipping->weight_stop = preg_replace('/(^.*weight_stop=")(.*)(".*$)/U', '\\2', $shipping->shipment_params);