Exemple #1
0
    /**
     * Delete article
     *
     * DELETE /api/articles/{id}
     */
    public function deleteAction()
    {
        $id = $this->Request()->getParam('id');

        $this->resource->delete($id);

        $this->View()->assign(array('success' => true));
    }
 /**
  * Does the actual import
  */
 public function import()
 {
     $parentId = Shopware()->Models()->find('Shopware\\Models\\Shop\\Shop', $this->shopId)->getCategory()->getId();
     // Trigger to indicate an error while creating new category
     $addError = false;
     foreach ($this->plentyCategoryBranch as $plentyCategory) {
         $plentyCategoryId = $plentyCategory['branchId'];
         $plentyCategoryName = $plentyCategory['name'];
         if ($this->categoryNodeLang != $this->shopLang) {
             $plentyLocalCategoryName = $this->getLocalCategoryName($plentyCategoryId);
             if ($plentyLocalCategoryName) {
                 $plentyCategoryName = $plentyLocalCategoryName;
             }
         }
         // Root category id (out of the shop)
         $CategoryFound = self::$CategoryRepository->findOneBy(array('name' => $plentyCategoryName, 'parentId' => $parentId));
         if ($CategoryFound instanceof Shopware\Models\Category\Category) {
             //
             PlentymarketsMappingEntityCategory::addCategory($CategoryFound->getId(), $this->shopId, $plentyCategoryId, $this->storeId);
             $parentId = $CategoryFound->getId();
         } else {
             $params = array();
             $params['name'] = $plentyCategoryName;
             $params['parentId'] = $parentId;
             try {
                 // Create
                 $CategoryModel = self::$CategoryApi->create($params);
                 // Add mapping and save into the object
                 PlentymarketsMappingEntityCategory::addCategory($CategoryModel->getId(), $this->shopId, $plentyCategoryId, $this->storeId);
                 // Parent
                 $parentCategoryName = $CategoryModel->getParent()->getName();
                 // Log
                 PlentymarketsLogger::getInstance()->message('Sync:Item:Category', 'The category »' . $plentyCategoryName . '« has been created beneath the category »' . $parentCategoryName . '«');
                 // Id to connect with the item
                 $parentId = $CategoryModel->getId();
             } catch (Exception $E) {
                 // Log
                 PlentymarketsLogger::getInstance()->error('Sync:Item:Category', 'The category »' . $plentyCategoryName . '« with the parentId »' . $parentId . '« could not be created (' . $E->getMessage() . ')', 3300);
                 // Set the trigger - the category will not be connected with the item
                 $addError = true;
             }
         }
     }
     if ($addError) {
         return false;
     } else {
         return $parentId;
     }
 }