Constructs the data array for the view from the given item

@param \Aimeos\MShop\Catalog\Item\Iface $item Catalog item object
@return string[] Multi-dimensional associative list of item data
501445
protected function toArray( \Aimeos\MShop\Catalog\Item\Iface $item, $copy = false )
	{
		$data = $item->toArray( true );
		$data['config'] = [];

		if( $copy === true )
		{
			$data['catalog.id'] = '';
			$data['catalog.siteid'] = $item->getSiteId();
			$data['catalog.code'] = $data['catalog.code'] . '_copy';
		}

		foreach( $item->getConfig() as $key => $value )
		{
			$data['config']['key'][] = $key;
			$data['config']['val'][] = $value;
		}

		return $data;
	}
485423
protected function getProducts( \Aimeos\MShop\Context\Item\Iface $context, array $prodIds, $stockType )
	{
		$productCodes = $stockMap = [];
		$productItems = $this->getProductItems( $context, $prodIds );

		foreach( $productItems as $productItem ) {
			$productCodes[] = $productItem->getCode();
		}

		foreach( $this->getStockItems( $context, $productCodes, $stockType ) as $stockItem ) {
			$stockMap[ $stockItem->getProductCode() ] = true;
		}

		foreach( $productItems as $productId => $productItem )
		{
			if( !isset( $stockMap[ $productItem->getCode() ] ) ) {
				unset( $productItems[$productId] );
			}
		}

		return $productItems;
	}
927806
protected function fromArray( \Aimeos\MShop\Product\Item\Iface $item, array $data )
	{
		$context = $this->getContext();

		$textManager = \Aimeos\MShop::create( $context, 'text' );
		$listManager = \Aimeos\MShop::create( $context, 'product/lists' );

		$listItems = $item->getListItems( 'text', null, null, false );


		foreach( $data as $idx => $entry )
		{
			if( trim( $this->getValue( $entry, 'text.content', '' ) ) === '' ) {
				continue;
			}

			$listType = $entry['product.lists.type'];

			if( ( $listItem = $item->getListItem( 'text', $listType, $entry['text.id'], false ) ) === null ) {
				$listItem = $listManager->createItem();
			}

			if( ( $refItem = $listItem->getRefItem() ) === null ) {
				$refItem = $textManager->createItem();
			}

			$refItem->fromArray( $entry, true );
			$conf = [];

			foreach( (array) $this->getValue( $entry, 'config/key' ) as $num => $key )
			{
				if( trim( $key ) !== '' && ( $val = $this->getValue( $entry, 'config/val/' . $num ) ) !== null ) {
					$conf[$key] = trim( $val );
				}
			}

			$listItem->fromArray( $entry, true );
			$listItem->setPosition( $idx );
			$listItem->setConfig( $conf );

			$item->addListItem( 'text', $listItem, $refItem );

			unset( $listItems[$listItem->getId()] );
		}

		return $item->deleteListItems( $listItems, true );
	}
394777
protected function getItemOptions($item)
    {
        $options = '';
        if ($orderOptions = $this->getItemOrderOptions($item)) {
            foreach ($orderOptions as $_option) {
                if (strlen($options) > 0) {
                    $options .= ', ';
                }
                $options .= $_option['label'].': '.$_option['value'];
            }
        }
        return $options;
    }
293020
public function getViewUrlFor($item)
    {
        if (is_object($item)) {
            $id = $item->getid();
        } else {
            $id = $item['id'];
        }
        $params = ['id' => $id];
        $params = array_merge($params, $this->getExtraParameters());

        return [
            'path' => $this->getPathByConvention($this::SUFFIX_VIEW),
            'params' => $params,
        ];
    }
989556
protected function fromArray( \Aimeos\MShop\Product\Item\Iface $item, array $data )
	{
		$context = $this->getContext();

		$attrManager = \Aimeos\MShop::create( $context, 'attribute' );
		$listManager = \Aimeos\MShop::create( $context, 'product/lists' );

		$listItems = $item->getListItems( 'attribute', 'config', 'interval', false );

		foreach( $data as $idx => $entry )
		{
			if( !array_key_exists( 'attribute.id', $entry ) ) {
				continue;
			}

			if( $entry['attribute.id'] == '' || ( $listItem = $item->getListItem( 'attribute', 'config', $entry['attribute.id'], false ) ) === null ) {
				$listItem = $listManager->createItem()->setType( 'config' );
			}

			if( $entry['attribute.id'] == '' || ( $refItem = $listItem->getRefItem() ) === null )
			{
				$refItem = $attrManager->createItem()->setType( 'interval' );
				$refItem->fromArray( $entry, true );
			}

			unset( $listItems[$listItem->getId()] );

			$item->addListItem( 'attribute', $listItem->setPosition( $idx ), $refItem );
		}

		$item->deleteListItems( $listItems );
	}
1042240
public function parse(array $item): array
    {
        $item['groupId'] = $this->getGroupByName($item['group'])->id;
        unset($item['group']);
        $site = new Site($item);

        return [$site, null];
    }
1101219
protected function createCoupons( \Aimeos\MShop\Order\Item\Base\Iface $orderBaseItem )
	{
		$map = [];
		$manager = \Aimeos\MShop::create( $this->getContext(), 'order/base/product/attribute' );

		foreach( $orderBaseItem->getProducts() as $pos => $orderProductItem )
		{
			if( $orderProductItem->getType() === 'voucher'
				&& $orderProductItem->getAttribute( 'coupon-code', 'coupon' ) === null
			) {
				$codes = [];

				for( $i = 0; $i < $orderProductItem->getQuantity(); $i++ )
				{
					$str = $i . getmypid() . microtime( true ) . $orderProductItem->getId();
					$code = substr( strtoupper( sha1( $str ) ), -8 );
					$map[$code] = $orderProductItem->getId();
					$codes[] = $code;
				}

				$item = $manager->createItem()->setCode( 'coupon-code' )->setType( 'coupon' )->setValue( $codes );
				$orderBaseItem->addProduct( $orderProductItem->setAttributeItem( $item ), $pos );
			}
		}

		$this->addCouponCodes( $map );
		return $orderBaseItem;
	}
402974
protected function fromArray( \Aimeos\MShop\Attribute\Item\Iface $item, array $data )
	{
		$manager = \Aimeos\MShop::create( $this->getContext(), 'attribute/property' );

		$propItems = $item->getPropertyItems( null, false );

		foreach( $data as $entry )
		{
			if( isset( $propItems[$entry['attribute.property.id']] ) )
			{
				$propItem = $propItems[$entry['attribute.property.id']];
				unset( $propItems[$entry['attribute.property.id']] );
			}
			else
			{
				$propItem = $manager->createItem();
			}

			$propItem->fromArray( $entry, true );
			$item->addPropertyItem( $propItem );
		}

		$item->deletePropertyItems( $propItems );
	}
1302419
public function getGroups( \Aimeos\MShop\Context\Item\Iface $context )
	{
		$list = array();
		$manager = \Aimeos\MShop::create( $context, 'customer/group' );

		$search = $manager->createSearch();
		$search->setConditions( $search->compare( '==', 'customer.group.id', $context->getGroupIds() ) );

		foreach( $manager->searchItems( $search ) as $item ) {
			$list[] = $item->getCode();
		}

		return $list;
	}
122199
protected function getItemAttributes(ItemInterface $item)
    {
        $result = $item->getAttributes();

        $result['id'] = $item->getId();
        $result['content'] = $item->getContent();
        $result['collection'] = $item->getCollection();
        $result['path'] = $item->getPath(ItemInterface::SNAPSHOT_PATH_RELATIVE);

        return $result;
    }
1211054
private function getDataFromItem($item)
    {
        if (!is_object($item) && !is_array($item)) {
            return array();
        }

        return is_object($item) ? get_object_vars($item) : $item;
    }
900699
protected function checkConfig( \Aimeos\MShop\Service\Item\Iface $item )
	{
		$msg = '';
		$provider = $this->manager->getProvider( $item );
		$result = $provider->checkConfigBE( $item->getConfig() );

		foreach( $result as $key => $message )
		{
			if( $message !== null ) {
				$msg .= sprintf( "- %1\$s : %2\$s\n", $key, $message );
			}
		}

		if( $msg !== '' ) {
			throw new \Aimeos\Controller\ExtJS\Exception( "Invalid configuration:\n" . $msg );
		}
	}
527964
protected function fromArray( \Aimeos\MShop\Product\Item\Iface $item, array $data )
	{
		$manager = \Aimeos\MShop::create( $this->getContext(), 'stock' );

		$search = $manager->createSearch();
		$search->setConditions( $search->compare( '==', 'stock.productcode', $item->getCode() ) );
		$stockItems = $manager->searchitems( $search );

		$list = (array) $this->getValue( $data, 'stock.id', [] );

		foreach( $list as $idx => $id )
		{
			$type = $this->getValue( $data, 'stock.type/' . $idx );

			if( isset( $stockItems[$id] ) && $stockItems[$id]->getType() == $type )
			{
				$stockItem = $stockItems[$id];
				unset( $stockItems[$id] );
			}
			else
			{
				$stockItem = $manager->createItem()->setType( $type );
			}

			$stockItem->setProductCode( $item->getCode() );
			$stockItem->setStocklevel( $this->getValue( $data, 'stock.stocklevel/' . $idx ) );
			$stockItem->setDateBack( $this->getValue( $data, 'stock.dateback/' . $idx ) );

			$manager->saveItem( $stockItem, false );
		}

		$manager->deleteItems( array_keys( $stockItems ) );
	}
1161322
protected function saveData( \Aimeos\MShop\Common\Manager\Iface $manager, \stdClass $request )
	{
		$data = [];

		if( isset( $request->data ) )
		{
			foreach( (array) $request->data as $entry ) {
				$data[] = $this->saveEntry( $manager, $entry );
			}
		}

		return $data;
	}
1239738
public function parse(array $item): array
    {
        $siteSettings = [];
        foreach ($item['siteSettings'] as $settingKey => $settings) {
            $siteId = isset($settings['siteId']) ? Craft::$app->sites->getSiteByHandle($settings['siteId'])->id : Craft::$app->sites->getPrimarySite()->id;
            unset($settings['siteId']);
            $siteSettings[$siteId] = new CategoryGroup_SiteSettings(array_merge($settings, [
                'siteId' => $siteId,
                'hasUrls' => !empty($settings['uriFormat']),
            ]));
        }
        $categoryGroup = new CategoryGroup([
            'name' => $item['name'],
            'handle' => $item['handle'],
            'maxLevels' => $item['maxLevels'],
        ]);

        $categoryGroup->setSiteSettings($siteSettings);

        return [$categoryGroup, null];
    }
374685
public function saveItem( \Aimeos\MShop\Common\Item\Iface $item, $fetch = true )
	{
		self::checkClass( \Aimeos\MShop\Customer\Item\Group\Iface::class, $item );

		if( !$item->isModified() ) {
			return $item;
		}

		$context = $this->getContext();

		$dbm = $context->getDatabaseManager();
		$dbname = $this->getResourceName();
		$conn = $dbm->acquire( $dbname );

		try
		{
			$id = $item->getId();

			if( $id === null )
			{
				/** mshop/customer/manager/group/typo3/insert/mysql
				 * Inserts a new customer group record into the database table
				 *
				 * @see mshop/customer/manager/group/typo3/insert/ansi
				 */

				/** mshop/customer/manager/group/typo3/insert/ansi
				 * Inserts a new customer group record into the database table
				 *
				 * Items with no ID yet (i.e. the ID is NULL) will be created in
				 * the database and the newly created ID retrieved afterwards
				 * using the "newid" SQL statement.
				 *
				 * The SQL statement must be a string suitable for being used as
				 * prepared statement. It must include question marks for binding
				 * the values from the customer group item to the statement before
				 * they are sent to the database server. The number of question
				 * marks must be the same as the number of columns listed in the
				 * INSERT statement. The order of the columns must correspond to
				 * the order in the saveItems() method, so the correct values are
				 * bound to the columns.
				 *
				 * The SQL statement should conform to the ANSI standard to be
				 * compatible with most relational database systems. This also
				 * includes using double quotes for table and column names.
				 *
				 * @param string SQL statement for inserting records
				 * @since 2015.08
				 * @category Developer
				 * @see mshop/customer/manager/group/typo3/update/ansi
				 * @see mshop/customer/manager/group/typo3/newid/ansi
				 * @see mshop/customer/manager/group/typo3/delete/ansi
				 * @see mshop/customer/manager/group/typo3/search/ansi
				 * @see mshop/customer/manager/group/typo3/count/ansi
				 */
				$path = 'mshop/customer/manager/group/typo3/insert';
			}
			else
			{
				/** mshop/customer/manager/group/typo3/update/mysql
				 * Updates an existing customer group record in the database
				 *
				 * @see mshop/customer/manager/group/typo3/update/ansi
				 */

				/** mshop/customer/manager/group/typo3/update/ansi
				 * Updates an existing customer group record in the database
				 *
				 * Items which already have an ID (i.e. the ID is not NULL) will
				 * be updated in the database.
				 *
				 * The SQL statement must be a string suitable for being used as
				 * prepared statement. It must include question marks for binding
				 * the values from the customer group item to the statement before
				 * they are sent to the database server. The order of the columns
				 * must correspond to the order in the saveItems() method, so the
				 * correct values are bound to the columns.
				 *
				 * The SQL statement should conform to the ANSI standard to be
				 * compatible with most relational database systems. This also
				 * includes using double quotes for table and column names.
				 *
				 * @param string SQL statement for updating records
				 * @since 2015.08
				 * @category Developer
				 * @see mshop/customer/manager/group/typo3/insert/ansi
				 * @see mshop/customer/manager/group/typo3/newid/ansi
				 * @see mshop/customer/manager/group/typo3/delete/ansi
				 * @see mshop/customer/manager/group/typo3/search/ansi
				 * @see mshop/customer/manager/group/typo3/count/ansi
				 */
				$path = 'mshop/customer/manager/group/typo3/update';
			}

			$stmt = $this->getCachedStatement( $conn, $path );

			$stmt->bind( 1, $this->pid, \Aimeos\MW\DB\Statement\Base::PARAM_INT );
			$stmt->bind( 2, $item->getCode() );
			$stmt->bind( 3, $item->getLabel() );
			$stmt->bind( 4, time(), \Aimeos\MW\DB\Statement\Base::PARAM_INT ); // mtime

			if( $id !== null ) {
				$stmt->bind( 5, $id, \Aimeos\MW\DB\Statement\Base::PARAM_INT );
				$item->setId( $id );
			} else {
				$stmt->bind( 5, time() ); // ctime
			}

			$stmt->execute()->finish();

			if( $id === null && $fetch === true )
			{
				/** mshop/customer/manager/group/typo3/newid/mysql
				 * Retrieves the ID generated by the database when inserting a new record
				 *
				 * @see mshop/customer/manager/group/typo3/newid/ansi
				 */

				/** mshop/customer/manager/group/typo3/newid/ansi
				 * Retrieves the ID generated by the database when inserting a new record
				 *
				 * As soon as a new record is inserted into the database table,
				 * the database server generates a new and unique identifier for
				 * that record. This ID can be used for retrieving, updating and
				 * deleting that specific record from the table again.
				 *
				 * For MySQL:
				 *  SELECT LAST_INSERT_ID()
				 * For PostgreSQL:
				 *  SELECT currval('seq_mcus_id')
				 * For SQL Server:
				 *  SELECT SCOPE_IDENTITY()
				 * For Oracle:
				 *  SELECT "seq_mcus_id".CURRVAL FROM DUAL
				 *
				 * There's no way to retrive the new ID by a SQL statements that
				 * fits for most database servers as they implement their own
				 * specific way.
				 *
				 * @param string SQL statement for retrieving the last inserted record ID
				 * @since 2015.08
				 * @category Developer
				 * @see mshop/customer/manager/group/typo3/insert/ansi
				 * @see mshop/customer/manager/group/typo3/update/ansi
				 * @see mshop/customer/manager/group/typo3/delete/ansi
				 * @see mshop/customer/manager/group/typo3/search/ansi
				 * @see mshop/customer/manager/group/typo3/count/ansi
				 */
				$path = 'mshop/customer/manager/group/typo3/newid';
				$item->setId( $this->newId( $conn, $path ) );
			}

			$dbm->release( $conn, $dbname );
		}
		catch( \Exception $e )
		{
			$dbm->release( $conn, $dbname );
			throw $e;
		}

		return $item;
	}