*/ class stGroupPriceBackendActions extends autoStGroupPriceBackendActions { public function executeProductAddGroup() { stAuthUsersListener::checkModificationCredentials($this, $this->getRequest(), $this->getModuleName()); $ids = $this->getRequestParameter('product[selected]', array()); $related_id = $this->getRequestParameter('forward_parameters[group_price_id]'); /** * @var Product $product */ foreach (ProductPeer::retrieveByPKs($ids) as $product) { $product->setGroupPriceId($related_id); if ($product->isModified()) { ProductPeer::doUpdate($product); } } return $this->redirect($this->getRequest()->getReferer()); } public function executeProductRemoveGroup() { stAuthUsersListener::checkModificationCredentials($this, $this->getRequest(), $this->getModuleName()); $ids = $this->getRequestParameter('product[selected]', array()); foreach (ProductPeer::retrieveByPKs($ids) as $product) { $product->setGroupPriceId(null); if ($product->isModified()) { ProductPeer::doUpdate($product); } } return $this->redirect($this->getRequest()->getReferer()); } protected function saveGroupPrice($group_price) { parent::saveGroupPrice($group_price); if ($this->hasRequestParameter('save_and_add')) { return $this->redirect('@stGroupPricePlugin?action=edit&id=' . $group_price->getId() . '&update=1'); } } protected function saveCurrencyPriceAddGroupPrice($add_group_price) { parent::saveCurrencyPriceAddGroupPrice($add_group_price); if ($this->hasRequestParameter('save_and_add')) { return $this->redirect('@stGroupPricePlugin?action=currencyPriceEdit&id=' . $add_group_price->getId() . '¤cy_id=' . $add_group_price->getCurrencyId() . '&update=1'); } } protected function updateGroupPriceFromRequest() { if (!$this->getRequestParameter('group_type')) { $this->showField('ustaw_szablon_cen'); $this->hideField('zmien_jedna_cene'); $this->group_price->setPriceType(null); } else { $this->showField('zmien_jedna_cene'); $this->hideField('ustaw_szablon_cen'); } parent::updateGroupPriceFromRequest(); $c = new Criteria(); $c->add(CurrencyPeer::MAIN, 1); $currency_main = CurrencyPeer::doSelectOne($c); $this->group_price->setCurrencyId($currency_main->getId()); } protected function updateCurrencyPriceAddGroupPriceFromRequest() { if (!$this->getRequestParameter('group_type')) { $this->showField('ustaw_szablon_cen'); $this->hideField('zmien_jedna_cene'); $this->add_group_price->setPriceType(null); } else { $this->showField('zmien_jedna_cene'); $this->hideField('ustaw_szablon_cen'); } parent::updateCurrencyPriceAddGroupPriceFromRequest(); } public function validateEdit() { $ok = true; if ($this->getRequest()->getMethod() == sfRequest::POST && $this->getRequest()->getParameter('group_type')) { $i18n = $this->getContext()->getI18N(); $price = $this->getRequestParameter('group_price[price_modifier]'); $pattern = "/^[-+]{0,1}[0-9.]{1,}\%{0,1}$/"; if (preg_match($pattern, $price) != 1) { $this->getRequest()->setError('group_price{price_modifier}', $i18n->__('Zła wartość')); $ok = false; } if (!$price) { $this->getRequest()->setError('group_price{price_modifier}', $i18n->__('Proszę podać cenę.')); $ok = false; } $percent = substr($price, -1); if ($percent == "%") { if ($price[0] != "-" && $price[0] != "+") { $this->getRequest()->setError('group_price{price_modifier}', $i18n->__('Wartość procentowa musi zawierać znak + lub -')); $ok = false; } $value = substr($price, 1, -1); $pattern = "/^[0-9]+$/"; if (preg_match($pattern, $value) != 1) { $this->getRequest()->setError('group_price{price_modifier}', $i18n->__('Zła wartość procentowa')); $ok = false; } if ($price[0] == "-" && $value > 100) { $this->getRequest()->setError('group_price{price_modifier}', $i18n->__('Zła wartość procentowa')); $ok = false; } } } return $ok; } public function validateAddGroupPriceEdit() { $ok = true; if ($this->getRequest()->getMethod() == sfRequest::POST && $this->getRequest()->getParameter('group_type')) { $i18n = $this->getContext()->getI18N(); $price = $this->getRequestParameter('add_group_price[price_modifier]'); $pattern = "/^[-+]{0,1}[0-9.]{1,}\%{0,1}$/"; if (preg_match($pattern, $price) != 1) { $this->getRequest()->setError('add_group_price{price_modifier}', $i18n->__('Zła wartość')); $ok = false; } if (!$price) { $this->getRequest()->setError('add_group_price{price_modifier}', $i18n->__('Proszę podać cenę.')); $ok = false; } $reverse_price = strrev($price); if ($reverse_price[0] == "%") { if ($price[0] != "-" && $price[0] != "+") { $this->getRequest()->setError('add_group_price{price_modifier}', $i18n->__('Wartość procentowa musi zawierać znak + lub -')); $ok = false; } $value = substr($price, 1, -1); $pattern = "/^[0-9]+$/"; if (preg_match($pattern, $value) != 1) { $this->getRequest()->setError('add_group_price{price_modifier}', $i18n->__('Zła wartość procentowa')); $ok = false; } if ($price[0] == "-" && $value > 100) { $this->getRequest()->setError('add_group_price{price_modifier}', $i18n->__('Zła wartość procentowa')); $ok = false; } } } return $ok; } protected function getGroupPriceOrCreate($id = 'id') { $groupPrice = parent::getGroupPriceOrCreate($id); if ($groupPrice->isNew()) { $this->hideAction('_save_and_add'); } if (null !== $groupPrice->getPriceType()) { $this->hideField('ustaw_szablon_cen'); } else { $this->hideField('zmien_jedna_cene'); } return $groupPrice; } protected function getCurrencyPriceAddGroupPriceOrCreate($id = 'id', $currency_id = 'currency_id') { $groupPrice = parent::getCurrencyPriceAddGroupPriceOrCreate($id, $currency_id); if ($groupPrice->isNew()) { $this->hideAction('_save_and_add'); } if (null !== $groupPrice->getPriceType()) { $this->hideField('ustaw_szablon_cen'); } else { $this->hideField('zmien_jedna_cene'); } return $groupPrice; } protected function addProductFiltersCriteria($c) { parent::addProductFiltersCriteria($c); $c->remove(ProductPeer::GROUP_PRICE_ID); if (!isset($this->filters['assigned_product']) || "" === $this->filters['assigned_product']) { $criterion = $c->getNewCriterion(ProductPeer::GROUP_PRICE_ID, $this->related_object->getId()); $criterion->addOr($c->getNewCriterion(ProductPeer::GROUP_PRICE_ID, null, Criteria::ISNULL)); $c->add($criterion); } else { if ($this->filters['assigned_product']) { $c->add(ProductPeer::GROUP_PRICE_ID, $this->related_object->getId()); } else { $c->add(ProductPeer::GROUP_PRICE_ID, null, Criteria::ISNULL); } } } }