Group example

$set->setName($data['__configuratorSet_name']);
        $set->setType((int) $data['__configuratorSet_type']);

        return $set;
    }

    /** * @param array<string, mixed> $data */
    private function createGroup(array $data): Group
    {
        $group = new Group();
        $translation = $this->getTranslation($data, '__configuratorGroup');
        $data = array_merge($data$translation);

        $group->setId((int) $data['__configuratorGroup_id']);
        $group->setName($data['__configuratorGroup_name']);
        $group->setDescription($data['__configuratorGroup_description']);

        if ($data['__configuratorGroupAttribute_id']) {
            $this->attributeHydrator->addAttribute($group$data, 'configuratorGroupAttribute', null, 'configuratorGroup');
        }

        

    public function create(array $params)
    {
        $this->checkPrivilege('create');

        $params = $this->prepareCustomerGroupData($params);

        $result = new Group();

        $discounts = $params['discounts'];
        unset($params['discounts']);

        $result->fromArray($params);

        $violations = $this->getManager()->validate($result);
        if ($violations->count() > 0) {
            throw new ValidationException($violations);
        }

        
$this->View()->assign(['success' => true, 'data' => $model->toArray]);
    }

    /** * Creates a new custom newsletter group */
    public function createNewsletterGroupAction()
    {
        $data = $this->Request()->getParams();

        $groupModel = new Shopware\Models\Newsletter\Group();
        $groupModel->fromArray($data);
        $this->get('models')->persist($groupModel);
        $this->get('models')->flush();

        $this->View()->assign(['success' => true]);
    }

    /** * Create a new sender */
    public function createSenderAction()
    {

    public function create(array $params)
    {
        $this->checkPrivilege('create');

        $params = $this->preparePropertyData($params);

        $property = new \Shopware\Models\Property\Group();
        $property->fromArray($params);

        $violations = $this->getManager()->validate($property);
        if ($violations->count() > 0) {
            throw new ApiException\ValidationException($violations);
        }

        $this->getManager()->persist($property);
        $this->flush();

        return $property;
    }
$this->View()->assign([
                'success' => false,
                'message' => 'nameExists',
            ]);

            return;
        }

        // Check if key exists         $model = $repository->findOneBy(['key' => $key]);
        if ($model === null) {
            $model = new Group();
            $model->setKey($key);
        } else {
            $this->View()->assign([
                'success' => false,
                'message' => 'variableExists',
            ]);

            return;
        }
        $model->setName($name);

        
/** * Saves the passed configurator group data. If an id passed, the function updates the existing group, otherwise * a new group will be created. */
    public function saveConfiguratorGroupAction()
    {
        $id = (int) $this->Request()->getParam('id');
        if (!empty($id)) {
            $group = $this->get('models')->find(Group::class$id);
        } else {
            $group = new Group();
        }
        $data = $this->Request()->getParams();
        unset($data['options']);
        $group->fromArray($data);
        $this->get('models')->persist($group);
        $this->get('models')->flush();
        $data['id'] = $group->getId();

        $this->View()->assign([
            'success' => true,
            'data' => $data,
        ]);
public function __construct(AttributeHydrator $attributeHydrator)
    {
        $this->attributeHydrator = $attributeHydrator;
    }

    /** * @return Group */
    public function hydrate(array $data)
    {
        $customerGroup = new Group();

        $customerGroup->setId((int) $data['__customerGroup_id']);

        $customerGroup->setName($data['__customerGroup_description']);

        $customerGroup->setDisplayGrossPrices((bool) $data['__customerGroup_tax']);

        $customerGroup->setInsertedGrossPrices((bool) $data['__customerGroup_taxinput']);

        $customerGroup->setKey($data['__customerGroup_groupkey']);

        
'success' => true,
                'data' => $assignments,
                'total' => \count($assignments),
            ]
        );
    }

    public function createSetAction()
    {
        $params = $this->Request()->getPost();

        $group = new Group();
        $group->fromArray($params);

        $modelManager = $this->get(\Shopware\Components\Model\ModelManager::class);
        try {
            $modelManager->persist($group);
            $modelManager->flush();
        } catch (\Exception $e) {
            $this->View()->assign(['success' => false, 'message' => $e->getMessage()]);

            return;
        }
        
return $sets;
    }

    /** * @param array<string, mixed> $data * * @return Group */
    public function hydrateGroup(array $data)
    {
        $group = new Group();
        $translation = $this->getTranslation($data, '__propertyGroup', ['optionName' => 'name']);
        $data = array_merge($data$translation);

        $group->setId((int) $data['__propertyGroup_id']);
        $group->setName($data['__propertyGroup_name']);
        $group->setFilterable((bool) $data['__propertyGroup_filterable']);

        if ($data['__propertyGroupAttribute_id']) {
            $this->attributeHydrator->addAttribute($group$data, 'propertyGroupAttribute', null, 'propertyGroup');
        }

        
Home | Imprint | This part of the site doesn't use cookies.