1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?php
class Product extends AppModel
{
var $validate = array(
"shop_id" => VALID_NUMBER,
"category_id" => VALID_NUMBER,
"logo_visibility" => VALID_NOT_EMPTY,
"name" => VALID_NOT_EMPTY,
'code' => array(
'unique' => array(
'rule' => 'isUnique',
'message' => 'This code has already been taken'
)
)
);
var $belongsTo = array(
'Category' => array('className' => 'Category'),
'Shop' => array('className' => 'Shop')
);
///
function add($data)
{
$data["created_date"] = $data["modified_date"] = date("Y-m-d");
return ($this->save($data, true,
array (
"user_id",
"code",
"name",
"shop_id",
"category_id",
"producer_id",
"logo_visibility",
"created_date",
"modified_date"
)));
}
///
function setProductImageLink($id, $fieldName, $ImageId)
{
$data['id'] = $id;
$data["modified_date"] = date("Y-m-d");
$data[$fieldName] = $ImageId;
return ($this->save($data, true,
array (
$fieldName,
"modified_date"
)));
}
///
function modify($productId, $replaceWithData) {
$replaceWithData['id'] = $productId;
$replaceWithData["modified_date"] = date("Y-m-d");
$keysToSave = array (
"user_id",
"code",
"name",
"shop_id",
"category_id",
"logo_visibility",
);
return $this->save($replaceWithData, true, $keysToSave);
}
function setCategoryImageLink($productId, $imageCategoryId) {
$data = array(
"id" => $productId,
"category_image_id" => $imageCategoryId
);
return ($this->save($data, true,
array ("category_image_id")));
}
function setLogoImageLink($productId, $logoCategoryId) {
$data = array(
"id" => $productId,
"logo_image_id" => $logoCategoryId,
);
$data["modified_date"] = date("Y-m-d");
return ($this->save($data, true,
array ("logo_image_id", "modified_date")));
}
///
function getUniqueCode()
{
$product = $this->find(array(), 'MAX(Product.code) AS code', null, -1);
return ($product[0]['code'] + 1);
}
///
function modify_page_layout_data($itemId, $replaceWithData)
{
$replaceWithData['id'] = $itemId;
$replaceWithData["modified_date"] = date("Y-m-d");
return $this->save($replaceWithData, true,
array (
"text1",
"text2",
"modified_date"
));
}
///
function modify_spec_fields_values($productId, $spec_arrays)
{
$replaceWithData['id'] = $productId;
$replaceWithData["modified_date"] = date("Y-m-d");
$replaceWithData["spec_fields_values"] = serialize($spec_arrays);
return $this->save($replaceWithData, true,
array ("spec_fields_values", "modified_date"));
}
}
?>