first commit
This commit is contained in:
156
apps/backend/modules/stGiftGroup/actions/actions.class.php
Normal file
156
apps/backend/modules/stGiftGroup/actions/actions.class.php
Normal file
@@ -0,0 +1,156 @@
|
||||
<?php
|
||||
/**
|
||||
* SOTESHOP/stGiftGroup
|
||||
*
|
||||
* Ten plik należy do aplikacji stGiftGroup 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 stGiftGroup
|
||||
* @subpackage actions
|
||||
* @copyright SOTE (www.sote.pl)
|
||||
* @license http://www.sote.pl/license/open (Open License SOTE) Otwarta Licencja SOTE
|
||||
* @version $Id:
|
||||
* @author Krzysztof Bebło <krzysztof.beblo@sote.pl>, Paweł Byszewski <pawel.byszewski@sote.pl>
|
||||
*/
|
||||
|
||||
/**
|
||||
* Akcje grupy produktów.
|
||||
*
|
||||
* @package stGiftGroup
|
||||
* @author Marcin Butlak <marcin.butlak@sote.pl>
|
||||
*/
|
||||
|
||||
class stGiftGroupActions extends autoStGiftGroupActions
|
||||
{
|
||||
public function executeProductAddGroup()
|
||||
{
|
||||
stAuthUsersListener::checkModificationCredentials($this, $this->getRequest(), $this->getModuleName());
|
||||
$ids = $this->getRequestParameter('product[selected]', array($this->getRequestParameter('id')));
|
||||
$related_id = $this->getRequestParameter('forward_parameters[product_group_id]');
|
||||
|
||||
$pids = $this->getAffectedProducts($ids, $related_id);
|
||||
|
||||
$new = array();
|
||||
|
||||
foreach ($ids as $id)
|
||||
{
|
||||
if (in_array($id, $pids))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$product_group_has_product = new ProductGroupHasProduct();
|
||||
$product_group_has_product->setProductGroupId($related_id);
|
||||
$product_group_has_product->setProductId($id);
|
||||
$product_group_has_product->save();
|
||||
$new[] = $id;
|
||||
}
|
||||
|
||||
if ($new)
|
||||
{
|
||||
$this->updateProducts($new, true);
|
||||
}
|
||||
|
||||
$this->redirect($this->getRequest()->getReferer());
|
||||
}
|
||||
|
||||
|
||||
public function executeProductRemoveGroup()
|
||||
{
|
||||
stAuthUsersListener::checkModificationCredentials($this, $this->getRequest(), $this->getModuleName());
|
||||
$ids = $this->getRequestParameter('product[selected]', array($this->getRequestParameter('id')));
|
||||
$related_id = $this->getRequestParameter('forward_parameters[product_group_id]');
|
||||
|
||||
$ids = $this->getAffectedProducts($ids, $related_id);
|
||||
|
||||
if ($ids)
|
||||
{
|
||||
$con = Propel::getConnection();
|
||||
$c = new Criteria();
|
||||
$c->add(ProductGroupHasProductPeer::PRODUCT_GROUP_ID, $related_id);
|
||||
$c->add(ProductGroupHasProductPeer::PRODUCT_ID, $ids, Criteria::IN);
|
||||
BasePeer::doDelete($c, $con);
|
||||
$this->updateProducts($ids, false);
|
||||
}
|
||||
|
||||
$this->redirect($this->getRequest()->getReferer());
|
||||
}
|
||||
|
||||
public function addProductFiltersCriteria($c)
|
||||
{
|
||||
parent::addProductFiltersCriteria($c);
|
||||
|
||||
if (isset($this->filters['list_image']) && $this->filters['list_image'] !== '')
|
||||
{
|
||||
$c->add(ProductPeer::OPT_IMAGE, null, $this->filters['list_image'] ? Criteria::ISNOTNULL : Criteria::ISNULL);
|
||||
}
|
||||
|
||||
if (isset($this->filters['list_assigned']) && $this->filters['list_assigned'] !== '')
|
||||
{
|
||||
$c->addJoin(ProductPeer::ID, sprintf("%s AND %s = %d", ProductGroupHasProductPeer::PRODUCT_ID, ProductGroupHasProductPeer::PRODUCT_GROUP_ID, $this->forward_parameters['product_group_id']), Criteria::LEFT_JOIN);
|
||||
|
||||
if ($this->filters['list_assigned'])
|
||||
{
|
||||
$c->add(ProductGroupHasProductPeer::ID, null, Criteria::ISNOTNULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
$c->add(ProductGroupHasProductPeer::ID, null, Criteria::ISNULL);
|
||||
}
|
||||
}
|
||||
|
||||
$c->add(ProductPeer::OPT_HAS_OPTIONS, 1, Criteria::LESS_EQUAL);
|
||||
}
|
||||
|
||||
protected function addFiltersCriteria($c)
|
||||
{
|
||||
$c->add(ProductGroupPeer::FROM_BASKET_VALUE, null, Criteria::ISNOTNULL);
|
||||
|
||||
parent::addFiltersCriteria($c);
|
||||
}
|
||||
|
||||
protected function updateProducts($ids, $is_gift)
|
||||
{
|
||||
$con = Propel::getConnection();
|
||||
|
||||
if ($is_gift)
|
||||
{
|
||||
$sql = 'UPDATE %1$s SET %2$s = %2$s + 1 WHERE %3$s IN ('.implode(',', $ids).')';
|
||||
}
|
||||
else
|
||||
{
|
||||
$sql = 'UPDATE %1$s SET %2$s = %2$s - 1 WHERE %3$s IN ('.implode(',', $ids).')';
|
||||
}
|
||||
|
||||
$st = $con->prepareStatement(sprintf($sql,
|
||||
ProductPeer::TABLE_NAME,
|
||||
ProductPeer::IS_GIFT,
|
||||
ProductPeer::ID
|
||||
));
|
||||
|
||||
|
||||
$st->executeUpdate();
|
||||
}
|
||||
|
||||
protected function getAffectedProducts($ids, $related_id)
|
||||
{
|
||||
$c = new Criteria();
|
||||
$c->addSelectColumn(ProductGroupHasProductPeer::PRODUCT_ID);
|
||||
$c->add(ProductGroupHasProductPeer::PRODUCT_GROUP_ID, $related_id);
|
||||
$c->add(ProductGroupHasProductPeer::PRODUCT_ID, array_values($ids), Criteria::IN);
|
||||
// throw new Exception('tes32!');
|
||||
$rs = ProductGroupHasProductPeer::doSelectRs($c);
|
||||
|
||||
$pids = array();
|
||||
|
||||
while($rs->next())
|
||||
{
|
||||
$row = $rs->getRow();
|
||||
$pids[] = $row[0];
|
||||
}
|
||||
|
||||
return $pids;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
/**
|
||||
* SOTESHOP/stGiftGroup
|
||||
*
|
||||
* Ten plik należy do aplikacji stGiftGroup 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 stGiftGroup
|
||||
* @subpackage actions
|
||||
* @copyright SOTE (www.sote.pl)
|
||||
* @license http://www.sote.pl/license/open (Open License SOTE) Otwarta Licencja SOTE
|
||||
* @version $Id:
|
||||
* @author Marcin Butlak <marcin.butlak@sote.pl>
|
||||
*/
|
||||
|
||||
/**
|
||||
* Komponenty stGiftGroup
|
||||
*
|
||||
* @author Marcin Butlak <marcin.butlak@sote.pl>
|
||||
*
|
||||
* @package stGiftGroup
|
||||
* @subpackage actions
|
||||
*/
|
||||
class stGiftGroupComponents extends autoStGiftGroupComponents
|
||||
{
|
||||
|
||||
}
|
||||
?>
|
||||
84
apps/backend/modules/stGiftGroup/config/generator.yml
Normal file
84
apps/backend/modules/stGiftGroup/config/generator.yml
Normal file
@@ -0,0 +1,84 @@
|
||||
generator:
|
||||
class: stAdminGenerator
|
||||
param:
|
||||
model_class: ProductGroup
|
||||
product_model_class: Product
|
||||
theme: simple
|
||||
custom_actions:
|
||||
list: [product]
|
||||
label: Gratisy w koszyku
|
||||
|
||||
documentation:
|
||||
pl: https://www.sote.pl/docs/gratisy-w-koszyku
|
||||
en: https://www.soteshop.com/docs/gifts_in_cart
|
||||
|
||||
icon: stGiftGroup
|
||||
route: @stGiftGroup
|
||||
applications: [stProduct]
|
||||
|
||||
list:
|
||||
use_helper: [stGiftGroup/stGiftGroup]
|
||||
peer_method: doSelect
|
||||
peer_count_method: doCount
|
||||
title: Gratisy
|
||||
display: [=from_basket_value]
|
||||
menu:
|
||||
display: [list]
|
||||
fields:
|
||||
list: {name: Gratisy, action: stGiftGroup/list}
|
||||
actions:
|
||||
_create: {name: Dodaj}
|
||||
object_actions:
|
||||
_edit: -
|
||||
_delete: -
|
||||
fields:
|
||||
from_basket_value: {name: Od wartości koszyka, label_callback: list_gift_group_price_label}
|
||||
sort: [from_basket_value, DESC]
|
||||
empty_message: {message: "Tutaj pojawią się gratisy.", i18n: stGiftGroup}
|
||||
|
||||
create:
|
||||
title: "Dodaj nowy gratis"
|
||||
edit:
|
||||
use_helper: [stGiftGroup/stGiftGroup]
|
||||
menu:
|
||||
display: [product]
|
||||
fields:
|
||||
_edit: {name: Edycja podstawowa}
|
||||
product: {name: Przypisz produkty, action: stGiftGroup/productList?product_group_id=%%id%%}
|
||||
title: Edycja podstawowa
|
||||
display: [from_basket_value]
|
||||
fields:
|
||||
from_basket_value: {name: Od wartości koszyka, type: gift_group_price, help: Wartość koszyka nie uwzględnia rabatu na zamówienie}
|
||||
actions:
|
||||
_list: {name: Lista}
|
||||
_save: {name: Zapisz}
|
||||
_save_and_add: {name: Zapisz i dodaj}
|
||||
_delete: {name: Usuń}
|
||||
product_list:
|
||||
use_stylesheet: [backend/stProductList.css]
|
||||
use_helper: [stProduct/stProduct]
|
||||
forward_parameters: [product_group_id]
|
||||
filters:
|
||||
list_image: {partial: filter_list_image, module: stProduct}
|
||||
name: {filter_field: product_i18n.name}
|
||||
fields:
|
||||
code: {name: Kod, i18n: stProduct}
|
||||
name: {name: Nazwa, params: size=40, sort_field: product_i18n.name, width: 35%, callback: list_product_name}
|
||||
list_image: {name: Zdjęcie, width: 1%, callback: list_product_image, i18n: stProduct}
|
||||
opt_price_brutto: {name: Cena, width: 1%, callback: list_product_price, label_callback: list_product_price_label, i18n: stProduct}
|
||||
active: {name: Aktywny, i18n: stProduct}
|
||||
build_options:
|
||||
related_id: forward_parameters.product_group_id
|
||||
through_class: ProductGroupHasProduct
|
||||
peer_method: doSelectWithI18n
|
||||
peer_count_method: doCountWithI18n
|
||||
display: [list_image, name, code, opt_price_brutto, active]
|
||||
select_actions:
|
||||
display: [product_add_group, product_remove_group]
|
||||
actions:
|
||||
product_add_group: {name: Dodaj do grupy, action: productAddGroup, i18n: stAdminGeneratorPlugin}
|
||||
product_remove_group: {name: Usuń z grupy, action: productRemoveGroup, i18n: stAdminGeneratorPlugin}
|
||||
menu: {use: edit.menu}
|
||||
title: Przypisz produkty
|
||||
object_actions: []
|
||||
actions: []
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
function list_gift_group_price_label($label)
|
||||
{
|
||||
$currency = stCurrency::getInstance(sfContext::getInstance())->getBackendMainCurrency();
|
||||
|
||||
return __($label, null, 'stGiftGroup').' ['.$currency->getFrontSymbol().$currency->getBackSymbol().']';
|
||||
}
|
||||
|
||||
function object_gift_group_price(ProductGroup $product_group, $method, $options)
|
||||
{
|
||||
sfLoader::loadHelpers(array('Helper', 'stPrice'));
|
||||
$currency = stCurrency::getInstance(sfContext::getInstance())->getBackendMainCurrency();
|
||||
return input_tag('product_group[from_basket_value]', $product_group->getFromBasketValue(), array('size' => 6, 'style' => 'vertical-align: middle')).' <span style="vertical-align: middle">'.$currency->getShortcut().'</span>'.st_price_add_format_behavior('product_group_from_basket_value', 0);
|
||||
}
|
||||
Reference in New Issue
Block a user