Skip to content

Instantly share code, notes, and snippets.

@rsmarshall
Last active August 29, 2015 14:15
Show Gist options
  • Save rsmarshall/65e5202b5bd7a80767cf to your computer and use it in GitHub Desktop.
Save rsmarshall/65e5202b5bd7a80767cf to your computer and use it in GitHub Desktop.
/**
* 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