コード例 #1
0
 public function testCanInjectParameters()
 {
     $category = new \Shopware\Models\Category\Category();
     $categoryId = 1;
     $translationId = 12;
     $customerGroupId = 23;
     $category->setPrimaryIdentifier($categoryId);
     $sArticles = new sArticles($category, $translationId, $customerGroupId);
     $this->assertsArticlesState($sArticles, $categoryId, $translationId, $customerGroupId);
 }
コード例 #2
0
 /**
  * @param array $category
  * @param \Shopware\Models\Category\Repository $categoryRepository
  * @param $metaData
  * @return Shopware\Models\Category\Category
  */
 public function saveCategory($category, \Shopware\Models\Category\Repository $categoryRepository, $metaData)
 {
     $parent = $categoryRepository->find($category['parentID']);
     if (!$parent) {
         throw new \Exception(sprintf('Could not update/insert category with id %s, could not find parentId %s', $category['categoryID'], $category['parentID']));
     }
     $category = $this->toUtf8($category);
     $mapping = array();
     foreach ($metaData->fieldMappings as $fieldMapping) {
         $mapping[$fieldMapping['columnName']] = $fieldMapping['fieldName'];
     }
     $mapping = $mapping + array('categoryID' => 'id', 'ac_attr1' => 'attribute_attribute1', 'ac_attr2' => 'attribute_attribute2', 'ac_attr3' => 'attribute_attribute3', 'ac_attr4' => 'attribute_attribute4', 'ac_attr5' => 'attribute_attribute5', 'ac_attr6' => 'attribute_attribute6');
     $updateData = $this->mapFields($category, $mapping);
     $updateData['parent'] = $parent;
     $attribute = $this->prefixToArray($updateData, 'attribute_');
     if (!empty($attribute)) {
         $updateData['attribute'] = $attribute;
     }
     /** @var $categoryModel \Shopware\Models\Category\Category */
     $categoryModel = $categoryRepository->find($category['categoryID']);
     if (!$categoryModel) {
         $categoryModel = new \Shopware\Models\Category\Category();
         $categoryModel->setPrimaryIdentifier($category['categoryID']);
         $this->getManager()->persist($categoryModel);
     }
     $categoryModel->fromArray($updateData);
     return $categoryModel;
 }