Create new product item object initialized with given parameters.

@param MShop_Product_Item_Interface $item Product item object
@return array Associative list of key/value pairs suitable for product item constructor
18196
protected function _createArray( MShop_Product_Item_Interface $item )
	{
		return array(
			'id' => $item->getId(),
			'typeid' => $item->getTypeId(),
			'type' => $item->getType(),
			'status' => $item->getStatus(),
			'label' => $item->getLabel(),
			'start' => $item->getDateStart(),
			'end' => $item->getDateEnd(),
			'code' => $item->getCode(),
			'suppliercode' => $item->getSupplierCode(),
			'ctime' => $item->getTimeCreated(),
			'mtime' => $item->getTimeModified(),
			'editor' => $item->getEditor(),
		);
	}
839143
protected function _buildItemClasses($item)
    {
        $cls = [
            $this->config('itemClass')
        ];

        if ($this->_isActive($item)) {
            $cls[] = $this->config('itemActiveClass');
        }

        if ($this->_isOpen($item)) {
            $cls[] = $this->config('itemOpenClass');
        }

        return $cls;
    }
1245900
public function saveItem( MShop_Common_Item_Interface $item, $fetch = true )
	{
		$iface = 'MShop_Service_Item_Interface';
		if ( !( $item instanceof $iface ) ) {
			throw new MShop_Service_Exception(sprintf('Object is not of required type "%1$s"', $iface));
		}

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

		$context = $this->_getContext();

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

		try
		{
			$id = $item->getId();
			$date = date( 'Y-m-d H:i:s' );

			if( $id === null )
			{
				/** mshop/service/manager/default/item/insert
				 * Inserts a new service 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 service 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 2014.03
				 * @category Developer
				 * @see mshop/service/manager/default/item/update
				 * @see mshop/service/manager/default/item/newid
				 * @see mshop/service/manager/default/item/delete
				 * @see mshop/service/manager/default/item/search
				 * @see mshop/service/manager/default/item/count
				 */
				$path = 'mshop/service/manager/default/item/insert';
			}
			else
			{
				/** mshop/service/manager/default/item/update
				 * Updates an existing service 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 service 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 2014.03
				 * @category Developer
				 * @see mshop/service/manager/default/item/insert
				 * @see mshop/service/manager/default/item/newid
				 * @see mshop/service/manager/default/item/delete
				 * @see mshop/service/manager/default/item/search
				 * @see mshop/service/manager/default/item/count
				 */
				$path = 'mshop/service/manager/default/item/update';
			}

			$stmt = $this->_getCachedStatement( $conn, $path );
			$stmt->bind( 1, $context->getLocale()->getSiteId(), MW_DB_Statement_Abstract::PARAM_INT );
			$stmt->bind( 2, $item->getPosition(), MW_DB_Statement_Abstract::PARAM_INT );
			$stmt->bind( 3, $item->getTypeId() );
			$stmt->bind( 4, $item->getCode() );
			$stmt->bind( 5, $item->getLabel() );
			$stmt->bind( 6, $item->getProvider() );
			$stmt->bind( 7, json_encode( $item->getConfig() ) );
			$stmt->bind( 8, $item->getStatus(), MW_DB_Statement_Abstract::PARAM_INT );
			$stmt->bind( 9, $date ); // mtime
			$stmt->bind( 10, $context->getEditor() );

			if ( $id !== null ) {
				$stmt->bind( 11, $id, MW_DB_Statement_Abstract::PARAM_INT );
				$item->setId( $id );
			} else {
				$stmt->bind( 11, $date ); // ctime
			}

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

			if( $id === null && $fetch === true )
			{
				/** mshop/service/manager/default/item/newid
				 * 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_mser_id')
				 * For SQL Server:
				 *  SELECT SCOPE_IDENTITY()
				 * For Oracle:
				 *  SELECT "seq_mser_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 2014.03
				 * @category Developer
				 * @see mshop/service/manager/default/item/insert
				 * @see mshop/service/manager/default/item/update
				 * @see mshop/service/manager/default/item/delete
				 * @see mshop/service/manager/default/item/search
				 * @see mshop/service/manager/default/item/count
				 */
				$path = 'mshop/service/manager/default/item/newid';
				$item->setId( $this->_newId($conn, $context->getConfig()->get( $path, $path ) ) );
			}

			$dbm->release( $conn, $dbname );
		}
		catch ( Exception $e )
		{
			$dbm->release( $conn, $dbname );
			throw $e;
		}
	}
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 );
	}
585688
public function addItem($item)
	{
		if( ! $item instanceof Model )
		{
			$item = new $this->defaultModel($item);
		}

		$this->data[] = $item;
	}
1203192
protected function prepareItem(array $item, array $data)
    {
        $product = $this->product->getBySku($item['sku'], $item['store_id']);

        if (empty($product['status']) || $data['store_id'] != $product['store_id']) {
            return array();
        }

        $product['price'] = $this->currency->convert($product['price'], $product['currency'], $data['currency']);

        $calculated = $this->product->calculate($product);

        if ($calculated != $product['price']) {
            $item['original_price'] = $product['price'];
        }

        $item['product'] = $product;
        $item['price'] = $calculated;
        $item['total'] = $item['price'] * $item['quantity'];

        return $item;
    }
1269428
public function saveItem( MShop_Common_Item_Interface $item, $fetch = true )
	{
		$iface = 'MShop_Media_Item_Interface';
		if( !( $item instanceof $iface ) ) {
			throw new MShop_Media_Exception( sprintf( 'Object is not of required type "%1$s"', $iface ) );
		}

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

		$context = $this->_getContext();

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

		try
		{
			$id = $item->getId();
			$date = date( 'Y-m-d H:i:s' );

			if( $id === null )
			{
				/** mshop/media/manager/default/item/insert
				 * Inserts a new media 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 media 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 2014.03
				 * @category Developer
				 * @see mshop/media/manager/default/item/update
				 * @see mshop/media/manager/default/item/newid
				 * @see mshop/media/manager/default/item/delete
				 * @see mshop/media/manager/default/item/search
				 * @see mshop/media/manager/default/item/count
				 */
				$path = 'mshop/media/manager/default/item/insert';
			}
			else
			{
				/** mshop/media/manager/default/item/update
				 * Updates an existing media 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 media 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 2014.03
				 * @category Developer
				 * @see mshop/media/manager/default/item/insert
				 * @see mshop/media/manager/default/item/newid
				 * @see mshop/media/manager/default/item/delete
				 * @see mshop/media/manager/default/item/search
				 * @see mshop/media/manager/default/item/count
				 */
				$path = 'mshop/media/manager/default/item/update';
			}

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

			$stmt->bind( 1, $context->getLocale()->getSiteId(), MW_DB_Statement_Abstract::PARAM_INT );
			$stmt->bind( 2, $item->getLanguageId() );
			$stmt->bind( 3, $item->getTypeId(), MW_DB_Statement_Abstract::PARAM_INT );
			$stmt->bind( 4, $item->getLabel() );
			$stmt->bind( 5, $item->getMimeType() );
			$stmt->bind( 6, $item->getUrl() );
			$stmt->bind( 7, $item->getStatus(), MW_DB_Statement_Abstract::PARAM_INT );
			$stmt->bind( 8, $item->getDomain());
			$stmt->bind( 9, $item->getPreview() );
			$stmt->bind( 10, $date ); // mtime
			$stmt->bind( 11, $context->getEditor() );

			if( $id !== null ) {
				$stmt->bind( 12, $id, MW_DB_Statement_Abstract::PARAM_INT);
				$item->setId( $id ); //is not modified anymore
			} else {
				$stmt->bind( 12, $date ); // ctime
			}

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

			if( $id === null && $fetch === true )
			{
				/** mshop/media/manager/default/item/newid
				 * 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_mmed_id')
				 * For SQL Server:
				 *  SELECT SCOPE_IDENTITY()
				 * For Oracle:
				 *  SELECT "seq_mmed_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 2014.03
				 * @category Developer
				 * @see mshop/media/manager/default/item/insert
				 * @see mshop/media/manager/default/item/update
				 * @see mshop/media/manager/default/item/delete
				 * @see mshop/media/manager/default/item/search
				 * @see mshop/media/manager/default/item/count
				 */
				$path = 'mshop/media/manager/default/item/newid';
				$item->setId( $this->_newId( $conn, $context->getConfig()->get( $path, $path ) ) );
			}

			$dbm->release( $conn, $dbname );
		}
		catch( Exception $e )
		{
			$dbm->release( $conn, $dbname );
			throw $e;
		}
	}
1268764
public function addItem(Item $item)
    {
        $this->items->put($item->getName(), $item);

        return $this;
    }
959157
protected function getItemLineOrder($item)
    {
        $result = array();

        $this->addPropertySource('item', $item);

        $this->addProductInfo($result);

        // For higher precision of the unit price, we will recalculate the price
        // ex vat if product prices are entered inc vat by the admin.
        $productPriceEx = (float) $item->getBasePrice();
        $productPriceInc = (float) $item->getBasePriceInclTax();

        // Check for cost price and margin scheme.
        if (!empty($line['costPrice']) && $this->allowMarginScheme()) {
            // Margin scheme:
            // - Do not put VAT on invoice: send price incl VAT as unitprice.
            // - But still send the VAT rate to Acumulus.
            $result[Tag::UnitPrice] = $productPriceInc;
        } else {
            $result += array(
                Tag::UnitPrice => $productPriceEx,
                Meta::UnitPriceInc => $productPriceInc,
                Meta::RecalculatePrice => $this->productPricesIncludeTax() ? Tag::UnitPrice : Meta::UnitPriceInc,
            );
        }
        $result[Tag::Quantity] = $item->getQtyOrdered();

        // Tax amount = VAT over discounted product price.
        // Hidden tax amount = VAT over discount.
        // Tax percent = VAT % as specified in product settings, for the parent
        // of bundled products this may be 0 and incorrect.
        // But as discounts get their own lines and the product lines are
        // showing the normal (not discounted) price we add these 2.
        $vatRate = (float) $item->getTaxPercent();
        $lineVat = (float) $item->getBaseTaxAmount() + (float) $item->getBaseDiscountTaxCompensationAmount();

        // Add VAT related info.
        $childrenItems = $item->getChildrenItems();
        if (Number::isZero($vatRate) && !empty($childrenItems)) {
            // 0 VAT rate on parent: this is (very very) probably not correct.
            $result += array(
                Tag::VatRate => null,
                Meta::VatRateSource => Creator::VatRateSource_Completor,
                Meta::VatRateLookup => $vatRate,
                Meta::VatRateLookupSource => '$item->getTaxPercent()',
            );
        } else {
            // No 0 VAT or not a parent product: the vat rate is real.
            $result += array(
                Tag::VatRate => $vatRate,
                Meta::VatRateSource => Number::isZero($vatRate) ? Creator::VatRateSource_Exact0 : Creator::VatRateSource_Exact,
            );
        }
        $result += array(
            Meta::LineVatAmount => $lineVat,
        );

        // Add vat meta data.
        $product = $item->getProduct();
        if ($product) {
            /** @noinspection PhpUndefinedMethodInspection */
            $result += $this->getVatClassMetaData((int) $product->getTaxClassId());
        }

        // Add discount related info.
        if (!Number::isZero($item->getBaseDiscountAmount())) {
            // Store discount on this item to be able to get correct discount
            // lines later on in the completion phase.
            $result[Meta::LineDiscountAmountInc] = -$item->getBaseDiscountAmount();
        }

        // Add children lines for composed products.
        if (!empty($childrenItems)) {
            $result[Meta::ChildrenLines] = array();
            foreach ($childrenItems as $child) {
                $result[Meta::ChildrenLines][] = $this->getItemLineOrder($child);
            }
        }

        $this->removePropertySource('item');

        return $result;
    }
765728
protected function setItemSupplier(ApiItemInterface $item, ProductInterface $product)
    {
        $supplier = null;
        $supplierName = '';
        // Get products supplier.
        if ($product->getSupplier()) {
            $supplier = $product->getSupplier();
            $supplierName = $product->getSupplier()->getName();
        }
        $item->setSupplier($supplier);
        $item->setSupplierName($supplierName);
    }
1183231
public function add($item)
    {
        foreach ($this->_requiredInterfaces as $interface) {
            if (!$item instanceof $interface) {
                throw new RuntimeException(
                    sprintf('Item "%s" should implement "%s" interface', get_class($item), $interface)
                );
            }
        }
        
        $this->_items[spl_object_hash($item)] = $item;
        return $this;
    }
1271150
protected function prepareCartItem(array &$item)
    {
        $this->setItemImages($item['product'], 'product', $this->image);
        $this->setItemThumbCart($item, $this->image);
        $this->setItemPriceFormatted($item, $this->price, $this->current_currency);
        $this->setItemTotalFormatted($item, $this->price);
        $this->setItemProductBundle($item['product'], $this->product, $this->image);
    }
1069133
public function addItem($item)
    {
        if (!isset($this->_items)) {
            $this->_items = [];
        }
        if (!is_array($item)) {
            $item = [];
        }
        if (!isset($item['class'])) {
            $item['class'] = $this->itemClass;
        }
        $item = Yii::createObject($item);
        $this->_items[$item->id] = $item;

        return $item;
    }
966024
public function itemCreate(Item $item)
    {
        $response = $this->getGuzzleClient()
            ->post(
                '/items',
                array_merge($this->setQuery(), $this->setBody($item))
            );

        return $this->serializer->deserialize(
            $response->getBody()->getContents(),
            Item::class,
            'json'
        );
    }
698803
protected function validateIfItemProductActive(ItemInterface $item)
    {
        $product = $item->getProduct();

        if (!$product) {
            throw new ProductNotFoundException('item ' . $item->getId());
        }

        if ($product->getStatus()->getId() !== Status::ACTIVE) {
            throw new ProductNotActiveException($product->getId());
        }

        return true;
    }
447205
protected function _getItem( MShop_Coupon_Item_Code_Interface $item, array $row )
	{
		foreach( $row as $idx => $value ) {
			$row[$idx] = trim( $value );
		}

		$count = ( isset( $row[1] ) && $row[1] != '' ? $row[1] : 1 );
		$start = ( isset( $row[2] ) && $row[2] != '' ? $row[2] : null );
		$end = ( isset( $row[3] ) && $row[3] != '' ? $row[3] : null );

		$item->setId( null );
		$item->setCode( $row[0] );
		$item->setCount( $count );
		$item->setDateStart( $start );
		$item->setDateEnd( $end );

		return $item;
	}
170253
public function copyFrom( MShop_Product_Item_Interface $product )
	{
		$this->setName( $product->getName() );
		$this->setType( $product->getType() );
		$this->setSupplierCode( $product->getSupplierCode() );
		$this->setProductCode( $product->getCode() );
		$this->setProductId( $product->getId() );

		$items = $product->getRefItems( 'media', 'default', 'default' );
		if( ( $item = reset( $items ) ) !== false ) {
			$this->setMediaUrl( $item->getUrl() );
		}

		$this->setModified();
	}