1 <?php
2
3 4 5 6 7 8 9 10 11
12
13 14 15 16 17 18 19
20 class ProductAttributeRepositoryWriter implements ProductAttributeRepositoryWriterInterface
21 {
22 23 24
25 protected $db;
26
27 28 29
30 protected $tableName = 'products_attributes';
31
32
33 34 35 36 37
38 public function __construct(CI_DB_query_builder $db)
39 {
40 $this->db = $db;
41 }
42
43
44 45 46 47 48 49 50 51 52
53 public function insertIntoProduct(IdType $productId, ProductAttributeInterface $productAttribute)
54 {
55 $dataArray = array(
56 'products_id' => $productId->asInt(),
57 'options_id' => $productAttribute->getOptionId(),
58 'options_values_id' => $productAttribute->getOptionValueId(),
59 'options_values_price' => $productAttribute->getPrice(),
60 'price_prefix' => $productAttribute->getPriceType(),
61 'attributes_model' => $productAttribute->getAttributeModel(),
62 'attributes_stock' => $productAttribute->getStock(),
63 'options_values_weight' => $productAttribute->getWeight(),
64 'weight_prefix' => $productAttribute->getWeightType(),
65 'sortorder' => $productAttribute->getSortOrder(),
66 'products_vpe_id' => $productAttribute->getVpeId(),
67 'gm_vpe_value' => $productAttribute->getVpeValue(),
68 'gm_ean' => $productAttribute->getAttributeEan(),
69 );
70
71 $this->db->insert($this->tableName, $dataArray);
72
73 return $this->db->insert_id();
74 }
75
76
77 78 79 80 81 82 83
84 public function update(StoredProductAttributeInterface $productAttribute)
85 {
86 $dataArray = array(
87 'options_id' => $productAttribute->getOptionId(),
88 'options_values_id' => $productAttribute->getOptionValueId(),
89 'options_values_price' => $productAttribute->getPrice(),
90 'price_prefix' => $productAttribute->getPriceType(),
91 'attributes_model' => $productAttribute->getAttributeModel(),
92 'attributes_stock' => $productAttribute->getStock(),
93 'options_values_weight' => $productAttribute->getWeight(),
94 'weight_prefix' => $productAttribute->getWeightType(),
95 'sortorder' => $productAttribute->getSortOrder(),
96 'products_vpe_id' => $productAttribute->getVpeId(),
97 'gm_vpe_value' => $productAttribute->getVpeValue(),
98 'gm_ean' => $productAttribute->getAttributeEan(),
99 );
100
101 $this->db->update($this->tableName, $dataArray,
102 array('products_attributes_id' => $productAttribute->getAttributeId()));
103
104 return $this;
105 }
106 }