示例#1
0
 public static function updateProduct(&$product, &$class, &$vm1)
 {
     $lang = $class->config->language;
     $a = explode('-', $lang);
     $langkey = strtolower(str_replace('-', '_', $lang));
     $lang = strtolower($a[0]);
     $vm1 = array();
     $vm1['atr'] = '';
     $vm1['product_id'] = $product->virtuemart_product_id;
     if (empty($product->product_sku)) {
         $product->product_sku = $product->virtuemart_product_id;
     }
     $vm1['sku'] = $product->product_sku;
     $key = $langkey . '_product_name';
     $vm1['product_name'] = $product->{$key};
     $product->product_name = $vm1['product_name'];
     $key = $langkey . '_mf_name';
     $vm1['manufacturer_name'] = $product->{$key};
     $vm1['manufacturer'] = $vm1['manufacturer_name'];
     $vm1['mf_name'] = $product->{$key};
     $product->mf_name = $vm1['mf_name'];
     $key = $langkey . '_mf_desc';
     $vm1['mf_desc'] = $product->{$key};
     $product->mf_desc = $vm1['mf_desc'];
     $ida = $product->virtuemart_media_id;
     if (is_array($ida)) {
         $id = reset($ida);
     } else {
         $id = $ida;
     }
     $img = OPCImage::getMediaData($id);
     $site = OPCXmlExport::$config->xml_live_site;
     if (is_array($product->virtuemart_manufacturer_id)) {
         $vm1['manufacturer_id'] = reset($product->virtuemart_manufacturer_id);
     } else {
         $vm1['manufacturer_id'] = 0;
     }
     if (!empty($img['file_url'])) {
         if (stripos($img['file_url'], 'http') === false) {
             $vm1['thumb_url'] = $site . $img['file_url'];
         } else {
             $vm1['thumb_url'] = $img['file_url'];
         }
     } else {
         $vm1['thumb_url'] = '';
     }
     $product->imagePaths = array();
     $product->imagePaths[] = $vm1['thumb_url'];
     if (!empty($ida)) {
         foreach ($ida as $im) {
             $img = OPCImage::getMediaData($id);
             if (!empty($img['file_url'])) {
                 $product->imagePaths[] = OPCXmlExport::getLink('', $vm1['thumb_url']);
             }
         }
     }
     //$vm1['thumb_url'] = $img->file_url;
     $vm1['fullimg'] = $vm1['thumb_url'];
     $key = $langkey . '_product_s_desc';
     $vm1['desc'] =& $product->{$key};
     $product->product_s_desc =& $vm1['desc'];
     $key = $langkey . '_product_desc';
     $vm1['fulldesc'] =& $product->{$key};
     $product->fulldesc =& $vm1['fulldesc'];
     if (!empty($class->config->cname)) {
         $utm = 'utm_source=' . $class->config->cname;
     } else {
         $utm = '';
     }
     if ($class->config->url_type == 1) {
         $product->url = OPCXmlExport::getLink('', $product->link);
     } else {
         if ($class->config->url_type == 2) {
             $product->url = OPCXmlExport::getLink('', $product->link, $utm);
         } else {
             if ($class->config->url_type == 3) {
                 $product->url = OPCXmlExport::getLink('', 'index.php?option=com_virtuemart&lang=' . $lang . '&view=productdetails&virtuemart_product_id=' . (int) $product->virtuemart_product_id, $utm);
             } else {
                 $product->url = OPCXmlExport::getLink('', 'index.php?option=com_onepage&view=redirect&virtuemart_product_id=' . (int) $product->virtuemart_product_id . '&nosef=1&tmpl=component&format=opchtml', $utm);
             }
         }
     }
     $vm1['link'] = $product->url;
     $vm1['node_link'] = OPCXmlExport::getLink('', 'index.php?option=com_virtuemart&lang=' . $lang . '&view=productdetails&virtuemart_product_id=' . (int) $product->virtuemart_product_id, $utm);
     $vm1['cena_s_dph'] = $product->pricesCalc[$class->config->shopper_group]['salesPrice'];
     $product->prices = $product->pricesCalc[$class->config->shopper_group];
     if (!empty($product->prices['discountedPriceWithoutTax'])) {
         $vm1['cena_txt'] = $product->pricesCalc[$class->config->shopper_group]['discountedPriceWithoutTax'];
     } else {
         $vm1['cena_txt'] = $product->pricesCalc[$class->config->shopper_group]['priceBeforeTax'];
     }
     $product->prices = $product->pricesCalc[$class->config->shopper_group];
     $vm1['tax_rate'] = OPCXmlExport::getTaxRate($product, $class->config);
     $vm1['avai_obr'] = $product->product_availability;
     if (empty($product->product_availability)) {
         $vm1['avaitext'] = $class->config->avaitext;
         $vm1['avaidays'] = $class->config->avaidays;
     } else {
         $img = $product->product_availability;
         $pattern = '/[^\\w]+/';
         //'[^a-zA-Z\s]';
         $key2 = preg_replace($pattern, '_', $img);
         if (isset($class->config->{$key . 'txt'})) {
             $vm1['avaitext'] = $class->config->{$key . 'txt'};
         } else {
             $vm1['avaitext'] = $product->product_availability;
         }
         if (isset($class->config->{$key . 'days'})) {
             $vm1['avaidays'] = $class->config->{$key . 'days'};
         } else {
             $vm1['avaidays'] = $product->product_availability;
         }
     }
     $lang = $class->config->language;
     $lang = strtolower(str_replace('-', '_', $lang));
     $vm1['cats'] = array();
     $cats = array();
     if (!empty($product->categories)) {
         foreach ($product->categories as $cat) {
             //
             $clang = strtolower(str_replace('-', '_', $lang));
             $query = array();
             $qeury['langswitch'] = $clang;
             $helper = vmrouterHelperSEFforOPC::getInstance($query);
             $categoryRoute = $helper->getCategoryRoute($cat);
             if (isset($categoryRoute->route)) {
                 $arr = explode('~/~', $categoryRoute->route);
                 if (count($arr) > 0) {
                     $catname = '';
                     foreach ($arr as $c) {
                         $catname = $c;
                         $catname = str_replace(" ", '', $catname);
                         $mycats[$clang][$cat]['cats'][] = trim($c);
                         $helper->catsOfCats[$cat][] = trim($c);
                     }
                 } else {
                     $mycats[$clang][$cat]['cats'][] = trim($categoryRoute->route);
                     $helper->catsOfCats[$query['virtuemart_category_id']][] = trim($categoryRoute->route);
                 }
                 $mycats[$clang][$cat]['route'] = $categoryRoute->route;
             }
             $vm1['cats'][$cat] = $mycats[$clang][$cat]['cats'];
         }
     }
     $count = 0;
     $sk = -1;
     $l = 0;
     foreach ($vm1['cats'] as $key => $cat) {
         //echo 'count: '.count($cat)."<br />\n";
         if (count($cat) > $count) {
             $sk = $key;
             $count = count($cat);
             $l = implode(' ', $cat);
         }
         if (count($cat) == $count) {
             $l2 = implode(' ', $cat);
             if ($l2 > $l) {
                 $count = count($cat);
                 $l = $l2;
                 $sk = $key;
             }
         }
     }
     $vm1['longest_cat_id'] = 0;
     if ($sk >= 0) {
         $vm1['longest_cats'] = $vm1['cats'][$sk];
         $vm1['longest_cat_id'] = $sk;
     }
     if (!isset($vm1['longest_cats'])) {
         $vm1['longest_cats'] = array();
     }
     $vm1['published'] = (bool) $product->published;
     $vm1['attribs'] = array();
     if (empty($vm1['manufacturer'])) {
         if (!empty($product->virtuemart_custom_field_ids)) {
             if (!empty($product->virtuemart_custom_fields)) {
                 $a = explode(',', $product->virtuemart_custom_field_ids);
                 $a2 = explode(',', $product->virtuemart_custom_fields);
                 if (count($a) == count($a2)) {
                     // attribs:
                     $q = 'select cs.custom_title, cf.custom_value, cf.virtuemart_customfield_id, cf.virtuemart_custom_id from #__virtuemart_customs as cs, #__virtuemart_product_customfields as cf where cs.virtuemart_custom_id = cf.virtuemart_custom_id and cf.virtuemart_customfield_id IN (' . $product->virtuemart_custom_fields . ') ';
                     $db = JFactory::getDBO();
                     $db->setQuery($q);
                     $res = $db->loadAssocList();
                     $vm1['attribs'] = $res;
                 }
             }
         }
     }
 }