Source for file ProductEditor.class.php
Documentation is available at ProductEditor.class.php
* Содержит класс ProductEditor
* @copyright ColoCall 2006
* Имя таблицы содержащей дополнительные данные(в эту таблицу будут загружаться данные из системы учета)
* @param Document $document
public function __construct($name, $module, Document $document, array $params = null) {
parent::__construct($name, $module, $document, $params);
* Возвращает имя таблицы с дополниельными данными
* Выводит дерево разделов
//$_POST['selectorID'] = Sitemap::getInstance()->getIDByURI(array('shop'));
'configFilename' => 'core/modules/shop/config/ProductDivisionEditor.component.xml'
* Для метода showTree вызывается свой билдер
public function build() {
$result = parent::build();
* Возвращает данные о значения в связанной таблицы
* Добавлена возможность вызвать окно "добавить производителя" из списка выбора
protected function getFKData($fkTableName, $fkKeyName) {
$result = $this->dbh->getForeignKeyData($fkTableName, $fkKeyName, $this->document->getLang());
if(in_array($this->getAction(), array('add', 'edit')) && $fkKeyName == 'producer_id'){
$addManufacturerOption = array(
$result[2] => $this->translate('TXT_ADD_MANUFACTURER'),
$result[0] = $addManufacturerOption;
$result[0] = array_merge($result[0], $addManufacturerOption);
$this->document->componentManager->createComponent(
'configFilename' => 'core/modules/shop/config/AddManufacturerForm.component.xml'
* Для поля smap_id формируется Дерево разделов
* Добавляются поля product_price, curr_id
* @return DataDescription
$fdPtID = $result->getFieldDescriptionByName('pt_id');
$result->getFieldDescriptionByName('producer_id')->removeProperty('nullable');
$smapPIDFieldDescription = $result->getFieldDescriptionByName('smap_id');
if ($productPriceFieldDescription = $result->getFieldDescriptionByName('product_price')) {
$productPriceFieldDescription->setProperty('nullable', false);
if ($productCurrFieldDescription = $result->getFieldDescriptionByName('curr_id')) {
$currencyOptions = $this->dbh->selectRequest(
'SELECT c.curr_id, curr_name FROM shop_currency c '.
'LEFT JOIN shop_currency_translation ct ON ct.curr_id = c.curr_id '.
'WHERE ct.lang_id = %s '.
$productCurrFieldDescription->loadAvailableValues($currencyOptions, 'curr_id', 'curr_name');
if($productCountFieldDescription = $result->getFieldDescriptionByName('product_count')){
elseif ($this->getAction() == 'getRawData' && ($productCountFieldDescription = $result->getFieldDescriptionByName('product_count'))) {
* Для метода edit добавляем данные о полях из внешней таблицы
if (($this->getType() == self::COMPONENT_TYPE_FORM_ALTER) && isset ($result[0]['product_code'])) {
$productCode = $result[0]['product_code'];
$res = $this->dbh->select($this->getExternalTableName(), array('product_price', 'product_count', 'curr_id'), array('product_code' => $productCode));
foreach ($result as $langID => $data) {
$result[$langID]['product_price'] = $res['product_price'];
$result[$langID]['product_count'] = $res['product_count'];
$result[$langID]['curr_id'] = $res['curr_id'];
elseif ($this->getType() == self::COMPONENT_TYPE_FORM_ADD) {
foreach ($result as $langID => $data) {
if (isset ($result[$langID]['ps_id'])) {
$result[$langID]['product_count'] = 1;
$request = 'SELECT product_id, product_count FROM `shop_product_external_properties` prop LEFT JOIN shop_products p ON prop.`product_code` = p.`product_code` WHERE p.product_id IN ('. implode(',', $ids). ')';
foreach ($result as $key => $row) {
$result[$key]['product_count'] = $res[$row['product_id']]['product_count'];
* Для метода редактирования изменяем данные для поля smap_id
$field = $this->getData()->getFieldByName('product_id');
$this->dbh->selectRequest('
SELECT files.upl_id, upl_path, upl_name
FROM `shop_product_uploads` p2f
LEFT JOIN `share_uploads` files ON p2f.upl_id=files.upl_id
', $this->getData()->getFieldByName('product_id')->getRowData(0))
$field = $this->getData()->getFieldByName('smap_id');
if($field->getRowData(0) !== null) {
$smapName = simplifyDBResult($this->dbh->select('share_sitemap_translation', array('smap_name'), array('smap_id' => $field->getRowData(0), 'lang_id' => $this->document->getLang())), 'smap_name', true);
$field->setRowProperty($i, 'data_name', $smapName);
$field->setRowProperty($i, 'segment', $smapSegment);
if(in_array($this->getAction(), array('add', 'edit'))){
$fd = $this->getDataDescription()->getFieldDescriptionByName('producer_id');
inspect($fd->getAvailableValues());
* При сохранении генерим thumbnail
//Если пустой фильтр - значит у нас метод вставки
$filter = array($this->getPK()=> $this->saver->getResult());
//Сохраняем данные в таблице дополнительных свойств
$productCode = $_POST[$this->getTableName()]['product_code'];
//Удаляем все записи с таким кодом продукта
$res = $this->dbh->modify(QAL::INSERT , $this->getExternalTableName(), array('product_code' => $productCode, 'product_price' => $price, 'product_count' => $count, 'curr_id'=> $currency));
if(isset ($_POST['shop_product_param_values'])){
$productParams = array_filter($_POST['shop_product_param_values']);
if(!empty($productParams)){
'shop_product_param_values',
array('product_id'=> $productID)
foreach($productParams as $ppID => $ppValue){
'shop_product_param_values',
'product_id' => $productID,
//записываем данные в таблицу share_sitemap_uploads
if(isset ($_POST['uploads']['upl_id'])){
foreach ($_POST['uploads']['upl_id'] as $uplID){
$this->dbh->modify(QAL::INSERT, 'shop_product_uploads', array('product_id' => $productID, 'upl_id' => $uplID));
* Выводит редактор значений парметров
$typeId = (int) $_POST['pt_id'];
$productId = (int) $_POST['product_id'];
$data = $this->dbh->selectRequest('
SELECT p.pp_id, pp_type, pp_name, pp_value FROM `shop_product_params` p
LEFT JOIN shop_product_params_translation pt On pt.pp_id = p.pp_id
LEFT JOIN shop_product_param_values pv ON pv.pp_id = p.pp_id and product_id = %s
WHERE pt_id=%s and pt.lang_id =%s
$JSONResponse = array('result' => true, 'data' => $data);
$this->response->setHeader('Content-Type', 'text/javascript; charset=utf-8');
|