Ejemplo n.º 1
0
 public function writeXMLExportFile($xmlexport_id = 0)
 {
     $config = new Redconfiguration();
     $shipping = new shipping();
     $uri = JURI::getInstance();
     $url = $uri->root();
     $xmlarray = array();
     $xmlexportdata = $this->getXMLExportInfo($xmlexport_id);
     if (count($xmlexportdata) <= 0) {
         return false;
     }
     $destpath = JPATH_SITE . "/components/com_redshop/assets/xmlfile/export/";
     $section = $xmlexportdata->section_type;
     $columns = $this->getSectionColumnList($section, "orderdetail");
     for ($i = 0; $i < count($columns); $i++) {
         $tag = $this->getXMLFileTag($columns[$i]->Field, $xmlexportdata->xmlexport_filetag);
         if ($tag[0] != "") {
             $xmlarray[$columns[$i]->Field] = $tag[0];
         }
     }
     $datalist = array();
     $billinglist = array();
     $shippinglist = array();
     $orderItemlist = array();
     $stocklist = array();
     $prdextrafieldlist = array();
     $xmlbilling = array();
     $xmlshipping = array();
     $xmlOrderitem = array();
     $xmlstock = array();
     $xmlprdextrafield = array();
     $prdfullimage = "";
     $prdthmbimage = "";
     switch ($section) {
         case "product":
             if (array_key_exists("product_full_image", $xmlarray)) {
                 $prdfullimage = $xmlarray['product_full_image'];
             }
             if (array_key_exists("product_thumb_image", $xmlarray)) {
                 $prdthmbimage = $xmlarray['product_thumb_image'];
             }
             $datalist = $this->getProductList($xmlarray, $xmlexportdata);
             $columns = $this->getSectionColumnList($section, "stockdetail");
             for ($i = 0; $i < count($columns); $i++) {
                 $tag = $this->getXMLFileTag($columns[$i]->Field, $xmlexportdata->xmlexport_stocktag);
                 if ($tag[0] != "") {
                     $xmlstock[$columns[$i]->Field] = $tag[0];
                 }
             }
             $columns = $this->getSectionColumnList($section, "prdextrafield");
             for ($i = 0; $i < count($columns); $i++) {
                 $tag = $this->getXMLFileTag($columns[$i]->Field, $xmlexportdata->xmlexport_prdextrafieldtag);
                 if ($tag[0] != "") {
                     $xmlprdextrafield[$columns[$i]->Field] = $tag[0];
                 }
             }
             break;
         case "order":
             $datalist = $this->getOrderList($xmlarray);
             $columns = $this->getSectionColumnList($section, "billingdetail");
             for ($i = 0; $i < count($columns); $i++) {
                 $tag = $this->getXMLFileTag($columns[$i]->Field, $xmlexportdata->xmlexport_billingtag);
                 if ($tag[0] != "") {
                     $xmlbilling[$columns[$i]->Field] = $tag[0];
                 }
             }
             $columns = $this->getSectionColumnList($section, "shippingdetail");
             for ($i = 0; $i < count($columns); $i++) {
                 $tag = $this->getXMLFileTag($columns[$i]->Field, $xmlexportdata->xmlexport_shippingtag);
                 if ($tag[0] != "") {
                     $xmlshipping[$columns[$i]->Field] = $tag[0];
                 }
             }
             $columns = $this->getSectionColumnList($section, "orderitem");
             for ($i = 0; $i < count($columns); $i++) {
                 $tag = $this->getXMLFileTag($columns[$i]->Field, $xmlexportdata->xmlexport_orderitemtag);
                 if ($tag[0] != "") {
                     $xmlOrderitem[$columns[$i]->Field] = $tag[0];
                 }
             }
             break;
         default:
             return false;
     }
     if ($xmlexportdata->filename != "") {
         if (is_file($destpath . $xmlexportdata->filename)) {
             //				unlink($destpath.$xmlexportdata->filename);
         }
     }
     $filetmpname = str_replace(" ", "_", strtolower($xmlexportdata->display_filename));
     $filename = JPath::clean(time() . '_' . $filetmpname . '.xml');
     //Make the filename unique
     $xml_document = "<?xml version='1.0' encoding='utf-8'?>";
     if (trim($xmlexportdata->element_name) == "") {
         $xmlexportdata->element_name = $xmlexportdata->parent_name . "_element";
     }
     $xml_document .= "<" . $xmlexportdata->parent_name . ">";
     for ($i = 0; $i < count($datalist); $i++) {
         $product_id = 0;
         if ($section == "product") {
             $product_id = $datalist[$i]['product_id'];
         }
         $xml_billingdocument = "";
         $xml_shippingdocument = "";
         $xml_itemdocument = "";
         $xml_stockdocument = "";
         $xml_prdextradocument = "";
         if (count($xmlbilling) > 0) {
             $billinglist = $this->getOrderUserInfoList($xmlbilling, $datalist[$i]->order_id);
             if (count($billinglist) > 0) {
                 $xml_billingdocument .= "<{$xmlexportdata->billing_element_name}>";
                 while (list($prop, $val) = each($billinglist)) {
                     $val = html_entity_decode($val);
                     $xml_billingdocument .= "<{$prop}><![CDATA[{$val}]]></{$prop}>";
                 }
                 $xml_billingdocument .= "</{$xmlexportdata->billing_element_name}>";
             }
         }
         if (count($xmlshipping) > 0) {
             $shippinglist = $this->getOrderUserInfoList($xmlshipping, $datalist[$i]->order_id, "ST");
             if (count($shippinglist) > 0) {
                 $xml_shippingdocument .= "<{$xmlexportdata->shipping_element_name}>";
                 while (list($prop, $val) = each($shippinglist)) {
                     $val = html_entity_decode($val);
                     $xml_shippingdocument .= "<{$prop}><![CDATA[{$val}]]></{$prop}>";
                 }
                 $xml_shippingdocument .= "</{$xmlexportdata->shipping_element_name}>";
             }
         }
         if (count($xmlOrderitem) > 0) {
             $orderItemlist = $this->getOrderItemList($xmlOrderitem, $datalist[$i]->order_id);
             if (count($orderItemlist) > 0) {
                 $xml_itemdocument .= "<" . $xmlexportdata->orderitem_element_name . "s>";
                 for ($j = 0; $j < count($orderItemlist); $j++) {
                     $xml_itemdocument .= "<{$xmlexportdata->orderitem_element_name}>";
                     while (list($prop, $val) = each($orderItemlist[$j])) {
                         $val = html_entity_decode($val);
                         $xml_itemdocument .= "<{$prop}><![CDATA[{$val}]]></{$prop}>";
                     }
                     $xml_itemdocument .= "</{$xmlexportdata->orderitem_element_name}>";
                 }
                 $xml_itemdocument .= "</" . $xmlexportdata->orderitem_element_name . "s>";
             }
         }
         if (count($xmlstock) > 0) {
             $stocklist = $this->getStockroomList($xmlstock, $product_id);
             if (count($stocklist) > 0) {
                 $xml_stockdocument .= "<" . $xmlexportdata->stock_element_name . "s>";
                 for ($j = 0; $j < count($stocklist); $j++) {
                     $xml_stockdocument .= "<{$xmlexportdata->stock_element_name}>";
                     while (list($prop, $val) = each($stocklist[$j])) {
                         $val = html_entity_decode($val);
                         $xml_stockdocument .= "<{$prop}><![CDATA[{$val}]]></{$prop}>";
                     }
                     $xml_stockdocument .= "</{$xmlexportdata->stock_element_name}>";
                 }
                 $xml_stockdocument .= "</" . $xmlexportdata->stock_element_name . "s>";
             }
         }
         if (count($xmlprdextrafield) > 0) {
             $prdextrafieldlist = $this->getExtraFieldList($xmlprdextrafield, $product_id, 1);
             if (count($prdextrafieldlist) > 0) {
                 $xml_prdextradocument .= "<" . $xmlexportdata->prdextrafield_element_name . "s>";
                 for ($j = 0; $j < count($prdextrafieldlist); $j++) {
                     $xml_prdextradocument .= "<{$xmlexportdata->prdextrafield_element_name}>";
                     while (list($prop, $val) = each($prdextrafieldlist[$j])) {
                         $val = html_entity_decode($val);
                         $xml_prdextradocument .= "<{$prop}><![CDATA[{$val}]]></{$prop}>";
                     }
                     $xml_prdextradocument .= "</{$xmlexportdata->prdextrafield_element_name}>";
                 }
                 $xml_prdextradocument .= "</" . $xmlexportdata->prdextrafield_element_name . "s>";
             }
         }
         if ($section == "order" && $xml_itemdocument == "") {
         } else {
             $xml_document .= "<{$xmlexportdata->element_name}>";
             while (list($prop, $val) = each($datalist[$i])) {
                 $val = html_entity_decode($val);
                 if ($prop == $prdfullimage && $val != "") {
                     $val = REDSHOP_FRONT_IMAGES_ABSPATH . "product/" . $val;
                 }
                 if ($prop == $prdthmbimage && $val != "") {
                     $val = REDSHOP_FRONT_IMAGES_ABSPATH . "product/thumb/" . $val;
                 }
                 if (isset($xmlarray['cdate']) && $prop == $xmlarray['cdate'] || isset($xmlarray['mdate']) && $prop == $xmlarray['mdate']) {
                     $val = $config->convertDateFormat($val);
                 }
                 if ($prop != "order_id" && $prop != "product_id") {
                     // Start Code for display product url,delivertime,pickup,charges,freight
                     if ($prop == "manufacturer") {
                         $val = "noname";
                     }
                     if ($prop == "link") {
                         $val = JURI::root() . 'index.php?option=com_redshop&view=product&pid=' . $product_id;
                     } elseif ($prop == "pickup") {
                         $val = "";
                     } elseif ($prop == "charge") {
                         $d['product_id'] = $product_id;
                         $srate = $shipping->getDefaultShipping_xmlexport($d);
                         $val1 = $srate['shipping_rate'];
                         $val = round($val1);
                     } elseif ($prop == "freight") {
                         $d['product_id'] = $product_id;
                         $srate = $shipping->getDefaultShipping_xmlexport($d);
                         $val1 = $srate['shipping_rate'];
                         $val = round($val1);
                     } elseif ($prop == "delivertime") {
                         $query = "SELECT * FROM " . $this->_table_prefix . "stockroom AS s " . "LEFT JOIN " . $this->_table_prefix . "product_stockroom_xref AS sx ON s.stockroom_id=sx.stockroom_id " . "WHERE product_id=" . (int) $product_id . " " . "ORDER BY s.stockroom_id ASC ";
                         $this->_db->setQuery($query);
                         $list = $this->_db->loadObject();
                         for ($k = 0; $k < count($list); $k++) {
                             if ($list->max_del_time == 1 && $list->max_del_time < 2) {
                                 $val = "1";
                             } elseif ($list->max_del_time == 2 && $list->max_del_time <= 3) {
                                 $val = "2";
                             } elseif ($list->max_del_time == 4) {
                                 $val = "4";
                             } elseif ($list->max_del_time == 5) {
                                 $val = "5";
                             } elseif ($list->max_del_time >= 6 && $list->max_del_time <= 10) {
                                 $val = "6,7,8,9,10";
                             } elseif ($list->max_del_time == "") {
                                 $val = "";
                             }
                         }
                     }
                     if ($prop == "link") {
                         $xml_document .= "<{$prop}><![CDATA[{$val}]]></{$prop}>";
                     } else {
                         $xml_document .= "<{$prop}>{$val}</{$prop}>";
                     }
                 }
             }
             $xml_document .= $xml_billingdocument;
             $xml_document .= $xml_shippingdocument;
             $xml_document .= $xml_itemdocument;
             $xml_document .= $xml_stockdocument;
             $xml_document .= $xml_prdextradocument;
             $xml_document .= "</" . $xmlexportdata->element_name . ">";
         }
     }
     $xml_document .= "</" . $xmlexportdata->parent_name . ">";
     /* Data in Variables ready to be written to an XML file */
     $fp = fopen($destpath . $filename, 'w');
     $write = fwrite($fp, $xml_document);
     $this->insertXMLExportlog($xmlexport_id, $filename);
     // Update new generated exported file in database record
     $this->updateXMLExportFilename($xmlexport_id, $filename);
     return $filename;
 }