first commit
This commit is contained in:
@@ -0,0 +1,970 @@
|
||||
<?php
|
||||
/**
|
||||
* SOTESHOP/stProductOptionsPlugin
|
||||
*
|
||||
* Ten plik należy do aplikacji stProductOptionsPlugin opartej na licencji (Open License SOTE) Otwarta Licencja SOTE.
|
||||
* Nie zmieniaj tego pliku, jeśli chcesz korzystać z automatycznych aktualizacji oprogramowania.
|
||||
* Jeśli chcesz wprowadzać swoje modyfikacje do programu, zapoznaj się z dokumentacją, jak zmieniać
|
||||
* oprogramowanie bez zmiany kodu bazowego http://www.sote.pl/modifications
|
||||
*
|
||||
* @package stProductOptionsPlugin
|
||||
* @subpackage actions
|
||||
* @copyright SOTE (www.sote.pl)
|
||||
* @license http://www.sote.pl/license/open (Open License SOTE) Otwarta Licencja SOTE
|
||||
* @version $Id: actions.class.php 16889 2012-01-27 11:23:35Z piotr $
|
||||
* @author Daniel Mendalka <daniel.mendalka@sote.pl>
|
||||
*/
|
||||
|
||||
/**
|
||||
* Akcje modułu stProductOptionsBackend
|
||||
*
|
||||
* @author Daniel Mendalka <daniel.mendalka@sote.pl>
|
||||
* @author Marcin Butlak <marcin.butlak@sote.pl>
|
||||
*
|
||||
* @package stProductOptionsPlugin
|
||||
* @subpackage actions
|
||||
* @property Product $related_object
|
||||
*/
|
||||
class stProductOptionsBackendActions extends autoStProductOptionsBackendActions
|
||||
{
|
||||
public function executeSelectTemplate()
|
||||
{
|
||||
$this->setLayout(false);
|
||||
}
|
||||
|
||||
public function executeTemplateEdit()
|
||||
{
|
||||
$ret = parent::executeTemplateEdit();
|
||||
|
||||
if ($this->product_options_template->isNew())
|
||||
{
|
||||
$this->getUser()->setParameter('zarzadzaj_szablonem', true, 'soteshop/stAdminGenerator/hidden');
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
public function executeAjaxJstreeJson()
|
||||
{
|
||||
$type = $this->getRequestParameter('type');
|
||||
$id = $this->getRequestParameter('id');
|
||||
$culture = $this->getRequestParameter('culture');
|
||||
|
||||
if ($type == 'field')
|
||||
{
|
||||
$results = ProductOptionsValuePeer::doSelectByFieldIdAsJsTreeFormat($id, $culture);
|
||||
}
|
||||
else
|
||||
{
|
||||
$results = ProductOptionsFieldPeer::doSelectByValueIdAsJsTreeFormat($id, $culture);
|
||||
}
|
||||
|
||||
return $this->renderJSON($results);
|
||||
}
|
||||
|
||||
public function executeAjaxJstreeTemplateJson()
|
||||
{
|
||||
$type = $this->getRequestParameter('type');
|
||||
$id = $this->getRequestParameter('id');
|
||||
$culture = $this->getRequestParameter('culture');
|
||||
|
||||
if ($type == 'field')
|
||||
{
|
||||
$results = ProductOptionsDefaultValuePeer::doSelectByFieldIdAsJsTreeFormat($id, $culture);
|
||||
}
|
||||
else
|
||||
{
|
||||
$results = ProductOptionsFieldPeer::doSelectByDefaultValueIdAsJsTreeFormat($id, $culture);
|
||||
}
|
||||
|
||||
return $this->renderJSON($results);
|
||||
}
|
||||
|
||||
public function executeAjaxJstreeDelete()
|
||||
{
|
||||
$type = $this->getRequestParameter('type');
|
||||
$id = $this->getRequestParameter('id');
|
||||
$product_id = $this->getRequestParameter('product_id');
|
||||
|
||||
if ($type == 'field')
|
||||
{
|
||||
$field = ProductOptionsFieldPeer::retrieveByPK($id);
|
||||
|
||||
if ($field)
|
||||
{
|
||||
$c = new Criteria();
|
||||
$c->add(ProductOptionsValuePeer::PRODUCT_OPTIONS_FIELD_ID, $field->getId());
|
||||
|
||||
foreach (ProductOptionsValuePeer::doSelect($c) as $index => $value)
|
||||
{
|
||||
if ($index > 0)
|
||||
{
|
||||
$value = $value->reload();
|
||||
}
|
||||
|
||||
$value->delete();
|
||||
}
|
||||
|
||||
$field->delete();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$value = ProductOptionsValuePeer::retrieveByPK($id);
|
||||
|
||||
if ($value)
|
||||
{
|
||||
$value->delete();
|
||||
}
|
||||
}
|
||||
|
||||
ProductOptionsValuePeer::updateStock($product_id);
|
||||
|
||||
stFastCacheManager::clearCache();
|
||||
|
||||
return $this->renderJSON(array(
|
||||
'status' => 'success',
|
||||
));
|
||||
}
|
||||
|
||||
public function executeAjaxJstreeTemplateDelete()
|
||||
{
|
||||
$type = $this->getRequestParameter('type');
|
||||
$id = $this->getRequestParameter('id');
|
||||
|
||||
if ($type == 'field')
|
||||
{
|
||||
$field = ProductOptionsFieldPeer::retrieveByPK($id);
|
||||
|
||||
if ($field)
|
||||
{
|
||||
$c = new Criteria();
|
||||
$c->add(ProductOptionsDefaultValuePeer::PRODUCT_OPTIONS_FIELD_ID, $field->getId());
|
||||
|
||||
foreach (ProductOptionsDefaultValuePeer::doSelect($c) as $index => $value)
|
||||
{
|
||||
if ($index > 0)
|
||||
{
|
||||
$value = $value->reload();
|
||||
}
|
||||
|
||||
$value->delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$value = ProductOptionsDefaultValuePeer::retrieveByPK($id);
|
||||
|
||||
if ($value)
|
||||
{
|
||||
$value->delete();
|
||||
}
|
||||
}
|
||||
|
||||
return $this->renderJSON(array(
|
||||
'status' => 'success',
|
||||
));
|
||||
}
|
||||
|
||||
public function executeAjaxJstreeAdd()
|
||||
{
|
||||
$entity_field_data = $this->getRequestParameter("entity_field_data");
|
||||
$parent = ProductOptionsValuePeer::retrieveByPK($this->getRequestParameter('parent_id'));
|
||||
$product_id = $this->getRequestParameter('product_id');
|
||||
$value = $this->getRequestParameter('value');
|
||||
|
||||
$optionValue = new ProductOptionsValue();
|
||||
$optionValue->setCulture(stLanguage::getHydrateCulture());
|
||||
|
||||
if ($entity_field_data)
|
||||
{
|
||||
$field = new ProductOptionsField();
|
||||
$field->setCulture(stLanguage::getHydrateCulture());
|
||||
$field->fromArray($entity_field_data, BasePeer::TYPE_FIELDNAME);
|
||||
}
|
||||
else
|
||||
{
|
||||
$field = ProductOptionsFieldPeer::retrieveByPK($this->getRequestParameter('field_id'));
|
||||
}
|
||||
|
||||
$optionValue->setIsActive($field->getIsActive());
|
||||
$optionValue->setProductOptionsField($field);
|
||||
$optionValue->setProductId($product_id);
|
||||
$optionValue->setStock($optionValue->getProduct()->getStockManagment() == ProductPeer::STOCK_PRODUCT_OPTIONS ? 0.00 : null);
|
||||
$optionValue->setValue($value);
|
||||
$optionValue->insertAsLastChildOf($parent);
|
||||
$optionValue->save();
|
||||
|
||||
|
||||
$this->updateProductSearchIndex($optionValue->getProduct());
|
||||
|
||||
if ($entity_field_data && isset($entity_field_data['fields_order']))
|
||||
{
|
||||
$this->updateFieldsOrder($entity_field_data['fields_order']);
|
||||
}
|
||||
|
||||
stFastCacheManager::clearCache();
|
||||
|
||||
return $this->renderJSON(array(
|
||||
"data" => $optionValue->toArray(BasePeer::TYPE_FIELDNAME)
|
||||
));
|
||||
}
|
||||
|
||||
public function executeAjaxJstreeTemplateAdd()
|
||||
{
|
||||
$entity_field_data = $this->getRequestParameter("entity_field_data");
|
||||
$parent = ProductOptionsDefaultValuePeer::retrieveByPK($this->getRequestParameter('parent_id'));
|
||||
$template_id = $this->getRequestParameter('template_id');
|
||||
$value = $this->getRequestParameter('value');
|
||||
|
||||
$optionValue = new ProductOptionsDefaultValue();
|
||||
$optionValue->setCulture(stLanguage::getHydrateCulture());
|
||||
|
||||
if ($entity_field_data)
|
||||
{
|
||||
$field = new ProductOptionsField();
|
||||
$field->setCulture(stLanguage::getHydrateCulture());
|
||||
$field->fromArray($entity_field_data, BasePeer::TYPE_FIELDNAME);
|
||||
}
|
||||
else
|
||||
{
|
||||
$field = ProductOptionsFieldPeer::retrieveByPK($this->getRequestParameter('field_id'));
|
||||
}
|
||||
|
||||
$optionValue->setProductOptionsField($field);
|
||||
$optionValue->setProductOptionsTemplateId($template_id);
|
||||
$optionValue->setValue($value);
|
||||
$optionValue->insertAsLastChildOf($parent);
|
||||
$optionValue->save();
|
||||
|
||||
if ($entity_field_data && isset($entity_field_data['fields_order']))
|
||||
{
|
||||
$this->updateFieldsOrder($entity_field_data['fields_order']);
|
||||
}
|
||||
|
||||
return $this->renderJSON(array(
|
||||
"data" => $optionValue->toArray(BasePeer::TYPE_FIELDNAME)
|
||||
));
|
||||
}
|
||||
|
||||
public function executeAjaxJstreeMove()
|
||||
{
|
||||
$id = $this->getRequestParameter('id');
|
||||
$type = $this->getRequestParameter('type');
|
||||
$prev_sibling_id = $this->getRequestParameter('prev_sibling_id');
|
||||
$parent_id = $this->getRequestParameter('parent_id');
|
||||
$fields_order = $this->getRequestParameter('fields_order');
|
||||
$product_id = $this->getRequestParameter('product_id');
|
||||
$culture = $this->getRequestParameter('culture');
|
||||
|
||||
if ($type == "value")
|
||||
{
|
||||
$this->moveJstreeValue($id, $prev_sibling_id, $parent_id);
|
||||
}
|
||||
else
|
||||
{
|
||||
$values = ProductOptionsValuePeer::doSelectByFieldId($id, $culture);
|
||||
|
||||
if ($prev_sibling_id) {
|
||||
$c = new Criteria();
|
||||
$c->add(ProductOptionsValuePeer::PRODUCT_OPTIONS_FIELD_ID, $prev_sibling_id);
|
||||
$c->addAscendingOrderByColumn(ProductOptionsValuePeer::LFT);
|
||||
$value = ProductOptionsValuePeer::doSelectOne($c);
|
||||
|
||||
$prev_sibling_id = $value->getId();
|
||||
}
|
||||
|
||||
foreach ($values as $value)
|
||||
{
|
||||
$this->moveJstreeValue($value->getId(), $prev_sibling_id, $parent_id);
|
||||
}
|
||||
|
||||
$this->updateFieldsOrder($fields_order);
|
||||
}
|
||||
|
||||
ProductOptionsValuePeer::updateStock($product_id);
|
||||
|
||||
stFastCacheManager::clearCache();
|
||||
|
||||
return sfView::HEADER_ONLY;
|
||||
}
|
||||
|
||||
public function executeAjaxJstreeTemplateMove()
|
||||
{
|
||||
$id = $this->getRequestParameter('id');
|
||||
$type = $this->getRequestParameter('type');
|
||||
$prev_sibling_id = $this->getRequestParameter('prev_sibling_id');
|
||||
$parent_id = $this->getRequestParameter('parent_id');
|
||||
$fields_order = $this->getRequestParameter('fields_order');
|
||||
$culture = $this->getRequestParameter('culture');
|
||||
|
||||
if ($type == "value")
|
||||
{
|
||||
$this->moveJstreeTemplateValue($id, $prev_sibling_id, $parent_id);
|
||||
}
|
||||
else
|
||||
{
|
||||
$values = ProductOptionsDefaultValuePeer::doSelectByFieldId($id, $culture);
|
||||
|
||||
if ($prev_sibling_id) {
|
||||
$c = new Criteria();
|
||||
$c->add(ProductOptionsDefaultValuePeer::PRODUCT_OPTIONS_FIELD_ID, $prev_sibling_id);
|
||||
$c->addAscendingOrderByColumn(ProductOptionsDefaultValuePeer::LFT);
|
||||
$value = ProductOptionsDefaultValuePeer::doSelectOne($c);
|
||||
|
||||
$prev_sibling_id = $value->getId();
|
||||
}
|
||||
|
||||
foreach ($values as $value)
|
||||
{
|
||||
$this->moveJstreeTemplateValue($value->getId(), null, $parent_id);
|
||||
}
|
||||
|
||||
$this->updateFieldsOrder($fields_order);
|
||||
}
|
||||
|
||||
return sfView::HEADER_ONLY;
|
||||
}
|
||||
|
||||
public function executeManager()
|
||||
{
|
||||
stAdminGeneratorHelper::generate('stProduct');
|
||||
|
||||
$i18n = $this->getContext()->getI18N();
|
||||
$product = ProductPeer::retrieveByPK($this->getRequestParameter('product_id'));
|
||||
$breadcrumbsBuilder = new stProductBreadcrumbsBuilder($this->getContext(), $this->getBreadcrumbs(), $product, array('product_id' => $product->getId(), 'category_id' => $this->getRequestParameter('category_id')));
|
||||
|
||||
$product->setCulture($this->getRequestParameter('culture', stLanguage::getHydrateCulture()));
|
||||
|
||||
$this->root = ProductOptionsValuePeer::doSelectRootAsJsTreeFormat($product);
|
||||
|
||||
if (!$this->root)
|
||||
{
|
||||
$root = new ProductOptionsValue();
|
||||
$root->setProduct($product);
|
||||
$root->makeRoot();
|
||||
$root->save();
|
||||
|
||||
$this->root = $root;
|
||||
} else {
|
||||
$this->root = ProductOptionsValuePeer::doSelectRoot($product);
|
||||
}
|
||||
|
||||
$this->product = $product;
|
||||
|
||||
$this->setFlash('info', $i18n->__('option.manager.help'), false);
|
||||
|
||||
$breadcrumbsBuilder->getEditBreadcrumbs($product)->add($i18n->__('Opcje produktu'));
|
||||
}
|
||||
|
||||
public function executeStockList()
|
||||
{
|
||||
$result = parent::executeStockList();
|
||||
|
||||
$request = $this->getRequest();
|
||||
|
||||
if ($request->getMethod() == sfRequest::POST)
|
||||
{
|
||||
$values = $request->getParameter('product_options_value');
|
||||
$updateProductColor = false;
|
||||
|
||||
/**
|
||||
* @var ProductOptionsValue $option
|
||||
*/
|
||||
foreach (ProductOptionsValuePeer::retrieveByPKs(array_keys($values)) as $option)
|
||||
{
|
||||
$options[$option->getId()] = $option;
|
||||
}
|
||||
|
||||
foreach ($values as $id => $value)
|
||||
{
|
||||
$option = $options[$id];
|
||||
$option->disableProductUpdate();
|
||||
$option->setStock($value['disabled'] ? null : $value['stock']);
|
||||
$option->save();
|
||||
|
||||
if ($option->getColor())
|
||||
{
|
||||
$updateProductColor = true;
|
||||
}
|
||||
}
|
||||
|
||||
ProductOptionsValuePeer::updateStock($this->related_object->getId());
|
||||
|
||||
if ($updateProductColor)
|
||||
{
|
||||
ProductOptionsValuePeer::updateProductColor($this->related_object->getId());
|
||||
}
|
||||
|
||||
$i18n = $this->getContext()->getI18N();
|
||||
|
||||
$this->setFlash('notice', $i18n->__('Twoje zmiany zostały zapisane', null, 'stAdminGeneratorPlugin'));
|
||||
|
||||
return $this->redirect($this->getRequest()->getReferer());
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function addStockFiltersCriteria($c)
|
||||
{
|
||||
parent::addStockFiltersCriteria($c);
|
||||
|
||||
$c->add(ProductOptionsValuePeer::PRODUCT_ID, $this->related_object->getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Funkcja kopiująca atrybuty i wartości z szablonu do produktu.
|
||||
*/
|
||||
public function executeAjaxJstreeAddTemplate()
|
||||
{
|
||||
$template_id = $this->getRequestParameter('template_id');
|
||||
$option_id = $this->getRequestParameter('parent_id');
|
||||
|
||||
$option = ProductOptionsValuePeer::retrieveByPk($option_id);
|
||||
|
||||
if(!$option)
|
||||
{
|
||||
return sfView::NONE;
|
||||
}
|
||||
|
||||
$c = new Criteria();
|
||||
$c->add(ProductOptionsDefaultValuePeer::PRODUCT_OPTIONS_TEMPLATE_ID, $template_id);
|
||||
$c->add(ProductOptionsDefaultValuePeer::PRODUCT_OPTIONS_DEFAULT_VALUE_ID, null, Criteria::ISNULL);
|
||||
|
||||
$template = ProductOptionsDefaultValuePeer::doSelectOne($c);
|
||||
|
||||
if ($template)
|
||||
{
|
||||
$count = $this->copyDescendands($template, $option);
|
||||
|
||||
if ($count > 1)
|
||||
{
|
||||
$product = $option->getProduct();
|
||||
$product->setOptHasOptions($product->getOptHasOptions() + $count - 1);
|
||||
$product->setStock(ProductOptionsValuePeer::updateStock($product, false));
|
||||
ProductPeer::doUpdate($product);
|
||||
}
|
||||
|
||||
ProductPeer::clearCache();
|
||||
stFastCacheManager::clearCache();
|
||||
}
|
||||
|
||||
return sfView::HEADER_ONLY;
|
||||
}
|
||||
|
||||
protected function updateProductOptionsValueFromRequest()
|
||||
{
|
||||
parent::updateProductOptionsValueFromRequest();
|
||||
|
||||
$data = $this->getRequestParameter('product_options_value');
|
||||
|
||||
if ($this->related_object->getStockManagment() == ProductPeer::STOCK_PRODUCT_OPTIONS)
|
||||
{
|
||||
if (isset($data['stock'])) {
|
||||
$this->product_options_value->setStock($data['stock']);
|
||||
}
|
||||
elseif ($this->product_options_value->isLeaf() && !isset($data['validate_stock']))
|
||||
{
|
||||
$this->product_options_value->setStock(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function saveProductOptionsValue($productOptionsValue)
|
||||
{
|
||||
$this->updateColorImage($productOptionsValue);
|
||||
|
||||
$updateProductSearchIndex = $productOptionsValue->isColumnModified(ProductOptionsValuePeer::OPT_VALUE)
|
||||
|| $productOptionsValue->isColumnModified(ProductOptionsValuePeer::MAN_CODE)
|
||||
|| $productOptionsValue->isColumnModified(ProductOptionsValuePeer::USE_PRODUCT);
|
||||
|
||||
$result = parent::saveProductOptionsValue($productOptionsValue);
|
||||
|
||||
if ($updateProductSearchIndex)
|
||||
{
|
||||
$this->updateProductSearchIndex($productOptionsValue->getProduct());
|
||||
}
|
||||
|
||||
ProductPeer::clearCache();
|
||||
stFastCacheManager::clearCache();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
protected function saveTemplateValueProductOptionsDefaultValue($product_options_default_value)
|
||||
{
|
||||
$this->updateColorImage($product_options_default_value, 'product_options_default_value');
|
||||
|
||||
return parent::saveTemplateValueProductOptionsDefaultValue($product_options_default_value);
|
||||
}
|
||||
|
||||
protected function getProductOptionsValueOrCreate($id = 'id')
|
||||
{
|
||||
$product_options_value = parent::getProductOptionsValueOrCreate($id);
|
||||
$filter = $product_options_value->getProductOptionsField()->getProductOptionsFilter();
|
||||
|
||||
$this->getUser()->setParameter('hide', $product_options_value->hasChildren(), 'stProductOptionsBackend/edit/fields/edit_stock');
|
||||
$this->getUser()->setParameter('hide', $product_options_value->hasChildren(), 'stProductOptionsBackend/edit/fields/man_code');
|
||||
$this->getUser()->setParameter('hide', $product_options_value->hasChildren(), 'stProductOptionsBackend/edit/fields/use_product');
|
||||
$this->getUser()->setParameter('hide', null === $filter || $filter->getFilterType() != ProductOptionsFilterPeer::COLOR_FILTER, 'stProductOptionsBackend/edit/fields/edit_color');
|
||||
|
||||
return $product_options_value;
|
||||
}
|
||||
|
||||
protected function getFieldProductOptionsFieldOrCreate($id = 'id')
|
||||
{
|
||||
$product_options_field = parent::getFieldProductOptionsFieldOrCreate($id);
|
||||
|
||||
if ($product_options_field->isNew())
|
||||
{
|
||||
$data = $this->getRequestParameter('entity_data', array());
|
||||
$product_options_field->fromArray($data, BasePeer::TYPE_FIELDNAME);
|
||||
|
||||
$option = ProductOptionsValuePeer::retrieveByPK($this->getRequestParameter('parent_id'));
|
||||
|
||||
$product_options_field->setIsActive($option->getIsActive());
|
||||
}
|
||||
|
||||
return $product_options_field;
|
||||
}
|
||||
|
||||
protected function getTemplateFieldProductOptionsFieldOrCreate($id = 'id')
|
||||
{
|
||||
$product_options_field = parent::getTemplateFieldProductOptionsFieldOrCreate($id);
|
||||
|
||||
if ($product_options_field->isNew())
|
||||
{
|
||||
$data = $this->getRequestParameter('entity_data', array());
|
||||
$product_options_field->fromArray($data, BasePeer::TYPE_FIELDNAME);
|
||||
}
|
||||
|
||||
return $product_options_field;
|
||||
}
|
||||
|
||||
protected function getTemplateValueProductOptionsDefaultValueOrCreate($id = 'id')
|
||||
{
|
||||
$product_options_value = parent::getTemplateValueProductOptionsDefaultValueOrCreate($id);
|
||||
|
||||
$filter = $product_options_value->getProductOptionsField()->getProductOptionsFilter();
|
||||
|
||||
$this->getUser()->setParameter('hide', null === $filter || $filter->getFilterType() != ProductOptionsFilterPeer::COLOR_FILTER, 'stProductOptionsBackend/edit/fields/template_field_edit_color');
|
||||
|
||||
return $product_options_value;
|
||||
}
|
||||
|
||||
protected function saveFieldProductOptionsField($product_options_field)
|
||||
{
|
||||
if (!$product_options_field->isNew())
|
||||
{
|
||||
$result = parent::saveFieldProductOptionsField($product_options_field);
|
||||
|
||||
stFastCacheManager::clearCache();
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
protected function saveTemplateFieldProductOptionsField($product_options_field)
|
||||
{
|
||||
if (!$product_options_field->isNew())
|
||||
{
|
||||
return parent::saveTemplateFieldProductOptionsField($product_options_field);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Aktualizuje kolor opcji
|
||||
*
|
||||
* @param ProductOptionsValue|ProductOptionsDefaultValue $value
|
||||
* @return void
|
||||
*/
|
||||
protected function updateColorImage($value, $requestNamespace = 'product_options_value')
|
||||
{
|
||||
$data = $this->getRequestParameter($requestNamespace);
|
||||
|
||||
if (isset($data['color_type']))
|
||||
{
|
||||
if (!$data['color_type'])
|
||||
{
|
||||
$value->deleteColorImage();
|
||||
$value->setColor($data['color']);
|
||||
}
|
||||
else
|
||||
{
|
||||
$color_image = $data['color_image'];
|
||||
|
||||
$delete = $color_image['delete'] ? explode(',', $color_image['delete']) : array();
|
||||
|
||||
$modified = $color_image['modified'] ? explode(',', $color_image['modified']) : array();
|
||||
|
||||
$upload_dir = sfConfig::get('sf_web_dir').'/uploads/plupload/'.$color_image['namespace'];
|
||||
|
||||
if ($delete)
|
||||
{
|
||||
$value->deleteColorImage();
|
||||
}
|
||||
|
||||
if ($modified)
|
||||
{
|
||||
$upload = $upload_dir.'/'.$modified[0];
|
||||
|
||||
if (is_file($upload))
|
||||
{
|
||||
$value->deleteColorImage();
|
||||
|
||||
$value->setColorImage($modified[0]);
|
||||
|
||||
if (!is_dir($value->getColorImageDir(true)))
|
||||
{
|
||||
mkdir($value->getColorImageDir(true), 0755, true);
|
||||
}
|
||||
|
||||
rename($upload, $value->getColorImagePath(true));
|
||||
}
|
||||
}
|
||||
|
||||
unset($data['color_image']);
|
||||
$this->getRequest()->setParameter($requestNamespace, $data);
|
||||
}
|
||||
|
||||
$value->setUseImageAsColor($data['color_type']);
|
||||
}
|
||||
}
|
||||
|
||||
protected function moveJstreeValue($id, $prev_sibling_id, $parent_id)
|
||||
{
|
||||
$value = ProductOptionsValuePeer::retrieveByPK($id);
|
||||
|
||||
if ($value)
|
||||
{
|
||||
if ($prev_sibling_id)
|
||||
{
|
||||
$value->moveToPrevSiblingOf(ProductOptionsValuePeer::retrieveByPK($prev_sibling_id));
|
||||
}
|
||||
else
|
||||
{
|
||||
$value->moveToLastChildOf(ProductOptionsValuePeer::retrieveByPK($parent_id));
|
||||
}
|
||||
|
||||
$value->save();
|
||||
}
|
||||
}
|
||||
|
||||
protected function moveJstreeTemplateValue($id, $prev_sibling_id, $parent_id)
|
||||
{
|
||||
$value = ProductOptionsDefaultValuePeer::retrieveByPK($id);
|
||||
|
||||
if ($value)
|
||||
{
|
||||
if ($prev_sibling_id)
|
||||
{
|
||||
$value->moveToPrevSiblingOf(ProductOptionsDefaultValuePeer::retrieveByPK($prev_sibling_id));
|
||||
}
|
||||
else
|
||||
{
|
||||
$value->moveToLastChildOf(ProductOptionsDefaultValuePeer::retrieveByPK($parent_id));
|
||||
}
|
||||
|
||||
$value->save();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param ProductOptionsValue $source
|
||||
* @param ProductOptionsValue $dest
|
||||
*/
|
||||
private function copyDescendands($source, $dest)
|
||||
{
|
||||
$product = $dest->getProduct();
|
||||
|
||||
$default_culture = stLanguage::getOptLanguage();
|
||||
|
||||
$c = new Criteria();
|
||||
|
||||
$c->add(ProductOptionsDefaultValuePeer::PRODUCT_OPTIONS_TEMPLATE_ID, $source->getProductOptionsTemplateId());
|
||||
$c->addAscendingOrderByColumn(ProductOptionsDefaultValuePeer::LFT);
|
||||
|
||||
$count = ProductOptionsDefaultValuePeer::doCount($c);
|
||||
|
||||
if ($count > 1)
|
||||
{
|
||||
$field_order = 0;
|
||||
|
||||
if ($dest->isRoot())
|
||||
{
|
||||
$fc = new Criteria();
|
||||
$fc->addJoin(ProductOptionsFieldPeer::ID, ProductOptionsValuePeer::PRODUCT_OPTIONS_FIELD_ID);
|
||||
$fc->add(ProductOptionsValuePeer::PRODUCT_OPTIONS_VALUE_ID, $dest->getId());
|
||||
$fc->addDescendingOrderByColumn(ProductOptionsFieldPeer::FIELD_ORDER);
|
||||
$field = ProductOptionsFieldPeer::doSelectOne($fc);
|
||||
|
||||
if (null !== $field)
|
||||
{
|
||||
$field_order = $field->getFieldOrder() + 1;
|
||||
}
|
||||
}
|
||||
|
||||
$fields = array();
|
||||
|
||||
$filters = array();
|
||||
|
||||
$depth = $dest->getDepth();
|
||||
|
||||
$tree_offset = $dest->getRgt() - 2;
|
||||
|
||||
// throw new Exception($tree_offset);
|
||||
|
||||
$parents = array($dest->getDepth() => $dest->getId());
|
||||
|
||||
$tree_size = $source->getRgt() - $source->getLft() - 1;
|
||||
|
||||
$sqls = sfPropelActAsNestedSetBehavior::shiftRLValues('ProductOptionsValuePeer', $dest->getRgt(), $tree_size, $dest->getProductId());
|
||||
|
||||
foreach ($sqls as $sql)
|
||||
{
|
||||
Propel::getConnection()->executeQuery($sql);
|
||||
}
|
||||
|
||||
for ($offset = 0; $offset < $count; $offset += stProductOptionsPluginListener::DUPLICATE_LIMIT)
|
||||
{
|
||||
$c->setOffset($offset);
|
||||
|
||||
$c->setLimit(stProductOptionsPluginListener::DUPLICATE_LIMIT);
|
||||
|
||||
$options = ProductOptionsDefaultValuePeer::doSelect($c);
|
||||
|
||||
foreach ($options as $option)
|
||||
{
|
||||
if ($option->getDepth() == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$depth_index = $depth + $option->getDepth();
|
||||
|
||||
$field_id = $option->getProductOptionsFieldId();
|
||||
|
||||
$duplicated_option = new ProductOptionsValue();
|
||||
|
||||
$option->copyInto($duplicated_option);
|
||||
|
||||
$duplicated_option->setStock(0);
|
||||
|
||||
$duplicated_option->setDepth($depth_index);
|
||||
|
||||
$duplicated_option->setLft($duplicated_option->getLft() + $tree_offset);
|
||||
|
||||
$duplicated_option->setRgt($duplicated_option->getRgt() + $tree_offset);
|
||||
|
||||
if ($duplicated_option->getDepth() > 0)
|
||||
{
|
||||
$duplicated_option->setProductOptionsValueId($parents[$duplicated_option->getDepth() - 1]);
|
||||
}
|
||||
|
||||
$duplicated_option->setProductId($dest->getProductId());
|
||||
|
||||
$duplicated_option->setProductOptionsTemplateId(0);
|
||||
|
||||
if ($field_id)
|
||||
{
|
||||
if (!isset($fields[$field_id]))
|
||||
{
|
||||
$field = $option->getProductOptionsField();
|
||||
|
||||
$duplicated_field = new ProductOptionsField();
|
||||
|
||||
$field->copyInto($duplicated_field);
|
||||
|
||||
$duplicated_field->setProductOptionsTemplateId(0);
|
||||
|
||||
$duplicated_field->setFieldOrder($field_order);
|
||||
|
||||
$duplicated_field->setId(ProductOptionsFieldPeer::doInsert($duplicated_field));
|
||||
|
||||
foreach ($field->getProductOptionsFieldI18ns() as $i18n)
|
||||
{
|
||||
if ($i18n->getCulture() && $i18n->getCulture() != $default_culture)
|
||||
{
|
||||
$duplicated_i18n = new ProductOptionsFieldI18n();
|
||||
|
||||
$i18n->copyInto($duplicated_i18n);
|
||||
|
||||
$duplicated_i18n->setCulture($i18n->getCulture());
|
||||
|
||||
$duplicated_i18n->setId($duplicated_field->getId());
|
||||
|
||||
ProductOptionsFieldI18nPeer::doInsert($duplicated_i18n);
|
||||
}
|
||||
}
|
||||
|
||||
$field->clearI18ns();
|
||||
|
||||
$fields[$field_id] = $duplicated_field->getId();
|
||||
|
||||
$filters[$field_id] = $duplicated_field->getProductOptionsFilterId();
|
||||
|
||||
$field_order++;
|
||||
}
|
||||
|
||||
$duplicated_option->setProductOptionsFieldId($fields[$field_id]);
|
||||
$duplicated_option->setOptFilterId($filters[$field_id]);
|
||||
}
|
||||
|
||||
$duplicated_option->setId(ProductOptionsValuePeer::doInsert($duplicated_option));
|
||||
|
||||
if ($option->getUseImageAsColor())
|
||||
{
|
||||
if (!is_dir($duplicated_option->getColorImageDir(true)))
|
||||
{
|
||||
mkdir($duplicated_option->getColorImageDir(true), 0755, true);
|
||||
}
|
||||
|
||||
copy($option->getColorImagePath(true), $duplicated_option->getColorImagePath(true));
|
||||
}
|
||||
|
||||
foreach ($option->getProductOptionsDefaultValueI18ns() as $i18n)
|
||||
{
|
||||
if ($i18n->getCulture() && $i18n->getCulture() != $default_culture)
|
||||
{
|
||||
$duplicated_i18n = new ProductOptionsValueI18n();
|
||||
|
||||
$i18n->copyInto($duplicated_i18n);
|
||||
|
||||
$duplicated_i18n->setCulture($i18n->getCulture());
|
||||
|
||||
$duplicated_i18n->setId($duplicated_option->getId());
|
||||
|
||||
ProductOptionsValueI18nPeer::doInsert($duplicated_i18n);
|
||||
}
|
||||
}
|
||||
|
||||
$option->clearI18ns();
|
||||
|
||||
if ($duplicated_option->hasChildren())
|
||||
{
|
||||
$parents[$duplicated_option->getDepth()] = $duplicated_option->getId();
|
||||
}
|
||||
}
|
||||
|
||||
unset($options);
|
||||
}
|
||||
}
|
||||
|
||||
return $count;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function executeFixOptions() {
|
||||
|
||||
}
|
||||
|
||||
public function executeFixStock()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function validateEdit()
|
||||
{
|
||||
$request = $this->getRequest();
|
||||
|
||||
if ($request->getMethod() == sfRequest::POST)
|
||||
{
|
||||
$i18n = $this->getContext()->getI18N();
|
||||
$data = $request->getParameter('product_options_value');
|
||||
|
||||
if (isset($data['use_product']) && $data['use_product'])
|
||||
{
|
||||
$c = new Criteria();
|
||||
$c->add(ProductPeer::CODE, $data['use_product']);
|
||||
|
||||
if (ProductPeer::doCount($c) > 0)
|
||||
{
|
||||
$request->setError('product_options_value{use_product}', $i18n->__('Produkt o podanym kodzie już istnieje'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return !$request->hasErrors();
|
||||
}
|
||||
|
||||
public function executeAjaxOptionChangeUpdate()
|
||||
{
|
||||
$namespace = $this->getRequestParameter('namespace');
|
||||
|
||||
$selected = $this->getRequestParameter($namespace);
|
||||
|
||||
$changed = $this->getRequestParameter('changed');
|
||||
|
||||
$product_id = $this->getRequestParameter('product_id');
|
||||
|
||||
$ids = array();
|
||||
|
||||
foreach ($selected as $field_id => $option_id)
|
||||
{
|
||||
$ids[$field_id] = $option_id;
|
||||
|
||||
if ($field_id == $changed)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$selectedValues = array();
|
||||
$parents = [];
|
||||
$index = 0;
|
||||
|
||||
foreach ($selected as $id)
|
||||
{
|
||||
if (!empty($id))
|
||||
{
|
||||
$option = ProductOptionsValuePeer::retrieveByPK($id);
|
||||
stNewProductOptions::buildSelectOptionsValues($option, $selected, $selectedValues, $parents, $index);
|
||||
}
|
||||
}
|
||||
|
||||
$product = ProductPeer::retrieveByPk($product_id);
|
||||
|
||||
$ids = stNewProductOptions::updateProduct($product, $ids, $selectedValues, false);
|
||||
|
||||
$content = $this->getRenderComponent('stProductOptionsBackend', 'optionPicker', array('product' => $product, 'namespace' => $namespace, 'selected' => $ids, 'ajax' => true));
|
||||
|
||||
$price = $product->getPriceBrutto();
|
||||
|
||||
if ($product->getPriceModifiers())
|
||||
{
|
||||
$price = stPrice::computePriceModifiers($product, $price, 'brutto');
|
||||
}
|
||||
|
||||
return $this->renderJSON(array(
|
||||
'price' => $price,
|
||||
'stock' => $product->getStock(),
|
||||
'man_code' => $product->getManCode(),
|
||||
'options' => $ids,
|
||||
'content' => $content,
|
||||
));
|
||||
}
|
||||
|
||||
protected function updateFieldsOrder(array $fields_order)
|
||||
{
|
||||
if ($fields_order)
|
||||
{
|
||||
/**
|
||||
* @var ProductOptionsField $field
|
||||
*/
|
||||
foreach (ProductOptionsFieldPeer::retrieveByPKs(array_keys($fields_order)) as $field)
|
||||
{
|
||||
$field->setFieldOrder($fields_order[$field->getId()]);
|
||||
$field->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function updateProductSearchIndex(Product $product)
|
||||
{
|
||||
stNewSearch::buildIndex($product, true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
/**
|
||||
* SOTESHOP/stProductOptionsPlugin
|
||||
*
|
||||
* Ten plik należy do aplikacji stProductOptionsPlugin opartej na licencji (Open License SOTE) Otwarta Licencja SOTE.
|
||||
* Nie zmieniaj tego pliku, jeśli chcesz korzystać z automatycznych aktualizacji oprogramowania.
|
||||
* Jeśli chcesz wprowadzać swoje modyfikacje do programu, zapoznaj się z dokumentacją, jak zmieniać
|
||||
* oprogramowanie bez zmiany kodu bazowego http://www.sote.pl/modifications
|
||||
*
|
||||
* @package stProductOptionsPlugin
|
||||
* @subpackage actions
|
||||
* @copyright SOTE (www.sote.pl)
|
||||
* @license http://www.sote.pl/license/open (Open License SOTE) Otwarta Licencja SOTE
|
||||
* @version $Id: components.class.php 3526 2010-02-16 10:31:45Z piotr $
|
||||
* @author Daniel Mendalka <daniel.mendalka@sote.pl>
|
||||
*/
|
||||
|
||||
/**
|
||||
* Komponenty dla modułu stProductOptionsBackend
|
||||
*
|
||||
* @author Daniel Mendalka <daniel.mendalka@sote.pl>
|
||||
*
|
||||
* @package stProductOptionsPlugin
|
||||
* @subpackage actions
|
||||
* @property ProductOptionsTemplate $product_options_template
|
||||
*/
|
||||
class stProductOptionsBackendComponents extends autoStProductOptionsBackendComponents
|
||||
{
|
||||
public function executeListMenu()
|
||||
{
|
||||
}
|
||||
|
||||
public function executeDepositoryStockOptions()
|
||||
{
|
||||
if ($this->product->getStockManagment() != ProductPeer::STOCK_PRODUCT_OPTIONS || $this->product->getOptHasOptions() <= 1)
|
||||
{
|
||||
return sfView::NONE;
|
||||
}
|
||||
}
|
||||
|
||||
public function executeOptionPicker()
|
||||
{
|
||||
if (!isset($this->product) || !get_class($this->product) == 'Product')
|
||||
{
|
||||
throw new Exception("You must pass Product instance");
|
||||
}
|
||||
|
||||
if ($this->product->getOptHasOptions() <= 1)
|
||||
{
|
||||
return sfView::NONE;
|
||||
}
|
||||
|
||||
$this->options = ProductOptionsValuePeer::doSelectByProduct($this->product, false);
|
||||
|
||||
if (!$this->options)
|
||||
{
|
||||
return sfView::NONE;
|
||||
}
|
||||
|
||||
if (!isset($this->selected))
|
||||
{
|
||||
$this->selected = array();
|
||||
}
|
||||
|
||||
if (!isset($this->ajax))
|
||||
{
|
||||
$this->ajax = false;
|
||||
}
|
||||
}
|
||||
|
||||
public function executeTemplateTree()
|
||||
{
|
||||
$this->root = ProductOptionsDefaultValuePeer::doSelectRootAsJsTreeFormat($this->product_options_template);
|
||||
}
|
||||
|
||||
public function executeEditProductImage()
|
||||
{
|
||||
$this->images = $this->product_options_value->getProduct()->getImages();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user