예제 #1
0
 /**
  * Determines if a feed needs to be marked as dirty
  * New feeds, feeds whose header, body or footer have been
  * changed are marked as dirty
  *
  * @param ProductFeed $productFeed
  * @param array $params
  * @return ProductFeed
  */
 private function setDirty($productFeed, $params)
 {
     if ($productFeed->isDirty()) {
         return $productFeed;
     }
     if (!$productFeed->getId()) {
         $productFeed->setDirty(true);
     } elseif (isset($params['header']) && $params['header'] != $productFeed->getHeader()) {
         $productFeed->setDirty(true);
     } elseif (isset($params['body']) && $params['body'] != $productFeed->getBody()) {
         $productFeed->setDirty(true);
     } elseif (isset($params['footer']) && $params['footer'] != $productFeed->getFooter()) {
         $productFeed->setDirty(true);
     }
     return $productFeed;
 }
예제 #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()));
        }
    }