Last active
August 29, 2015 14:15
-
-
Save rsmarshall/65e5202b5bd7a80767cf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Add multiple items (used for opticon app upload) | |
* | |
* @param array $data | |
* @return array $feedback | |
*/ | |
public function addMultipleItems($data) | |
{ | |
$branchId = $this->_customer->getBranchId(); | |
$trolleyId = $this->_trolleyRepository->findIdByCustomerId($this->_customer->getId()); | |
$feedback = array(); | |
$items = array(); | |
foreach ($data as $item) { | |
$feedback[$item->Barcode] = 'Product not found'; | |
if (array_key_exists($item->Barcode, $items)) { | |
$items[$item->Barcode]['quantity']++; | |
continue; | |
} | |
if ($product = $this->_productRepository->findProductByBarcodeApp($item->Barcode, $branchId)) { | |
foreach ($product->getPacks() as $pack) { | |
foreach ($pack->getBarcodes() as $barcode) { | |
if ($barcode->getBarcode() == $item->Barcode) { | |
$items[$item->Barcode] = array( | |
'packId' => $pack->getId(), | |
'quantity' => 1, | |
'price' => $pack->getPrice($this->_customer), | |
'trolleyId' => $trolleyId, | |
); | |
$feedback[$item->Barcode] = $product->getName(); | |
} | |
} | |
} | |
} | |
} | |
$this->_trolleyRepository->addFromApp($items); | |
return $feedback; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment