/** * export the content in a excel file * @param array $items */ public function bulk_xml($items = array()) { // Get the records from the customer table $data = self::get_products($items); $xml = new ExSimpleXMLElement('<shineisp></shineisp>'); $products = $xml->addChild('products'); foreach ($data as $item) { $product = $products->addChild('product'); $product->addAttribute('id', $item['product_id']); $product->addChild('sku', $item['sku']); $product->addChild('inserted_at', $item['inserted_at']); $product->addChild('updated_at', $item['updated_at']); $product->addChild('price', $item['price_1']); $product->addChild('setupfee', $item['setupfee']); if (!empty($item['ProductsMedia'])) { $media = $product->addChild('media'); foreach ($item['ProductsMedia'] as $productmedia) { $file = $media->addChild('file'); $file->addAttribute('id', $productmedia['media_id']); $file->addChildCData('name', $productmedia['filename']); $file->addChildCData('description', $productmedia['description']); $file->addChildCData('path', $productmedia['path']); } } if (!empty($item['categories'])) { $categories = $product->addChild('categories'); $theCats = ProductsCategories::getCategoriesByIds($item['categories']); foreach ($theCats as $categ) { $category = $categories->addChild('category'); $category->addAttribute('id', $categ['id']); $category->addChildCData('name', $categ['name']); $category->addChildCData('description', $categ['description']); $category->addChild('uri', $categ['uri']); } } if (!empty($item['ProductsData'][0])) { $product->addChildCData('name', $item['ProductsData'][0]['name']); $product->addChildCData('shortdescription', $item['ProductsData'][0]['shortdescription']); $product->addChildCData('description', $item['ProductsData'][0]['description']); $product->addChildCData('metakeywords', $item['ProductsData'][0]['metakeywords']); $product->addChildCData('metadescription', $item['ProductsData'][0]['metadescription']); } if (!empty($item['ProductsAttributesGroups'])) { $product->addAttribute('groupcode', $item['ProductsAttributesGroups']['code']); $product->addAttribute('groupname', $item['ProductsAttributesGroups']['name']); } if (!empty($item['ProductsAttributesIndexes'])) { $attributes = $product->addChild('attributes'); foreach ($item['ProductsAttributesIndexes'] as $attr) { $attribute = $attributes->addChild('attribute'); $theAttr = ProductsAttributes::getAllInfo($attr['attribute_id'], "attribute_id, code, type, is_visible_on_front, position, pad.label, pad.description, pad.prefix, pad.suffix"); $attribute->addAttribute('id', $attr['attribute_id']); $attribute->addChild('code', $theAttr['code']); $attribute->addChildCData('name', $theAttr['ProductsAttributesData'][0]['label']); $attribute->addChildCData('description', $theAttr['ProductsAttributesData'][0]['description']); $attribute->addChildCData('prefix', $theAttr['ProductsAttributesData'][0]['prefix']); $attribute->addChildCData('suffix', $theAttr['ProductsAttributesData'][0]['suffix']); $attribute->addChildCData('value', $attr['value']); $attribute->addChild('type', $theAttr['type']); $attribute->addChild('is_visible_on_front', $theAttr['is_visible_on_front']); $attribute->addChild('position', $theAttr['position']); } } if (!empty($item['ProductsTranches'])) { $prices = $product->addChild('prices'); foreach ($item['ProductsTranches'] as $tranches) { $price = $prices->addChild('price'); $price->addChild('quantity', $tranches['quantity']); $price->addChild('price', $tranches['price']); $price->addChild('measurement', $tranches['measurement']); if (!empty($tranches['BillingCycle'])) { $price->addAttribute('id', $tranches['BillingCycle']['billing_cycle_id']); $price->addAttribute('name', $tranches['BillingCycle']['name']); $price->addAttribute('months', $tranches['BillingCycle']['months']); } } } } $xml->saveXML(PUBLIC_PATH . "/tmp/products.xml"); if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') { die(json_encode(array('url' => "/tmp/products.xml"))); } }
/** * export the content in a excel file * @param array $items */ public function bulk_xml($items = array()) { // Get the records from the customer table $data = self::get_customers($items); $xml = new ExSimpleXMLElement('<shineisp></shineisp>'); $customers = $xml->addChild('customers'); foreach ($data as $item) { $customer = $customers->addChild('customer'); $customer->addAttribute('id', $item['customer_id']); $customer->addChildCData('company', $item['company']); $customer->addChild('firstname', $item['firstname']); $customer->addChild('lastname', $item['lastname']); $customer->addChild('gender', $item['gender']); $customer->addChild('email', $item['email']); $customer->addChild('password', $item['password']); $customer->addChild('birthdate', $item['birthdate']); $customer->addChild('birthplace', $item['birthplace']); $customer->addChild('birthdistrict', $item['birthdistrict']); $customer->addChild('birthcountry', $item['birthcountry']); $customer->addChild('birthnationality', $item['birthnationality']); $customer->addChild('taxpayernumber', $item['taxpayernumber']); $customer->addChild('vat', $item['vat']); $customer->addChild('birthnationality', $item['birthnationality']); $ctype = $customer->addChild('companytype', $item['CompanyTypes']['name']); $ctype->addAttribute('type_id', $item['type_id']); $legalform = $customer->addChild('companytype', $item['Legalforms']['name']); $legalform->addAttribute('legalform_id', $item['legalform_id']); $status = $customer->addChild('companytype', $item['Statuses']['status']); $status->addAttribute('status_id', $item['status_id']); $cgroup = $customer->addChild('companytype', $item['CustomersGroups']['name']); $cgroup->addAttribute('group_id', $item['group_id']); $customer->addChildCData('note', $item['note']); $language = $customer->addChild('language', $item['Languages']['language']); $language->addAttribute('language_id', $item['language_id']); $customer->addChild('issubscriber', $item['issubscriber']); $customer->addChild('created_at', $item['created_at']); $customer->addChild('updated_at', $item['updated_at']); $customer->addChild('taxfree', $item['taxfree']); $addresses = $customer->addChild('addresses'); foreach ($item['Addresses'] as $addr) { $address = $addresses->addChild('address'); $address->addAttribute('address_id', $addr['address_id']); $address->addChild('address', $addr['address']); $address->addChild('city', $addr['city']); $address->addChild('postcode', $addr['code']); $address->addChild('countrycode', $addr['Countries']['code']); $country = $address->addChild('country', $addr['Countries']['name']); $country->addAttribute('country_id', $addr['country_id']); $address->addChild('area', $addr['area']); $address->addChild('latitude', $addr['latitude']); $address->addChild('longitude', $addr['longitude']); } $contacts = $customer->addChild('contacts'); foreach ($item['Contacts'] as $cnt) { $contact = $contacts->addChild('contact'); $contact->addAttribute('contact_id', $cnt['contact_id']); $mycnt = $contact->addChild('contact', $cnt['contact']); $mycnt->addAttribute('type_id', $cnt['type_id']); $mycnt->addAttribute('label', $cnt['ContactsTypes']['name']); } $orders = $customer->addChild('orders'); foreach ($item['Orders'] as $odr) { $order = $orders->addChild('order'); $order->addAttribute('order_id', $odr['order_id']); $order->addChild('order_date', $odr['order_date']); $order->addChild('total', $odr['total']); $order->addChild('cost', $odr['cost']); $order->addChild('vat', $odr['vat']); $order->addChild('grandtotal', $odr['grandtotal']); $details = $order->addChild('details'); foreach ($odr['OrdersItems'] as $dtl) { $detail = $details->addChild('detail'); $detail->addAttribute('detail_id', $dtl['detail_id']); $detail->addAttribute('status_id', $dtl['status_id']); $arrProduct = Products::getAllInfo($dtl['product_id']); if (!empty($arrProduct)) { $product = $detail->addChild('product'); $product->addAttribute('product_id', $dtl['product_id']); $product->addAttribute('sku', $arrProduct['sku']); if (!empty($arrProduct['ProductsData'])) { $product->addChildCData('name', $arrProduct['ProductsData'][0]['name']); } } $detail->addChild('date_start', $dtl['date_start']); $detail->addChild('date_end', $dtl['date_end']); $detail->addChild('quantity', $dtl['quantity']); $detail->addChildCData('description', $dtl['description']); $detail->addChild('cost', $dtl['cost']); $detail->addChild('price', $dtl['price']); $detail->addChild('setupfee', $dtl['setupfee']); $detail->addChild('status_id', $dtl['status_id']); } } } $xml->saveXML(PUBLIC_PATH . "/tmp/customers.xml"); if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') { die(json_encode(array('url' => "/tmp/customers.xml"))); } }