/** * @param array $data */ public function setItemsByData($data) { foreach ($data as $itemData) { $item = new Item(); if (isset($itemData['item'])) { $itemData = array_merge($itemData, $itemData['item']); } // stop if quantity is smaller than 0 if ($this->getProperty('quantity', $itemData, 0) < 1) { continue; } $item->setPrice($this->getProperty('price', $itemData, 0)); $item->setQuantity($this->getProperty('quantity', $itemData)); $item->setQuantityUnit($this->getProperty('quantityUnit', $itemData)); $item->setAddress($this->getProperty('address', $itemData)); $item->setUseProductsPrice($this->getProperty('useProductsPrice', $itemData)); $item->setDeliveryDate($this->getProperty('deliveryDate', $itemData)); $item->setNetShippingCosts($this->getProperty('netShippingCosts', $itemData)); if (isset($itemData['product'])) { $product = new Product($this->getProperty('id', $itemData['product'])); $item->setProduct($product); } // set account to customer if (isset($itemData['account']) && !isset($itemData['customer'])) { $itemData['customer'] = $itemData['account']; } if (isset($itemData['customer'])) { $customer = new Account($this->getProperty('id', $itemData['customer']), $this->getProperty('name', $itemData['customer'])); $item->setCustomerAccount($customer); } if (isset($itemData['supplier'])) { $customer = new Account($this->getProperty('id', $itemData['supplier']), $this->getProperty('name', $itemData['supplier'])); $item->setSupplierAccount($customer); } // add to items array $this->items[] = $item; // create ordered item arrays $customerId = 0; $supplierId = 0; if ($item->getCustomerAccount()) { $customerId = $item->getCustomerAccount()->getId(); } if ($item->getSupplierAccount()) { $supplierId = $item->getSupplierAccount()->getId(); } $this->customerItems[$customerId][] = $item; $this->customerSupplierItems[$customerId]['supplierItems'][$supplierId][] = $item; } }