Creates new and updates existing items using the data array

@param \Aimeos\MShop\Order\Item\Base\Iface $order Order base item object
@param array $data Data array
429767
protected function fromArray( \Aimeos\MShop\Order\Item\Base\Iface $order, array $data )
	{
		$invoiceIds = $this->getValue( $data, 'order.id', [] );
		$manager = \Aimeos\MShop::create( $this->getContext(), 'order' );

		$search = $manager->createSearch()->setSlice( 0, count( $invoiceIds ) );
		$search->setConditions( $search->compare( '==', 'order.id', $invoiceIds ) );

		$items = $manager->searchItems( $search );


		foreach( $invoiceIds as $idx => $id )
		{
			if( !isset( $items[$id] ) ) {
				$item = $manager->createItem();
			} else {
				$item = $items[$id];
			}

			if( isset( $data['order.statusdelivery'][$idx] ) ) {
				$item->setDeliveryStatus( $data['order.statusdelivery'][$idx] );
			}

			if( isset( $data['order.statuspayment'][$idx] ) ) {
				$item->setPaymentStatus( $data['order.statuspayment'][$idx] );
			}

			if( isset( $data['order.datedelivery'][$idx] ) ) {
				$item->setDateDelivery( $data['order.datedelivery'][$idx] );
			}

			if( isset( $data['order.datepayment'][$idx] ) ) {
				$item->setDatePayment( $data['order.datepayment'][$idx] );
			}

			if( isset( $data['order.relatedid'][$idx] ) ) {
				$item->setRelatedId( $data['order.relatedid'][$idx] );
			}

			if( isset( $data['order.type'][$idx] ) ) {
				$item->setType( $data['order.type'][$idx] );
			}

			$item->setBaseId( $order->getId() );

			$manager->saveItem( $item );
		}
	}
100282
protected function fromArray( \Aimeos\MShop\Attribute\Item\Iface $item, array $data )
	{
		$propManager = \Aimeos\MShop::create( $this->getContext(), 'media/property' );
		$index = 0;

		foreach( $item->getRefItems( 'media', null, null, false ) as $refItem )
		{
			$propItems = $refItem->getPropertyItems( null, false );

			foreach( (array) $this->getValue( $data, $index . '/property', [] ) as $entry )
			{
				if( isset( $propItems[$entry['media.property.id']] ) )
				{
					$propItem = $propItems[$entry['media.property.id']];
					unset( $propItems[$entry['media.property.id']] );
				}
				else
				{
					$propItem = $propManager->createItem();
				}

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

			$refItem->deletePropertyItems( $propItems );
			$index++;
		}

		return $item;
	}
904303
protected function toArray( \Aimeos\MShop\Order\Item\Base\Iface $item, $copy = false )
	{
		$siteId = $this->getContext()->getLocale()->getSiteId();
		$data = $item->toArray( true );

		if( $item->getCustomerId() != '' )
		{
			$manager = \Aimeos\MShop::create( $this->getContext(), 'customer' );

			try {
				$data += $manager->getItem( $item->getCustomerId() )->toArray();
			} catch( \Exception $e ) {};
		}


		if( $copy === true )
		{
			$data['order.base.siteid'] = $siteId;
			$data['order.base.id'] = '';
		}

		foreach( $item->getAddresses() as $type => $addresses )
		{
			foreach( $addresses as $pos => $addrItem )
			{
				$list = $addrItem->toArray( true );

				foreach( $list as $key => $value ) {
					$data['address'][$type][$pos][$key] = $value;
				}

				if( $copy === true )
				{
					$data['address'][$type][$pos]['order.base.address.siteid'] = $siteId;
					$data['address'][$type][$pos]['order.base.address.id'] = '';
				}
			}
		}

		if( $copy !== true )
		{
			foreach( $item->getServices() as $type => $services )
			{
				foreach( $services as $serviceItem )
				{
					$serviceId = $serviceItem->getServiceId();

					foreach( $serviceItem->getAttributeItems() as $attrItem )
					{
						foreach( $attrItem->toArray( true ) as $key => $value ) {
							$data['service'][$type][$serviceId][$key][] = $value;
						}
					}
				}
			}
		}

		foreach( $item->getProducts() as $pos => $productItem ) {
			$data['product'][$pos]['order.base.product.status'] = $productItem->getStatus();
		}

		return $data;
	}
362516
protected function fromArray( \Aimeos\MShop\Product\Item\Iface $item, array $data )
	{
		$context = $this->getContext();
		$fs = $context->getFilesystemManager()->get( 'fs-secure' );

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

		$attrItem = $attrManager->createItem()->setType( 'download' );
		$listItem = $listManager->createItem()->setType( 'hidden' );
		$listItems = $item->getListItems( 'attribute', 'hidden', 'download', false );

		if( $this->getValue( $data, 'attribute.label' ) != '' )
		{
			$listId = $this->getValue( $data, 'product.lists.id' );

			if( isset( $listItems[$listId] ) ) {
				$litem = $listItems[$listId]; unset( $listItems[$listId] );
			} else {
				$litem = clone $listItem;
			}

			if( ( $refItem = $litem->getRefItem() ) === null ) {
				$refItem = clone $attrItem;
			}

			$litem->fromArray( $data, true );
			$refItem->fromArray( $data, true );

			if( ( $file = $this->getValue( (array) $this->getView()->request()->getUploadedFiles(), 'download/file' ) ) !== null
				&& $file->getError() === UPLOAD_ERR_OK
			) {
				$path = ( $this->getValue( $data, 'overwrite' ) == 1 ? $refItem->getCode() : null );
				$refItem->setCode( $this->storeFile( $file, $path ) );
			}

			$item->addListItem( 'attribute', $litem, $refItem );
		}

		foreach( $listItems as $listItem )
		{
			$refItem = $listItem->getRefItem();

			if( $refItem !== null && ( $path = $refItem->getCode() ) != '' && $fs->has( $path ) ) {
				$fs->rm( $path );
			}

			$item->deleteListItem( 'attribute', $listItem, $refItem );
		}
	}
154609
public function onCallbackSuccess($order, $data = null)
    {
        try {

            $response = $this->omnipay->completePurchase([
                'transactionId'    => $order->transactionId,
            ])->send();

            if ($response->isSuccessful()) {

                $this->statusCode = 'completed';

                $this->transactionId = $this->omnipay->getTransactionId();

                $this->detail = 'Success';

            } else {

                throw new GatewayException($response->getMessage(), 1);

            }

        } catch (\Exception $e) {

            throw new GatewayException(
                $e->getMessage(),
                1000,
                $e
            );

        }
    }
509144
final public function orderBy(string $orderBy, string $order = 'ASC')
    {        
       $this->query->addOrderBy($orderBy, $order);

        return $this;
    }
504235
protected function fromArray( \Aimeos\MShop\Supplier\Item\Iface $item, array $data )
	{
		$manager = \Aimeos\MShop::create( $this->getContext(), 'supplier/address' );

		$addrItems = $item->getAddressItems();

		foreach( $data as $entry )
		{
			if( isset( $addrItems[$entry['supplier.address.id']] ) )
			{
				$addrItem = $addrItems[$entry['supplier.address.id']];
				unset( $addrItems[$entry['supplier.address.id']] );
			}
			else
			{
				$addrItem = $manager->createItem();
			}

			$addrItem->fromArray( $entry, true );
			$item->addAddressItem( $addrItem );
		}

		$item->deleteAddressItems( $addrItems );
	}
68558
protected function fromArray( \Aimeos\MShop\Product\Item\Iface $item, array $data )
	{
		$context = $this->getContext();
		$manager = \Aimeos\MShop::create( $context, 'product' );
		$listManager = \Aimeos\MShop::create( $context, 'product/lists' );

		$prodItem = $manager->createItem()->setType( 'default' );
		$listItem = $listManager->createItem()->setType( 'default' );
		$articles = $item->getRefItems( 'product', null, 'default', false );
		$listItems = $item->getListItems( 'product', 'default', null, false );

		foreach( $data as $idx => $entry )
		{
			if( ( $litem = $item->getListItem( 'product', 'default', $entry['product.id'], false ) ) === null ) {
				$litem = clone $listItem;
			}

			if( isset( $articles[$litem->getRefId()] ) ) {
				$refItem = $articles[$litem->getRefId()];
			} else {
				$refItem = clone $prodItem;
			}

			$litem->fromArray( $entry, true );
			$litem->setPosition( $idx );

			$refItem->fromArray( $entry, true );

			if( isset( $entry['attr'] ) ) {
				$refItem = $this->fromArrayAttributes( $refItem, $entry['attr'] );
			}

			$item->addListItem( 'product', $litem, $refItem );
			unset( $listItems[$litem->getId()] );
		}

		return $item->deleteListItems( $listItems );
	}
104749
protected function fromArray( \Aimeos\MShop\Product\Item\Iface $item, array $data )
	{
		$manager = \Aimeos\MShop::create( $this->getContext(), 'catalog/lists' );
		$listIds = (array) $this->getValue( $data, 'catalog.lists.id', [] );
		$listItems = $map = $this->getListItems( $item->getId() );


		foreach( $listIds as $idx => $listid )
		{
			if( isset( $map[$listid] ) ) {
				unset( $map[$listid] );
			}
		}

		$manager->deleteItems( array_keys( $map ) );


		foreach( $listIds as $idx => $listid )
		{
			if( isset( $listItems[$listid] ) ) {
				$litem = $listItems[$listid];
			} else {
				$litem = $manager->createItem();
			}

			$litem->setDomain( 'product' );
			$litem->setRefId( $item->getId() );
			$litem->setParentId( $this->getValue( $data, 'catalog.id/' . $idx ) );
			$litem->setType( $this->getValue( $data, 'catalog.lists.type/' . $idx ) );

			$manager->saveItem( $litem, false );
		}
	}
155403
public function orderItems(Order $order)
    {
        return response()->json([
            'errors' => false,
            'data' => $order->items->map(function($item) {
                $item->product->load('options');
                return $item;
            }),
        ]);
    }
201826
public function orderBy($sort, $order = null)
    {
        return $this->add('orderBy', $sort . ' ' . (! $order ? 'ASC' : $order), false);
    }
1033226
public function add(array $order)
    {
        $result = null;
        $this->hook->attach('order.add.before', $order, $result, $this);

        if (isset($result)) {
            return (int) $result;
        }

        unset($order['order_id']); // In case the order is cloning
        $order['created'] = $order['modified'] = GC_TIME;
        $order += array('status' => $this->getDefaultStatus());

        $this->prepareComponents($order);

        $result = $this->db->insert('orders', $order);
        $this->hook->attach('order.add.after', $order, $result, $this);
        return (int) $result;
    }
1371487
public static function create($order)
    {
        $data = OpenPayU_Util::buildJsonFromArray($order);

        if (empty($data)) {
            throw new OpenPayU_Exception('Empty message OrderCreateRequest');
        }

        try {
            $authType = self::getAuth();
        } catch (OpenPayU_Exception $e) {
            throw new OpenPayU_Exception($e->getMessage(), $e->getCode());
        }

        $pathUrl = OpenPayU_Configuration::getServiceUrl() . self::ORDER_SERVICE;

        $result = self::verifyResponse(OpenPayU_Http::doPost($pathUrl, $data, $authType), 'OrderCreateResponse');

        return $result;
    }
39218
public function Order( $data )
	{
		Deprecation::getInstance()->setExceptionVersion( '0.9' )
			->message(  'Use orderBy instad' );
		if( !is_array( $data ) )
			throw new InvalidArgumentException( 'Orders must be given as List of Column and Direction.' );
		$column		= $data[0];
		$direction	= strtoupper( $data[1] );
		$this->builder->addOrder( $column, $direction );
		return array();
	}
218068
public function addOrders( $orders )
	{
		if( !is_array( $orders ) )
			throw new InvalidArgumentException( 'An Array should be given.' );
		foreach( $orders as $column => $direction )
			$this->addOrder( $column, $direction );
	}
239517
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' );
		$typeManager = \Aimeos\MShop::create( $context, 'product/lists/type' );

		$attrId = $attrManager->findItem( 'custom', [], 'product', 'price' )->getId();

		if( $this->getValue( $data, 'custom', 0 ) == 1 )
		{
			if( $item->getListItem( 'attribute', 'custom', $attrId, false ) === null )
			{
				$listItem = $listManager->createItem()->setType( 'custom' )->setRefId( $attrId );
				$item->addListItem( 'attribute', $listItem, $listItem->getRefItem() );
			}
		}
		else
		{
			if( ( $litem = $item->getListItem( 'attribute', 'custom', $attrId, false ) ) !== null ) {
				$item->deleteListItem( 'attribute', $litem );
			}
		}
	}
191618
public function onCallbackSuccess($order, $data = null)
    {
        $paymentId  = is_array($data) ? $data['paymentId'] : $data->paymentId;

        $payerId    = is_array($data) ? $data['PayerID'] : $data->PayerID;

        $this->statusCode = 'failed';

        $this->detail = sprintf('Payment failed. Ref: %s', $paymentId);

        // Begin paypal
        try {

            $this->setContext();

            $payment = Payment::get($paymentId, $this->apiContext);
            
            $execution = new PaymentExecution();

            $execution->setPayerId($payerId);

            $payment->execute($execution, $this->apiContext);

            $payment = Payment::get($paymentId, $this->apiContext);

            $this->statusCode = 'completed';

            $this->transactionId = $payment->id;

            $this->detail = 'Success';

        } catch (PayPalConnectionException $e) {

            $response = json_decode($e->getData());

            throw new GatewayException(
                sprintf(
                    '%s: %s',
                    $response->name,
                    isset($response->message) ? $response->message : 'Paypal payment Failed.'
                ),
                1001,
                $e
            );

        } catch (\Exception $e) {

            throw new GatewayException(
                $e->getMessage(),
                1000,
                $e
            );

        }
    }