Exemplo n.º 1
0
 public function actionCronXML()
 {
     echo "EXPORT STARTED\n";
     $xml = new \DOMDocument();
     $products = $xml->createElement('products');
     $xml->appendChild($products);
     $ids = $this->productManager->getAllIds();
     foreach ($ids as $id) {
         $product = $this->productFactory->createProduct();
         $product->loadById($id);
         $el = $xml->createElement('product');
         $id_el = $xml->createElement('id', $product->getId());
         $el->appendChild($id_el);
         $title_el = $xml->createElement('title');
         $title_el->appendChild($xml->createCDATASection($product->getTitle()));
         $el->appendChild($title_el);
         $sku_el = $xml->createElement('sku', $product->getSku());
         $el->appendChild($sku_el);
         $price_el = $xml->createElement('price', $product->getPrice());
         $el->appendChild($price_el);
         $category_el = $xml->createElement('category');
         $category_el->appendChild($xml->createCDATASection($product->getCategory()->getTitle()));
         $el->appendChild($category_el);
         $brand = $product->getBrand()->getTitle();
         if (false === empty($brand)) {
             $brand_el = $xml->createElement('brand');
             $brand_el->appendChild($xml->createCDATASection($brand));
             $el->appendChild($brand_el);
         }
         $warehouses_el = $xml->createElement('warehouses');
         $el->appendChild($warehouses_el);
         $checkString = $product->getId() . $product->getTitle() . $product->getSku() . $product->getPrice() . $product->getCategory()->getTitle() . $brand;
         foreach ($product->getWarehouses()->getAll() as $warehouse) {
             $warehouse_el = $xml->createElement('warehouse');
             $warehouses_el->appendChild($warehouse_el);
             $wid_el = $xml->createElement('id', $warehouse['id']);
             $warehouse_el->appendChild($wid_el);
             $total_el = $xml->createElement('total', $warehouse['total']);
             $warehouse_el->appendChild($total_el);
             $checkString .= $warehouse['id'] . $warehouse['total'];
         }
         $checksum = $xml->createElement('checksum', substr(md5($checkString), 0, 5));
         $el->appendChild($checksum);
         $products->appendChild($el);
     }
     echo "XML HAS BEEN CREATED\n";
     $file = TEMP_DIR . "/products.xml";
     $xml->save($file);
     echo "XML HAS BEEN SAVED\n";
     $this->ftpConnection->uploadFile($file);
     echo "XML HAS BEEN UPLOADED\n";
     unlink($file);
     echo "XML HAS BEEN DELETED\n";
     $this->terminate();
 }
Exemplo n.º 2
0
 public function renderDefault()
 {
     $this->template->products = $this->productManager->getLastUpdatedProducts();
 }