protected function buildDomainObject($row) { $order = new order(); $order->setId($row['cart_id']); $order->setTacosId($row['tacos_id']); $order->setTacosName($row['tacos_name']); $order->setNumber($row['cart_number']); $order->setPrice($row['tacos_price'] * $row['cart_number']); return $order; }
/** * Instantiates an order entity and sets its properties using db data. * * @param array $orderData * The array of db data. * * @return \MusicBox\Entity\order */ protected function buildorder($orderData) { $order = new order(); $order->setId($orderData['order_id']); $order->setName($orderData['name']); $order->setShortBiography($orderData['short_biography']); $order->setBiography($orderData['biography']); $order->setSoundCloudUrl($orderData['soundcloud_url']); $order->setImage($orderData['image']); $order->setLikes($orderData['likes']); $createdAt = new \DateTime('@' . $orderData['created_at']); $order->setCreatedAt($createdAt); return $order; }
/** * Save given order * @param order * @param array * @return bool */ public function save(order $order, array $products, array $visited) { // order data $data = $order->__toArray(); $data['at'] = date('Y-m-d H:i:s', time()); $data['delivery_type_id'] = $data['delivery_type']->getId(); unset($data['delivery_type']); $data['payment_type_id'] = $data['payment_type']->getId(); unset($data['payment_type']); $data['status_id'] = $data['status']->getId(); unset($data['status']); // start transaction dibi::begin(); try { $this->insert($data); $order_id = dibi::query('SELECT LAST_INSERT_ID()')->fetchSingle(); $order->setId($order_id); $order->dirty(order::UNDIRT); foreach (mapper::products()->findByIds(array_keys($products)) as $product) { dibi::query('INSERT INTO [:prefix:orders_products]', array('order_id' => $order_id, 'product_id' => $product->getId(), 'price' => $product->getPrice(), 'amount' => $products[$product->getId()])); } foreach ($visited as $_) { $values = array('order_id' => $order_id); $values['product_id'] = $_[0]->getId(); $values['visited_at'] = date('Y-m-d H:i:s', $_[1]); dibi::query('INSERT INTO [:prefix:order_visited_products]', $values); } $mail = new Mail(); $mail->setFrom(Environment::expand('%shopEmail%'))->addTo(Environment::expand('%shopEmail%'))->setSubject(__('New order'))->setBody(__('Hello, new order arrived'))->send(); $mail = new Mail(); $mail->setFrom(Environment::expand('%shopEmail%'))->addTo($data['email'])->setSubject(__('Your order at %s has been accepted', Environment::expand('%shopName%')))->setBody(str_replace('\\n', "\n", __('Hello, your order has been accepted.')))->send(); } catch (Exception $e) { dibi::rollback(); return FALSE; } dibi::commit(); return TRUE; }