예제 #1
0
 /**
  * Creates or updates a new Product Feed
  *
  * @throws RuntimeException
  * @return void
  */
 public function saveFeedAction()
 {
     $params = $this->Request()->getParams();
     $feedId = $params["id"];
     if (!empty($feedId)) {
         //edit Product Feed
         $productFeed = Shopware()->Models()->ProductFeed()->find($feedId);
         //clear all previous associations
         $productFeed->getCategories()->clear();
         $productFeed->getSuppliers()->clear();
         $productFeed->getArticles()->clear();
     } else {
         //new Product Feed
         $productFeed = new ProductFeed();
         //to set this value initial
         $productFeed->setLastExport("now");
     }
     if (empty($params['shopId'])) {
         $params['shopId'] = null;
     }
     if (empty($params['categoryId'])) {
         $params['categoryId'] = null;
     }
     if (empty($params['customerGroupId'])) {
         $params['customerGroupId'] = null;
     }
     if (empty($params['languageId'])) {
         $params['languageId'] = null;
     }
     //save data of the category tree
     $params['categories'] = $this->prepareAssociationDataForSaving('categories', 'Shopware\\Models\\Category\\Category', $params);
     //save data of the supplier filter
     $params['suppliers'] = $this->prepareAssociationDataForSaving('suppliers', 'Shopware\\Models\\Article\\Supplier', $params);
     //save data of the article filter
     $params['articles'] = $this->prepareAssociationDataForSaving('articles', 'Shopware\\Models\\Article\\Article', $params);
     $params['attribute'] = $params['attribute'][0];
     $productFeed = $this->setDirty($productFeed, $params);
     $productFeed->fromArray($params);
     //just for future use
     $productFeed->setExpiry(new DateTime());
     $productFeed->setLastChange(new DateTime());
     // Clear feed cache
     $cacheDir = $this->container->getParameter('kernel.cache_dir');
     $cacheDir .= '/productexport/';
     if (!is_dir($cacheDir)) {
         if (false === @mkdir($cacheDir, 0777, true)) {
             throw new \RuntimeException(sprintf("Unable to create the %s directory (%s)\n", "Productexport", $cacheDir));
         }
     } elseif (!is_writable($cacheDir)) {
         throw new \RuntimeException(sprintf("Unable to write in the %s directory (%s)\n", "Productexport", $cacheDir));
     }
     $fileName = $productFeed->getHash() . '_' . $productFeed->getFileName();
     $filePath = $cacheDir . $fileName;
     if (file_exists($filePath) && $productFeed->getInterval() != -1) {
         unlink($filePath);
     }
     $productFeed->setCacheRefreshed('2000-01-01');
     try {
         Shopware()->Models()->persist($productFeed);
         Shopware()->Models()->flush();
         $data = $this->getFeed($productFeed->getId());
         $this->View()->assign(array('success' => true, 'data' => $data));
     } catch (Exception $e) {
         $this->View()->assign(array('success' => false, 'message' => $e->getMessage()));
     }
 }
예제 #2
0
 /**
  * Creates or updates a new Product Feed
  *
  * @return void
  */
 public function saveFeedAction()
 {
     $params = $this->Request()->getParams();
     $feedId = $params["id"];
     if (!empty($feedId)) {
         //edit Product Feed
         $productFeed = Shopware()->Models()->ProductFeed()->find($feedId);
         //clear all previous associations
         $productFeed->getCategories()->clear();
         $productFeed->getSuppliers()->clear();
         $productFeed->getArticles()->clear();
     } else {
         //new Product Feed
         $productFeed = new ProductFeed();
         //to set this value initial
         $productFeed->setLastExport("now");
     }
     if (empty($params['shopId'])) {
         $params['shopId'] = null;
     }
     if (empty($params['categoryId'])) {
         $params['categoryId'] = null;
     }
     if (empty($params['customerGroupId'])) {
         $params['customerGroupId'] = null;
     }
     if (empty($params['languageId'])) {
         $params['languageId'] = null;
     }
     //save data of the category tree
     $params['categories'] = $this->prepareAssociationDataForSaving('categories', 'Shopware\\Models\\Category\\Category', $params);
     //save data of the supplier filter
     $params['suppliers'] = $this->prepareAssociationDataForSaving('suppliers', 'Shopware\\Models\\Article\\Supplier', $params);
     //save data of the article filter
     $params['articles'] = $this->prepareAssociationDataForSaving('articles', 'Shopware\\Models\\Article\\Article', $params);
     $params['attribute'] = $params['attribute'][0];
     $productFeed->fromArray($params);
     //just for future use
     $productFeed->setExpiry(new DateTime());
     $productFeed->setLastChange(new DateTime());
     // Clear feed cache
     $fileName = $productFeed->getHash() . '_' . $productFeed->getFileName();
     $filePath = Shopware()->DocPath() . 'cache/productexport/' . $fileName;
     if (file_exists($filePath) && $productFeed->getInterval() != -1) {
         unlink($filePath);
     }
     $productFeed->setCacheRefreshed('2000-01-01');
     try {
         Shopware()->Models()->persist($productFeed);
         Shopware()->Models()->flush();
         $data = $this->getFeed($productFeed->getId());
         $this->View()->assign(array('success' => true, 'data' => $data));
     } catch (Exception $e) {
         $this->View()->assign(array('success' => false, 'message' => $e->getMessage()));
     }
 }
예제 #3
0
    /**
     * Creates or updates a new Product Feed
     *
     * @return void
     */
    public function saveFeedAction()
    {
        $params = $this->Request()->getParams();

        $feedId = $params["feedId"];
        if(!empty($feedId)){
            //edit Product Feed
            $productFeed = Shopware()->Models()->ProductFeed()->find($feedId);
            //clear all previous associations
            $productFeed->getCategories()->clear();
            $productFeed->getSuppliers()->clear();
            $productFeed->getArticles()->clear();
        }
        else{
            //new Product Feed
            $productFeed = new ProductFeed();
            //to set this value initial
            $productFeed->setLastExport("now");
        }

        if (empty($params['shopId'])) {
            $params['shopId'] = null;
        }
        if (empty($params['categoryId'])) {
            $params['categoryId'] = null;
        }
        if (empty($params['customerGroupId'])) {
            $params['customerGroupId'] = null;
        }
        if (empty($params['languageId'])) {
            $params['languageId'] = null;
        }

        //save data of the category tree
        $params['categories'] = $this->prepareAssociationDataForSaving('categories','Shopware\Models\Category\Category',$params);

        //save data of the supplier filter
        $params['suppliers'] = $this->prepareAssociationDataForSaving('suppliers','Shopware\Models\Article\Supplier',$params);

        //save data of the article filter
        $params['articles'] = $this->prepareAssociationDataForSaving('articles','Shopware\Models\Article\Article',$params);

        $params['attribute'] = $params['attribute'][0];
        $productFeed->fromArray($params);

        //just for future use
        $productFeed->setExpiry(date("d-m-Y", time()));
        $productFeed->setLastChange(date("d-m-Y", time()));

        try {
            Shopware()->Models()->persist($productFeed);
            Shopware()->Models()->flush();

            $data = $this->getFeed($productFeed->getId());
            $this->View()->assign(array('success' => true, 'data' => $data));
        }
        catch (Exception $e) {
            $this->View()->assign(array('success' => false, 'message' => $e->getMessage()));
        }
    }