<?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"));
}
}
?>