本文整理汇总了PHP中Order::addItem方法的典型用法代码示例。如果您正苦于以下问题:PHP Order::addItem方法的具体用法?PHP Order::addItem怎么用?PHP Order::addItem使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Order
的用法示例。
在下文中一共展示了Order::addItem方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getMyOrder
/**
* @param string $drinkName
* @param string $plateName
* @return Order
*/
public function getMyOrder($drinkName, $plateName)
{
$chefCook = new ChefCook();
$dinner = $chefCook->makeDinner($plateName);
$barMan = new BarMan();
$drink = $barMan->makeDrink($drinkName);
$order = new Order();
$order->addItem($drink);
$order->addItem($dinner);
return $order;
}
示例2: generateItems
private function generateItems(Order $order)
{
$numOfItems = rand(1, 3);
$productsTaken = [];
while (count($productsTaken) < $numOfItems) {
$product = $this->productList->getRandomProduct();
if (in_array($product, $productsTaken)) {
continue;
}
$quantity = rand(1, 5);
$order->addItem($product, $quantity);
$productsTaken[] = $product;
}
}
示例3: execute
/**
*
* @param integer $orderId
* @param string $itemTitle
* @param integer $quantity
* @param integer $paidAmount
* @param integer $shippingAmount
* @throws \Exception
*/
public function execute($orderId, $itemTitle, $quantity, $paidAmount, $shippingAmount)
{
$stmt = $this->db->query("SELECT * FROM orders WHERE id = :orderId");
$stmt->bindValue(':orderId', $orderId, \PDO::PARAM_INT);
$stmt->execute();
$orderRow = $stmt->fetch(\PDO::FETCH_ASSOC);
if ($orderRow == NULL) {
throw new \Exception(sprintf("Order with id %d doesn't exists", $orderId));
}
$order = new Order((int) $orderRow['id'], $orderRow['pickup_address'], $orderRow['shipping_address'], (int) $orderRow['paid_amount'], (int) $orderRow['shipping_amount']);
$stmt = $this->db->query("SELECT * FROM order_items WHERE order_id = :orderId");
$stmt->bindValue(':orderId', $orderId, \PDO::PARAM_INT);
$stmt->execute();
$orderItemRows = $stmt->fetchAll(\PDO::FETCH_ASSOC);
foreach ($orderItemRows as $row) {
$order->addItem(new OrderItem((int) $row['id'], (int) $row['order_id'], $row['item_title'], (int) $row['quantity'], (int) $orderRow['paid_amount'], (int) $orderRow['shipping_amount']));
}
$orderItem = new OrderItem(NULL, $orderId, $itemTitle, $quantity, $paidAmount, $shippingAmount);
$insert = "INSERT INTO order_items (id, order_id, item_title, quantity, paid_amount, shipping_amount) \n VALUES (:id, :orderId, :itemTitle, :quantity, :paidAmount, :shippingAmount)";
$stmt = $this->db->prepare($insert);
$stmt->bindValue(':id', NULL, \PDO::PARAM_NULL);
$stmt->bindValue(':orderId', $orderId, \PDO::PARAM_INT);
$stmt->bindValue(':itemTitle', $itemTitle, \PDO::PARAM_STR);
$stmt->bindValue(':quantity', $quantity, \PDO::PARAM_STR);
$stmt->bindValue(':paidAmount', $paidAmount, \PDO::PARAM_INT);
$stmt->bindValue(':shippingAmount', $shippingAmount, \PDO::PARAM_INT);
$stmt->execute();
$order->addItem($orderItem);
$order->setPaidAmount($order->getPaidAmount() + $orderItem->getPaidAmount());
$order->setShippingAmount($order->getShippingAmount() + $orderItem->getShippingAmount());
$update = "UPDATE orders SET paid_amount = :paidAmount, shipping_amount = :shippingAmount\n WHERE id = :orderId";
$stmt = $this->db->prepare($update);
$stmt->bindValue(':orderId', $orderId, \PDO::PARAM_INT);
$stmt->bindValue(':paidAmount', $order->getPaidAmount(), \PDO::PARAM_INT);
$stmt->bindValue(':shippingAmount', $order->getShippingAmount(), \PDO::PARAM_INT);
$stmt->execute();
}
示例4: __construct
/**
* @param ItemDao $item_dao
* @return void
**/
public function __construct(ItemDao $item_dao)
{
$fp = fopen(ROOT . '/data/AbstractFactory/order.csv', 'r');
while ($data = fgetcsv($fp, 1000, ',')) {
$order = new Order();
$order->setId($data[0]);
foreach (explode(',', $data[1]) as $item_id) {
$item = $item_dao->findById($item_id);
if (!is_null($item)) {
$order->addItem($item);
}
}
$this->orders[$order->getId()] = $order;
}
}
示例5: order
*/
class OrderManager
{
public static function order(Order $order)
{
$item_dao = ItemDao::getInstance();
//1.ItemDaoインスタンスを取得し、
foreach ($order->getItems() as $order_item) {
//2.在庫を引き当て、
$item_dao->setAside($order_item);
}
OrderDao::createOrder($order);
//3.注文結果を表示する
}
}
/*
* Client
*/
/* TODO
* 以下5行、クライアント側にコードが記述されてしまっている!
* 以下のようにすると良いかも。
* 1.OrderクラスやItemDaoクラスの使用箇所は、Facadeにまとめる。
* 2.クライアント側からは、汎用的なデータ(配列など)を注文情報として渡すようにする。
*/
$order = new Order();
$item_dao = ItemDao::getInstance();
$order->addItem(new OrderItem($item_dao->findById(1), 2));
$order->addItem(new OrderItem($item_dao->findById(2), 1));
$order->addItem(new OrderItem($item_dao->findById(3), 3));
//注文処理は、この1行に隠蔽される
OrderManager::order($order);
示例6: findById
public function findById($order_id)
{
$order = new Order('999');
$order->addItem(new Item('99', 'ダミー商品'));
$order->addItem(new Item('99', 'ダミー商品'));
$order->addItem(new Item('98', 'テスト商品'));
return $order;
}
示例7: create
public static function create($data)
{
$order = new Order();
if ($data) {
$order->user_id = $data->user_id ? $data->user_id : $order->user_id;
$order->date = $data->date ? $data->date : $order->date;
$order->downpayment = $data->downpayment ? $data->downpayment : $order->downpayment;
$order->date_paid = $data->date_paid ? $data->date_paid : $order->date_paid;
$order->date_claimed = $data->date_claimed ? $data->date_claimed : $order->date_claimed;
$order->due = $data->due ? $data->due : $order->due;
$order->save();
if ($data->items) {
foreach ($data->items as $itemdata) {
$item = $order->addItem();
$item->product = $itemdata->id;
$item->price = $itemdata->price;
$item->quantity = $itemdata->quantity;
$item->save();
}
}
return $order;
}
throw new Exception("{$data} must not be empty", 1);
}