first commit
This commit is contained in:
@@ -0,0 +1,296 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* SOTESHOP/stGroupPriceBackend
|
||||
*
|
||||
*
|
||||
* @package stGroupPricePlugin
|
||||
* @author Bartosz Alejski <bartosz.alejski@sote.pl>
|
||||
*/
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
/**
|
||||
* SOTESHOP/stGroupPriceBackend
|
||||
*
|
||||
*
|
||||
* @package stGroupPricePlugin
|
||||
* @author Bartosz Alejski <bartosz.alejski@sote.pl>
|
||||
*/
|
||||
|
||||
class stGroupPriceBackendComponents extends autoStGroupPriceBackendComponents {
|
||||
|
||||
public function executeConfigContent() {
|
||||
|
||||
}
|
||||
|
||||
public function executeProductPriceUpdate()
|
||||
{
|
||||
if (null == $this->group->getPriceType())
|
||||
{
|
||||
$group_price['id'] = $this->group->getId();
|
||||
$group_price['set_one_price'] = "false";
|
||||
$group_price['currency_id'] = $this->group->getCurrencyId();
|
||||
$group_price['tax_id'] = $this->group->getTaxId();
|
||||
$group_price['opt_vat'] = $this->group->getOptVat();
|
||||
$group_price['price_netto'] = $this->group->getPriceNetto();
|
||||
$group_price['price_brutto'] = $this->group->getPriceBrutto();
|
||||
$group_price['old_price_netto'] = $this->group->getOldPriceNetto();
|
||||
$group_price['old_price_brutto'] = $this->group->getOldPriceBrutto();
|
||||
$group_price['wholesale_a_price_netto'] = $this->group->getWholesaleANetto();
|
||||
$group_price['wholesale_a_price_brutto'] = $this->group->getWholesaleABrutto();
|
||||
$group_price['wholesale_b_price_netto'] = $this->group->getWholesaleBNetto();
|
||||
$group_price['wholesale_b_price_brutto'] = $this->group->getWholesaleBBrutto();
|
||||
$group_price['wholesale_c_price_netto'] = $this->group->getWholesaleCNetto();
|
||||
$group_price['wholesale_c_price_brutto'] = $this->group->getWholesaleCBrutto();
|
||||
|
||||
stChangePriceProgressBar::setParam('group_price', $group_price);
|
||||
}
|
||||
else
|
||||
{
|
||||
$price = $this->group->getPriceModifier();
|
||||
|
||||
$price = trim($price);
|
||||
|
||||
if ($price[0] == "+")
|
||||
{
|
||||
$prefix = "+";
|
||||
$value = substr($price, 1);
|
||||
}
|
||||
elseif ($price[0] == "-")
|
||||
{
|
||||
$prefix = "-";
|
||||
$value = substr($price, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
$prefix = "false";
|
||||
$value = $price;
|
||||
}
|
||||
|
||||
$reverse_price = strrev($price);
|
||||
|
||||
if ($reverse_price[0] == "%")
|
||||
{
|
||||
|
||||
$value = substr($price, 1, -1);
|
||||
|
||||
$sufix = "true";
|
||||
}
|
||||
else
|
||||
{
|
||||
$sufix = "false";
|
||||
}
|
||||
|
||||
$group_price['id'] = $this->group->getId();
|
||||
$group_price['currency_id'] = $this->group->getCurrencyId();
|
||||
$group_price['tax_id'] = $this->group->getTaxId();
|
||||
$group_price['opt_vat'] = $this->group->getOptVat();
|
||||
$group_price['set_one_price'] = "true";
|
||||
$group_price['type'] = $this->group->getPriceType();
|
||||
$group_price['value'] = $value;
|
||||
$group_price['prefix'] = $prefix;
|
||||
$group_price['sufix'] = $sufix;
|
||||
|
||||
stChangePriceProgressBar::setParam('group_price', $group_price);
|
||||
}
|
||||
|
||||
// throw new Exception('<pre>'.var_export($group_price, true).'</pre>');
|
||||
|
||||
$this->count = $this->group->countProducts();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user