Prepare's the URL rewrite product => category relation attributes.

@return array The prepared attributes
978682
protected function prepareUrlRewriteProductCategoryAttributes()
    {

        // return the prepared product
        return $this->initializeEntity(
            array(
                MemberNames::PRODUCT_ID     => $this->entityId,
                MemberNames::CATEGORY_ID    => $this->categoryId,
                MemberNames::URL_REWRITE_ID => $this->urlRewriteId
            )
        );
    }
581801
protected function prepareAttributes($attributes)
    {
        foreach($this->getAttributeConfig() as $attr => $config){

            // If the attribute is not defined in model or $attributes array
            // set the default value.
            if(!isset($this->attributes[$attr]) && !isset($attributes[$attr])){

                $attributes[$attr] = $config['default'];

            }

        }

        foreach($attributes as $key => $value){

            if(isset($this->config['attributes'][$key])){

                $attributes[$key] = $this->$key()->before_save($value);

            } elseif(isset($this->config['relationships'][$key])){

                unset($attributes[$key]);

                $relationship = $this->config['relationships'][$key];

                $this->translateShorthand($value);

                switch($relationship['type']){

                    case Relationship::HAS_PIVOT:

                        if($value instanceof Collection) $value = $value->all();

                        if($value instanceof EntityContract) $value = [$value];

                        $this->$key()->saveMany($value);

                        break;

                    case Relationship::HAS_MANY:

                        $this->$key()->saveMany((array)$value);

                        break;

                    case Relationship::BELONGS_TO:

                        $this->$key()->associate($value);

                        break;

                    case Relationship::HAS_ONE:

                        $this->$key()->save($value);

                        break;

                    default:

                        throw new \Exception(sprintf(
                            "Unknown relationship type \"%s\" on entity \"%s\"",
                            $relationship['type'],
                            $relationship['entity']
                        ));

                        break;
                }

            }

        }

        return $attributes;
    }
1193596
protected function prepareAttributes()
    {

        // reset the position counter for the bundle selection
        $this->resetPositionCounter();

        try {
            // load and map the parent SKU
            $parentId = $this->mapSku($this->getValue(ColumnKeys::BUNDLE_PARENT_SKU));
        } catch (\Exception $e) {
            throw $this->wrapException(array(ColumnKeys::BUNDLE_PARENT_SKU), $e);
        }

        // extract the parent/child ID as well as type and position
        $required = $this->getValue(ColumnKeys::BUNDLE_VALUE_REQUIRED);
        $type = $this->getValue(ColumnKeys::BUNDLE_VALUE_TYPE);
        $position = 1;

        // return the prepared product
        return $this->initializeEntity(
            array(
                MemberNames::PARENT_ID => $parentId,
                MemberNames::REQUIRED  => $required,
                MemberNames::POSITION  => $position,
                MemberNames::TYPE      => $type
            )
        );
    }
1058689
public function getSaleProductsAttributeList()
    {
        $saleProducts = SaleProductQuery::create()->filterBySaleId($this->getId())->orderByProductId()->find();

        $selectedAttributes = [];

        $currentProduct = false;

        /** @var SaleProduct $saleProduct */
        foreach ($saleProducts as $saleProduct) {
            if ($currentProduct != $saleProduct->getProductId()) {
                $currentProduct = $saleProduct->getProductId();

                $selectedAttributes[$currentProduct] = [];
            }

            $selectedAttributes[$currentProduct][] = $saleProduct->getAttributeAvId();
        }

        return $selectedAttributes;
    }
656546
protected function prepareAttributes()
    {

        // prepare the date format for the created at/updated at dates
        $createdAt = $this->getValue(ColumnKeys::CREATED_AT, date('Y-m-d H:i:s'), array($this, 'formatDate'));
        $updatedAt = $this->getValue(ColumnKeys::UPDATED_AT, date('Y-m-d H:i:s'), array($this, 'formatDate'));

        // initialize the product values
        $sku = $this->getValue(ColumnKeys::SKU);
        $productType = $this->getValue(ColumnKeys::PRODUCT_TYPE);

        // load the product's attribute set ID
        $attributeSet = $this->getAttributeSet();
        $attributeSetId = $attributeSet[MemberNames::ATTRIBUTE_SET_ID];

        // return the prepared product
        return $this->initializeEntity(
            array(
                MemberNames::SKU              => $sku,
                MemberNames::CREATED_AT       => $createdAt,
                MemberNames::UPDATED_AT       => $updatedAt,
                MemberNames::HAS_OPTIONS      => 0,
                MemberNames::REQUIRED_OPTIONS => 0,
                MemberNames::TYPE_ID          => $productType,
                MemberNames::ATTRIBUTE_SET_ID => $attributeSetId
            )
        );
    }
598808
protected function process()
    {

        // process the link type attributes
        $productLinkAttribute = $this->getProductLinkAttributeByLinkTypeCodeAndAttributeCode($this->getValue(ColumnKeys::LINK_TYPE_CODE), $this->getValue(ColumnKeys::LINK_TYPE_ATTRIBUTE_CODE));

        // try to load the product link attribute
        $this->setProductLinkAttributeId($productLinkAttribute[MemberNames::PRODUCT_LINK_ATTRIBUTE_ID]);

        // load the link attribute data type
        $dataType = $productLinkAttribute[MemberNames::DATA_TYPE];

        // concatenate the initialize/persist method names
        $intializeMethod = sprintf('initializeProductLinkAttribute%s', $dataType);
        $persistMethod = sprintf('persistProductLinkAttribute%s', $dataType);

        // prepare, initialize and persist the product link attribute int entity
        $this->$persistMethod($this->$intializeMethod($this->prepareAttributes()));
    }
1150065
public function getAttributes()
    {
        $attributeEntities = $this->entity->getProductAttributes();

        $attributes = [];
        foreach ($attributeEntities as $attributesEntity) {
            $attributes[] = new ProductAttribute(
                $attributesEntity,
                $this->locale,
                $this->productLocaleManager->getFallbackLocale()
            );
        }

        return $attributes;
    }
140287
public function getAttributes()
    {
        return [
            Attributes\IdAttribute::make(),
            Attributes\TextAttribute::make('name')
                ->setRequired(true),
            Attributes\TextAttribute::make('code'),
            Attributes\BelongsToAttribute::make('legal_entity_id')
                ->setRelationName('legal_entity')
                ->setRelationManager(LegalEntityManager::class),
            Attributes\CreatedAtAttribute::make(),
            Attributes\UpdatedAtAttribute::make(),
            Attributes\DeletedAtAttribute::make(),
        ];
    }
341597
protected function process()
    {

        // process the new URL rewrites first
        parent::process();

        // load the root category
        $rootCategory = $this->getRootCategory();

        // create redirect URL rewrites for the existing URL rewrites
        foreach ($this->existingUrlRewrites as $existingUrlRewrite) {
            // if the URL rewrite has been created manually
            if ((integer) $existingUrlRewrite[MemberNames::IS_AUTOGENERATED] === 0) {
                // do NOTHING, because someone really WANTED to create THIS redirect
                continue;
            }

            // query whether or not 301 redirects have to be created, so don't create redirects
            // if the product is NOT visible or the rewrite history has been deactivated
            if ($this->isVisible() && $this->getSubject()->getCoreConfigData(CoreConfigDataKeys::CATALOG_SEO_SAVE_REWRITES_HISTORY, true)) {
                // if the URL rewrite already IS a redirect
                if ((integer) $existingUrlRewrite[MemberNames::REDIRECT_TYPE] !== 0) {
                    // do NOT create another redirect or update the actual one
                    continue;
                }

                // initialize the data with the URL rewrites new 301 configuration
                $attr = array(MemberNames::REDIRECT_TYPE => 301);

                // initialize the category with the root category
                $category = $rootCategory;

                // load the metadata from the existing URL rewrite
                $metadata = $this->getMetadata($existingUrlRewrite);

                // query whether or not the URL key of the existing URL rewrite has changed
                if (is_array($metadata) && isset($metadata[UrlRewriteObserver::CATEGORY_ID])) {
                    if (isset($this->urlRewrites[$metadata[UrlRewriteObserver::CATEGORY_ID]])) {
                        try {
                            // if yes, try to load the original category and OVERRIDE the default category
                            $category = $this->getCategory($metadata[UrlRewriteObserver::CATEGORY_ID], $this->getValue(ColumnKeys::STORE_VIEW_CODE));
                        } catch (\Exception $e) {
                            // if the old category can NOT be loaded, remove the
                            // category ID from the URL rewrites metadata
                            $attr[MemberNames::METADATA] = null;

                            // finally log a warning that the old category is not available ony more
                            $this->getSubject()
                                 ->getSystemLogger()
                                 ->warning(
                                     sprintf(
                                         'Category with ID "%d" is not longer available for URL rewrite with ID "%d"',
                                         $metadata[UrlRewriteObserver::CATEGORY_ID],
                                         $existingUrlRewrite[MemberNames::URL_REWRITE_ID]
                                     )
                                 );
                        }
                    }
                }

                // load target path/metadata for the actual category
                $targetPath = $this->prepareRequestPath($category);

                // skip update of URL rewrite, if resulting new target path EQUALS old request path
                if ($targetPath === $existingUrlRewrite[MemberNames::REQUEST_PATH]) {
                    // finally log a warning that the old category is not available ony more
                    $this->getSubject()
                         ->getSystemLogger()
                         ->warning(
                             sprintf(
                                 'New target path "%s" eqals request path for URL rewrite with ID "%d"',
                                 $existingUrlRewrite[MemberNames::REQUEST_PATH],
                                 $existingUrlRewrite[MemberNames::URL_REWRITE_ID]
                             )
                         );

                    // stop processing the URL rewrite
                    continue;
                }

                // set the target path
                $attr[MemberNames::TARGET_PATH] = $targetPath;

                // merge and return the prepared URL rewrite
                $existingUrlRewrite = $this->mergeEntity($existingUrlRewrite, $attr);

                // create the URL rewrite
                $this->persistUrlRewrite($existingUrlRewrite);
            } else {
                // query whether or not the URL rewrite has to be removed
                if ($this->getSubject()->getConfiguration()->hasParam(ConfigurationKeys::CLEAN_UP_URL_REWRITES) &&
                    $this->getSubject()->getConfiguration()->getParam(ConfigurationKeys::CLEAN_UP_URL_REWRITES)
                ) {
                    // delete the existing URL rewrite
                    $this->deleteUrlRewrite($existingUrlRewrite);

                    // log a message, that old URL rewrites have been cleaned-up
                    $this->getSubject()
                         ->getSystemLogger()
                         ->warning(
                             sprintf(
                                 'Cleaned-up %d URL rewrite "%s" for product with SKU "%s"',
                                 $existingUrlRewrite[MemberNames::REQUEST_PATH],
                                 $this->getValue(ColumnKeys::SKU)
                             )
                         );
                }
            }
        }
    }
878607
protected function prepareForCategoryRelation()
    {
        // also handle category relation name, if necessary
        if ($this->data['has_categories']) {

            $this->determineCategoryRelationName();

            // store the category name in the data
            if ( ! empty($this->categoryRelationName)) {
                $this->data->relationships['category'][ $this->categoryRelationName ] = [
                    'model' => config('pxlcms.generator.standard_models.category'),
                    'type'  => Generator::RELATIONSHIP_BELONGS_TO,
                ];
            }
        }

        return $this;
    }
934312
public function getAttributes()
    {

        // initialize the array with the attributes
        $attributes = array();

        // prepare the pattern to filter the attributes
        $pattern = sprintf('%s-*', $this->getSerial());

        // prepare the array with the attributes
        foreach ($this as $key => $value) {
            if (fnmatch($pattern, $key)) {
                $attributes[$key] = $value;
            }
        }

        // return the attributes
        return $attributes;
    }
1177571
private function getAttributeKeys()
    {
        if (!isset($this->attributeKeys)) {
            $this->attributeKeys = $this->category->getList();
        }

        return $this->attributeKeys;
    }
753170
public function customAttributes()
    {
        if (!$form = $this->distributor->form(null, $this->resourceName())){
            return [];
        }

        return $form->getValidator()->buildAttributeNames($form);
    }
1046925
public function prepareLinkTypeMappings()
    {

        // initialize the array with link type mappings
        $linkTypeMappings = array();

        // prepare the link type mappings
        foreach ($this->getLinkTypes() as $linkType) {
            // map the link type code to the column name, if necessary
            $columnName = $this->mapLinkTypeCodeToColumnName($linkType[MemberNames::CODE]);

            // create the header for the link type mapping
            $linkTypeMappings[$linkType[MemberNames::CODE]][] = array (
                $fullColumnName = sprintf('%s_skus', $columnName),
                $this->getLinkTypeColumnCallback($fullColumnName)
            );

            // add the mappings for the columns that contains the values for the configured link type attributes
            foreach ($this->getProductLinkAttributes($linkType[MemberNames::CODE]) as $linkAttribute) {
                // initialize the full column name that uses the column name as prefix and the attribute code as suffix
                $fullColumnName = sprintf('%s_%s', $columnName, $linkAttribute[MemberNames::PRODUCT_LINK_ATTRIBUTE_CODE]);
                // load the callback that extracts the values from the columns
                $callback = $this->getLinkTypeColumnCallback($fullColumnName);

                // map the column name to the real column name
                if (isset($this->linkTypeAttributeColumnToCallbackMapping[$fullColumnName])) {
                    list ($fullColumnName, ) = $this->linkTypeAttributeColumnToCallbackMapping[$fullColumnName];
                }

                // add the link type mapping for the column with the link type value
                $linkTypeMappings[$linkType[MemberNames::CODE]][] = array(
                    $fullColumnName,
                    $callback,
                    $linkAttribute[MemberNames::PRODUCT_LINK_ATTRIBUTE_CODE]
                );
            }
        }

        // return the link type mappings
        return $linkTypeMappings;
    }
1348407
public function generateAttributes ()
	{
		
		// Get attributes and relationships
		
		$attributes	= $this->getAttributes ();
		
		$this->addLine ('protected static $attributes = array (');
		$this->tabUp (FALSE);
		
		// Add each attribute
		
		foreach ($attributes as $name => $attribute)
		{
			
			$this->addLine ($this->tabVals ('\'' . $name . '\'', 'array (', 4, '=> '));
			$this->tabUp (FALSE);
			
			foreach ($attribute as $key => $val)
			{
				
				switch ($key)
				{
					
					case 'charset':
					case 'relation':
						
						$val	= '\'' . $val . '\'';
						break;
					
					case 'valid':
					case 'values':
						
						$val	= 'array (' . $val . ')';
						break;
					
				}
				
				$this->addLine ($this->tabVals ('\'' . $key . '\'', $val . ',', 3, '=> '));
				
			}
			
			// Remove last ,

			if (substr ($this->class, -2) == ",\n")
			{
				$this->class	= substr ($this->class, 0, -2) . "\n";
			}
			
			$this->tabDown (FALSE);
			$this->addLine ('),');
			
		}
		
		// Remove last ,

		if (substr ($this->class, -2) == ",\n")
		{
			$this->class	= substr ($this->class, 0, -2) . "\n";
		}
		
		// End attributes
		
		$this->tabDown (FALSE);
		$this->addLine (');');
		
	}
172564
public function getLinkAttributes()
    {
        $attributes = [
            'href' => $this->owner->Link,
            'title' => $this->owner->LinkTitle
        ];
        
        if ($class = $this->owner->LinkClass) {
            $attributes['class'] = $class;
        }
        
        if ($this->owner->OpenLinkInNewTab) {
            $attributes['target'] = '_blank';
        }
        
        return $attributes;
    }
1344007
private function prepareSortOrders()
    {
        $sortOrders = [];

        $useProductuctLimitation = isset($this->_productLimitationFilters['sortParams']);

        foreach ($this->_orders as $attribute => $direction) {
            $sortParams = ['direction' => $direction];
            $sortField  = $this->mapFieldName($attribute);

            if ($useProductuctLimitation && isset($this->_productLimitationFilters['sortParams'][$attribute])) {
                $sortField  = $this->_productLimitationFilters['sortParams'][$attribute]['sortField'];
                $sortParams = array_merge($sortParams, $this->_productLimitationFilters['sortParams'][$attribute]);
            } elseif ($attribute == 'price') {
                // Change the price sort field to the nested price field.
                $sortField = 'price.price';
                $sortParams['nestedPath'] = 'price';
                // Ensure we sort on the position field of the current customer group.
                $customerGroupId = $this->_productLimitationFilters['customer_group_id'];
                $sortParams['nestedFilter'] = ['price.customer_group_id' => $customerGroupId];
            }

            $sortOrders[$sortField] = $sortParams;
        }

        return $sortOrders;
    }