/** * 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"))); } }