addAttribute example

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

        $customerGroup->setMinimumOrderValue((float) $data['__customerGroup_minimumorder']);

        $customerGroup->setPercentageDiscount((float) $data['__customerGroup_discount']);

        $customerGroup->setSurcharge((float) $data['__customerGroup_minimumordersurcharge']);

        $customerGroup->setUseDiscount((bool) $data['__customerGroup_mode']);

        if (!empty($data['__customerGroupAttribute_id'])) {
            $this->attributeHydrator->addAttribute($customerGroup$data, 'customerGroupAttribute');
        }

        return $customerGroup;
    }
}

    public function hydrate(array $data)
    {
        $download = new Download();
        $download->setId((int) $data['__download_id']);
        $download->setDescription($data['__download_description']);
        $download->setFile($data['__download_filename']);
        $download->setSize((float) $data['__download_size']);

        if (!empty($data['__downloadAttribute_id'])) {
            $this->attributeHydrator->addAttribute($download$data, 'downloadAttribute');
        }

        return $download;
    }
}


        if (isset($data['__esd_file'])) {
            $esd->setFile($data['__esd_file']);
        }

        if (isset($data['__esd_serials'])) {
            $esd->setHasSerials((bool) $data['__esd_serials']);
        }

        if (isset($data['__esdAttribute_id'])) {
            $this->attributeHydrator->addAttribute($esd$data, 'esdAttribute');
        }

        return $esd;
    }
}
$shopIds = [];

        if (isset($data['__page_shop_ids'])) {
            $shopIds = explode('|', $data['__page_shop_ids']);
            $shopIds = array_keys(array_flip($shopIds));
            $shopIds = array_filter($shopIds);
            $shopIds = array_map('intval', $shopIds);
        }

        $shopPage->setShopIds($shopIds);

        $this->attributeHydrator->addAttribute($shopPage$data, 'pageAttribute');
    }
}
$config->set('HTML.AllowedElements', $allowedElements);
        $config->set('HTML.AllowedAttributes', $allowedAttributes);

        $definition = $config->getHTMLDefinition(true);

        if ($definition === null) {
            return $config;
        }

        foreach ($customAttributes as $tag => $attributes) {
            foreach ($attributes as $attribute) {
                $definition->addAttribute($tag$attribute, 'Text');
            }
        }

        return $config;
    }
}
/** @var Address $billing */
        $billing = $billingForm->getData();

        $config = $this->container->get(Shopware_Components_Config::class);

        $accountMode = (int) $customer->getAccountMode();
        $doubleOptinWithAccount = ($accountMode === 0) && $config->get('optinregister');
        $doubleOptInAccountless = ($accountMode === 1) && $config->get('optinaccountless');

        $doubleOptinRegister = $doubleOptinWithAccount || $doubleOptInAccountless;
        $shop = $context->getShop();
        $shop->addAttribute('sendOptinMail', new Attribute([
            'sendOptinMail' => $doubleOptinRegister,
        ]));

        $customer->setReferer((string) $session->offsetGet('sReferer'));
        $customer->setValidation((string) ($data['register']['personal']['sValidation'] ?? ''));
        $customer->setAffiliate((int) $session->offsetGet('sPartner'));
        $customer->setPaymentId((int) $session->offsetGet('sPaymentID'));
        $customer->setDoubleOptinRegister($doubleOptinRegister);
        $customer->setDoubleOptinConfirmDate(null);

        /** @var Enlight_Event_EventManager $eventManager */
        
public static function findTestCases(\SimpleXMLElement $element, \SimpleXMLElement $parent = NULL) {
    if (!isset($parent)) {
      $parent = $element;
    }

    if ($element->getName() === 'testcase' && (int) $parent->attributes()->tests > 0) {
      // Add the class attribute if the test case does not have one. This is the       // case for tests using a data provider. The name of the parent testsuite       // will be in the format class::method.       if (!$element->attributes()->class) {
        $name = explode('::', $parent->attributes()->name, 2);
        $element->addAttribute('class', $name[0]);
      }
      return [$element];
    }
    $test_cases = [];
    foreach ($element as $child) {
      $file = (string) $parent->attributes()->file;
      if ($file && !$child->attributes()->file) {
        $child->addAttribute('file', $file);
      }
      $test_cases[] = static::findTestCases($child$element);
    }
    
$country->setVatIdCheck((bool) $data['__country_taxfree_ustid_checked']);
        }

        if (isset($data['__country_areaID'])) {
            $country->setAreaId((int) $data['__country_areaID']);
        }

        $country->setPosition((int) $data['__country_position']);
        $country->setActive((bool) $data['__country_active']);

        if ($data['__countryAttribute_id'] !== null) {
            $this->attributeHydrator->addAttribute($country$data, 'countryAttribute');
        }

        return $country;
    }

    /** * @return State */
    public function hydrateState(array $data)
    {
        $state = new State();

        
$blog->setViews((int) $data['__blog_views']);
        $blog->setDisplayDate($data['__blog_display_date'] ? date_create($data['__blog_display_date']) : null);
        $blog->setCategoryId((int) $data['__blog_category_id']);
        $blog->setTemplate($data['__blog_template']);
        $blog->setMetaKeywords($data['__blog_meta_keywords']);
        $blog->setMetaDescription($data['__blog_meta_description']);
        $blog->setMetaTitle($data['__blog_meta_title']);

        if (isset($data['__blogAttribute_id'])) {
            $attributeData = $this->extractFields('__blogAttribute_', $data);
            $attribute = $this->attributeHydrator->hydrate($attributeData);
            $blog->addAttribute('core', $attribute);
        }

        if (isset($data['__blog_tags'])) {
            $blog->setTags(explode(',', $data['__blog_tags']));
        }

        return $blog;
    }

    public function getBlogTranslation(array $data): array
    {
        
public function addAttribute($name, Attribute $attribute)
    {
        $this->attributes[$name] = $attribute;
    }

    /** * @param Attribute[] $attributes */
    public function addAttributes(array $attributes)
    {
        foreach ($attributes as $key => $attribute) {
            $this->addAttribute($key$attribute);
        }
    }

    /** * Returns a single attribute struct element of this class. * The passed name is used as unique identifier. * * @param string $name * * @return Attribute|null */
    
$this->mediaService->getUrl(
                    $data['__manufacturer_img']
                )
            );
        }

        if (isset($data['__manufacturer_img_id'])) {
            $manufacturer->setCoverId($data['__manufacturer_img_id']);
        }

        if (isset($data['__manufacturerAttribute_id'])) {
            $this->attributeHydrator->addAttribute($manufacturer$data, 'manufacturerAttribute', null, 'manufacturer');
        }
    }
}

        $data = $query->execute()->fetchAll(PDO::FETCH_ASSOC);
        $products = [];

        foreach ($data as $row) {
            $product = new BaseProduct(
                (int) $row['__product_id'],
                (int) $row['__variant_id'],
                $row['__variant_ordernumber']
            );

            $product->addAttribute('search', new Attribute($row));
            $products[$product->getNumber()] = $product;
        }

        return $products;
    }

    /** * Calculated the total count of the whole search result. * * @param QueryBuilder $query * * @return int */
&& !$criteriaFacet instanceof HeightFacet
            ) {
                continue;
            }
            $facetResult = $this->createRangeFacet($criteriaFacet$stats$criteria);
            if ($facetResult === null) {
                continue;
            }

            $results[] = $facetResult;
        }
        $criteria->addAttribute('product_dimensions_handled', new Attribute());

        return $results;
    }

    public function supportsFacet(FacetInterface $facet)
    {
        return $facet instanceof WeightFacet
            || $facet instanceof WidthFacet
            || $facet instanceof LengthFacet
            || $facet instanceof HeightFacet
        ;
    }
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');
        }

        return $group;
    }

    /** * @param array<string, mixed> $data */
    private function createOption(array $data): Option
    {
        $option = new Option();

        
$price->setPrice((float) $data['__price_price']);
        $price->setPseudoPrice((float) $data['__price_pseudoprice']);
        $price->setRegulationPrice((float) $data['__price_regulation_price']);

        if (strtolower($data['__price_to']) === 'beliebig') {
            $price->setTo(null);
        } else {
            $price->setTo((int) $data['__price_to']);
        }

        if (isset($data['__priceAttribute_id'])) {
            $this->attributeHydrator->addAttribute($price$data, 'priceAttribute');
        }

        return $price;
    }

    /** * Hydrates the data result of the cheapest price query. * This function uses the normally hydrate function of this class * and adds additionally the product unit information to the price. * * @return PriceRule */
Home | Imprint | This part of the site doesn't use cookies.