1 <?php
2
3 4 5 6 7 8 9 10 11
12
13 MainFactory::load_class('OrderItemAttributeRepositoryWriterInterface');
14
15 16 17 18 19 20 21
22 class OrderItemAttributeRepositoryWriter implements OrderItemAttributeRepositoryWriterInterface
23 {
24 25 26 27
28 protected $db;
29
30 31 32 33
34 protected $table = 'orders_products_attributes';
35
36
37 38 39 40 41
42 public function __construct(CI_DB_query_builder $dbQueryBuilder)
43 {
44 $this->db = $dbQueryBuilder;
45 }
46
47
48 49 50 51 52 53 54 55
56 public function insertIntoOrderItem(IdType $orderItemId, OrderItemAttribute $orderItemAttribute)
57 {
58 $orderItemIdValue = $orderItemId->asInt();
59 $result = $this->db->get_where('orders_products', array('orders_products_id' => $orderItemIdValue))
60 ->row_array();
61
62 $columnValueArray = array(
63 'orders_products_id' => $orderItemIdValue,
64 'orders_id' => $result['orders_id'],
65 'products_options' => $orderItemAttribute->getName(),
66 'products_options_values' => $orderItemAttribute->getValue(),
67 'options_values_price' => $orderItemAttribute->getPrice(),
68 'price_prefix' => $orderItemAttribute->getPriceType(),
69 'options_id' => $orderItemAttribute->getOptionId(),
70 'options_values_id' => $orderItemAttribute->getOptionValueId(),
71 );
72
73 $this->db->insert($this->table, $columnValueArray);
74
75 return $this->db->insert_id();
76 }
77
78
79 80 81 82 83 84 85
86 public function update(StoredOrderItemAttribute $orderItemAttribute)
87 {
88 $columnValueArray = array(
89 'products_options' => $orderItemAttribute->getName(),
90 'products_options_values' => $orderItemAttribute->getValue(),
91 'options_values_price' => $orderItemAttribute->getPrice(),
92 'price_prefix' => $orderItemAttribute->getPriceType(),
93 'options_id' => $orderItemAttribute->getOptionId(),
94 'options_values_id' => $orderItemAttribute->getOptionValueId(),
95 );
96
97 $this->db->update($this->table, $columnValueArray,
98 array('orders_products_attributes_id' => $orderItemAttribute->getOrderItemAttributeId()));
99
100 return $this;
101 }
102 }