first commit

This commit is contained in:
2025-03-12 17:06:23 +01:00
commit 2241f7131f
13185 changed files with 1692479 additions and 0 deletions

View File

@@ -0,0 +1,44 @@
<?php
use_helper('stPrice');
function st_depository_list_stock(Product $product, $list_mode = null)
{
if (!$product->hasStockManagmentWithOptions())
{
$stock = stPrice::round($product->getStock());
}
else
{
$c = new Criteria();
$c->addSelectColumn('SUM('.ProductOptionsValuePeer::STOCK.')');
$c->add(ProductOptionsValuePeer::PRODUCT_ID, $product->getId());
$c->add(ProductOptionsValuePeer::LFT, sprintf('%s - %s = 1', ProductOptionsValuePeer::RGT, ProductOptionsValuePeer::LFT) , Criteria::CUSTOM);
$rs = ProductOptionsValuePeer::doSelectRS($c);
$stock = stPrice::round($rs->next() ? $rs->get(1) : 0);
}
if ($list_mode == 'edit')
{
$content = input_tag('product['.$product->getId().'][stock]', $stock, array(
'onchange' => 'this.value=stPrice.fixNumberFormat(this.value, 2)',
'size' => 6,
'disabled' => false !== $product->hasStockManagmentWithOptions()
));
}
else
{
$content = $stock;
}
return $content;
}
function st_depository_product_options_link(Product $product)
{
return $product->hasStockManagmentWithOptions() ? st_get_admin_button('edit', 'Opcje produktu', '@stDepositoryPlugin?action=optionsList&product_id='.$product->getId(), array('size' => 'small')) : '';
}

View File

@@ -0,0 +1,230 @@
<?php
/**
* SOTESHOP/stDepositoryPlugin
*
* Ten plik należy do aplikacji stDepositoryPlugin opartej na licencji (Professional License 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 stDepositoryPlugin
* @subpackage libs
* @copyright SOTE (www.sote.pl)
* @license http://www.sote.pl/license/sote (Professional License SOTE)
* @version $Id: stDepositiory.class.php 617 2009-04-09 13:02:31Z michal $
* @author Marcin Olejniczak <marcin.olejniczak@sote.pl>
*/
/**
* Klasa stDepository
*
* @author Marcin Olejniczak <marcin.olejniczak@sote.pl>
*
* @package stDepositoryPlugin
* @subpackage libs
*/
class stDepository
{
/**
* Zwiększanie stanu magazynowego produktu
*
* @param object $product
* @param integer $quantity
*/
public static function increase($product, $quantity)
{
$id = is_object($product)? $product->getId() : $product;
if ($id)
{
$con = Propel::getConnection();
$con->executeQuery(sprintf('UPDATE %1$s SET %2$s = %2$s + %3$s WHERE %4$s = %5$s',
ProductPeer::TABLE_NAME,
ProductPeer::STOCK,
$quantity,
ProductPeer::ID,
$id
));
AllegroAuctionPeer::updateRequiresSync($id);
$dispatcher = stEventDispatcher::getInstance();
if (!empty($dispatcher->getListeners('stDepository.increase')))
{
$dispatcher->notify(new sfEvent(null, 'stDepository.increase', ['product' => $product, 'quantity' => $quantity]));
}
}
}
/**
* Zmniejszanie stanu magazynowego produktu
*
* @param object $product
* @param integer $quantity
*/
public static function decrease($product, $quantity)
{
$id = is_object($product) ? $product->getId() : $product;
if ($id)
{
$con = Propel::getConnection();
$con->executeQuery(sprintf('UPDATE %1$s SET %2$s = GREATEST(0, %2$s - %3$s) WHERE %4$s = %5$s',
ProductPeer::TABLE_NAME,
ProductPeer::STOCK,
$quantity,
ProductPeer::ID,
$id
));
AllegroAuctionPeer::updateRequiresSync($id);
$dispatcher = stEventDispatcher::getInstance();
if (!empty($dispatcher->getListeners('stDepository.decrease')))
{
$dispatcher->notify(new sfEvent(null, 'stDepository.decrease', ['product' => $product, 'quantity' => $quantity]));
}
}
}
public static function increaseForOrderProduct(OrderProduct $item, $quantity = null)
{
if (null === $quantity)
{
$quantity = $item->getQuantity();
}
if ($item->hasPriceModifiers() && $item->getProduct()->hasStockManagmentWithOptions())
{
self::increaseProductOptionsForOrderProduct($item);
}
else
{
self::increase($item->getProductId(), $quantity);
}
foreach ($item->getOrderProductHasSets() as $set)
{
if ($set->getProductId() != $item->getProductId())
{
self::increase($set->getProductId(), $quantity);
}
}
}
public static function decreaseForOrderProduct(OrderProduct $item, $quantity = null)
{
if (null === $quantity)
{
$quantity = $item->getQuantity();
}
if ($item->hasPriceModifiers() && $item->getProduct()->hasStockManagmentWithOptions())
{
self::decreaseProductOptionsForOrderProduct($item);
}
else
{
self::decrease($item->getProductId(), $quantity);
}
foreach ($item->getOrderProductHasSets() as $set)
{
if ($set->getProductId() != $item->getProductId())
{
self::decrease($set->getProductId(), $quantity);
}
}
}
protected static function increaseProductOptionsForOrderProduct($item)
{
$ids = self::getProductOptionsIds($item);
if ($ids)
{
stDepository::increaseProductOptions($ids, $item->getQuantity());
ProductOptionsValuePeer::updateStock($item->getProductId());
}
}
protected static function decreaseProductOptionsForOrderProduct($item)
{
$ids = self::getProductOptionsIds($item);
if ($ids)
{
stDepository::decreaseProductOptions($ids, $item->getQuantity());
ProductOptionsValuePeer::updateStock($item->getProductId());
}
}
public static function set($product, $quantity)
{
$id = is_object($product) ? $product->getId() : $product;
if ($id)
{
$con = Propel::getConnection();
$ps = $con->prepareStatement(sprintf('UPDATE %s SET %s = ? WHERE %s = ?',
ProductPeer::TABLE_NAME,
ProductPeer::STOCK,
ProductPeer::ID
));
$ps->set(1, $quantity);
$ps->setInteger(2, $id);
$ps->executeQuery();
$dispatcher = stEventDispatcher::getInstance();
if (!empty($dispatcher->getListeners('stDepository.set')))
{
$dispatcher->notify(new sfEvent(null, 'stDepository.set', ['product' => $product, 'quantity' => $quantity]));
}
}
}
public static function increaseProductOptions($ids, $quantity)
{
$con = Propel::getConnection();
$con->executeQuery(sprintf('UPDATE %1$s SET %2$s = %2$s + %3$s WHERE %4$s IN (%5$s)',
ProductOptionsValuePeer::TABLE_NAME,
ProductOptionsValuePeer::STOCK,
$quantity,
ProductOptionsValuePeer::ID,
implode(',', $ids)
));
}
public static function decreaseProductOptions($ids, $quantity)
{
$con = Propel::getConnection();
$con->executeQuery(sprintf('UPDATE %1$s SET %2$s = GREATEST(0, %2$s - %3$s) WHERE %4$s IN (%5$s)',
ProductOptionsValuePeer::TABLE_NAME,
ProductOptionsValuePeer::STOCK,
$quantity,
ProductOptionsValuePeer::ID,
implode(',', $ids)
));
}
/**
* Pobranie stanu magazynowego produktu
*
* @param integer $product_id
* @return integer
*/
public static function getStock($product_id)
{
$product = ProductPeer::retrieveByPK($product_id);
return $product->getStock();
}
}

View File

@@ -0,0 +1,393 @@
<?php
/**
* SOTESHOP/stDepositoryPlugin
*
* Ten plik należy do aplikacji stDepositoryPlugin opartej na licencji (Professional License 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 stDepositoryPlugin
* @subpackage libs
* @copyright SOTE (www.sote.pl)
* @license http://www.sote.pl/license/sote (Professional License SOTE)
* @version $Id: stDepositoryPluginListener.class.php 617 2009-04-09 13:02:31Z michal $
* @author Daniel Mendalka <daniel.mendalka@sote.pl>
*/
/**
* Podpięcie pod generator stProduct modułu stDepositoryPlugin
*
* @author Daniel Mendalka <daniel.mendalka@sote.pl>
*
* @package stDepositoryPlugin
* @subpackage libs
*/
class stDepositoryPluginListener
{
const LIST_STOCK = 'list_stock';
public static function productSetListStock(sfEvent $event)
{
$event->getSubject()->setStock($event['arguments'][0]);
return true;
}
public static function translateFieldName()
{
return 'list_stock';
}
/**
* Podpięcie zdarzenia dla generatora produktu
*
* @param sfEvent $event
*/
public static function generate(sfEvent $event)
{
// możemy wywoływać podaną metodę wielokrotnie co powoduje dołączenie kolejnych plików
$event->getSubject()->attachAdminGeneratorFile('stDepositoryPlugin', 'stProduct.yml');
}
public static function modAddItem(sfEvent $event)
{
$event['item']->setMaxQuantity($event['product']->getStock());
}
public static function addDepositoryFiltersCriteria(sfEvent $event)
{
$action = $event->getSubject();
$has_filter = isset($action->filters['list_stock']) && (isset($action->filters['list_stock']['from']) && $action->filters['list_stock']['from'] !== '' || isset($action->filters['list_stock']['to']) && $action->filters['list_stock']['to'] !== '');
if ($has_filter || $action->getUser()->getAttribute('sort', null, 'sf_admin/autoStProduct/depository_sort') == 'list_stock')
{
$c = $event['criteria'];
$sql = sprintf('SELECT SUM(%s) FROM %s WHERE %s = %s AND %s - %s = 1',
ProductOptionsValuePeer::STOCK,
ProductOptionsValuePeer::TABLE_NAME,
ProductOptionsValuePeer::PRODUCT_ID,
ProductPeer::ID,
ProductOptionsValuePeer::RGT,
ProductOptionsValuePeer::LFT
);
$c->addAsColumn('list_stock', sprintf('IF(%s > 1 AND %s = %s, (%s), %s)', ProductPeer::OPT_HAS_OPTIONS, ProductPeer::STOCK_MANAGMENT, ProductPeer::STOCK_PRODUCT_OPTIONS, $sql, ProductPeer::STOCK));
}
if ($has_filter)
{
$having = array();
if ($action->filters['list_stock']['from'] !== '' && $action->filters['list_stock']['to'] !== '' && $action->filters['list_stock']['to'] == $action->filters['list_stock']['from'])
{
$having[] = 'list_stock = '.$action->filters['list_stock']['from'];
}
else
{
if ($action->filters['list_stock']['from'] !== '')
{
$having[] = 'list_stock >= '.floatval(str_replace(',', '.', $action->filters['list_stock']['from']));
}
if ($action->filters['list_stock']['to'] !== '')
{
$having[] = 'list_stock <= '.floatval(str_replace(',', '.', $action->filters['list_stock']['to']));
}
}
$c->addHaving(implode(' AND ', $having));
$action->pager->setPeerCountMethod(array('stDepositoryPluginListener', 'depositoryPeerCoundMethod'));
}
}
public static function depositoryPeerCoundMethod($c)
{
$culture = sfContext::getInstance()->getUser()->getCulture();
$c->clearSelectColumns()->clearOrderByColumns();
$c->addSelectColumn(ProductPeer::ID);
$sql = sprintf('SELECT SUM(%s) FROM %s WHERE %s = %s AND %s - %s = 1',
ProductOptionsValuePeer::STOCK,
ProductOptionsValuePeer::TABLE_NAME,
ProductOptionsValuePeer::PRODUCT_ID,
ProductPeer::ID,
ProductOptionsValuePeer::RGT,
ProductOptionsValuePeer::LFT
);
$c->addAsColumn('list_stock', sprintf('IF(%s > 1 AND %s = %s, (%s), %s)', ProductPeer::OPT_HAS_OPTIONS, ProductPeer::STOCK_MANAGMENT, ProductPeer::STOCK_PRODUCT_OPTIONS, $sql, ProductPeer::STOCK));
// $c->addSelectColumn(ProductPeer::ID);
// $c->addAsColumn('list_stock', sprintf('IFNULL(SUM(%s), %s)', ProductOptionsValuePeer::STOCK, ProductPeer::STOCK));
$c->addJoin(ProductPeer::ID, sprintf('%s AND %s = \'%s\'', ProductI18nPeer::ID, ProductI18nPeer::CULTURE, $culture), Criteria::LEFT_JOIN);
$sql = BasePeer::createSqlQuery($c);
$con = Propel::getConnection($c->getDbName());
$rs = $con->executeQuery('SELECT count(*) as cnt FROM ('.$sql.') as temp');
return $rs->next() ? $rs->getInt('cnt') : 0;
// return ProductPeer::doCountWithI18n($c);
}
/**
* Zmienia wyświetlanie koszyka na disabled gdy jest włączone
* sprawdzanie stany magazynowego, a wartość stock jest ustawiona na 0.
*
* @param sfEvent $event
*/
public static function blockAddBasketButton(sfEvent $event)
{
$config = stConfig::getInstance(sfContext::getInstance(), array('depository_basket' => stConfig::BOOL), 'stProduct');
$config->load();
if ($config->get('depository_basket') == 1)
{
$subject = $event->getSubject();
$depository = stDepository::getStock($subject->product->getId());
if ($depository === 0)
{
$subject->enabled = 0;
}
}
}
/**
* Sprawdza zmiany dokonane w zamówieniu i modyfikuje stany magazynowe
* zgodnie z konfiguracją sklepu.
*
* Tabela do else:
*
* old_status new_status on_change action
* =========================================================
* ST_CANCELED ST_PENDING ST_PENDING decrease
* ST_CANCELED ST_COMPLETE ST_PENDING decrease
*
* ST_PENDING ST_CANCELED ST_PENDING increase
* ST_COMPLETE ST_CANCELED ST_PENDING increase
*
* ST_PENDING ST_COMPLETE ST_PENDING nothing
* ST_COMPLETE ST_PENDING ST_PENDING nothing
*
* ---------------------------------------------------------
*
* ST_CANCELED ST_COMPLETE ST_COMPLETE decrease
* ST_PENDING ST_COMPLETE ST_COMPLETE decrease
*
* ST_COMPLETE ST_PENDING ST_COMPLETE increase
* ST_COMPLETE ST_CANCELED ST_COMPLETE increase
*
* ST_CANCELED ST_PENDING ST_COMPLETE nothing
* ST_PENDING ST_CANCELED ST_COMPLETE nothing
*
* @author Daniel Mendalka
*/
public static function preSaveOrder(sfEvent $event)
{
$config = stConfig::getInstance('stProduct');
if (!$config->get('depository_enabled', true))
{
return;
}
$order = $event->getSubject();
if (null === $order->getChangeStockOn())
{
if ($config->get('get_depository') == 'order')
{
$order->setChangeStockOn('ST_PENDING');
}
elseif ($config->get('get_depository') == 'order_status')
{
$order->setChangeStockOn('ST_COMPLETE');
}
}
if (null !== $order->getChangeStockOn() && $order->isColumnModified(OrderPeer::ORDER_STATUS_ID))
{
$previous_status = $order->getPreviousColumnValue(OrderPeer::ORDER_STATUS_ID) ? OrderStatusPeer::retrieveByPK($order->getPreviousColumnValue(OrderPeer::ORDER_STATUS_ID)) : null;
switch ($order->getChangeStockOn())
{
case 'ST_PENDING':
if ($previous_status && $previous_status->getType() == 'ST_CANCELED')
{
self::decreaseAll($order->getOrderProducts());
}
elseif ($order->getOrderStatus()->getType() == 'ST_CANCELED')
{
self::increaseAll($order->getOrderProducts());
}
ProductHasCategoryPeer::cleanCache();
stFastCacheManager::clearCache(true);
break;
case 'ST_COMPLETE':
if ($previous_status && $previous_status->getType() == 'ST_COMPLETE' && in_array($order->getOrderStatus()->getType(), array('ST_CANCELED', 'ST_PENDING', 'ST_IN_PROGRESS')))
{
self::increaseAll($order->getOrderProducts());
}
elseif ($order->getOrderStatus()->getType() == 'ST_COMPLETE')
{
self::decreaseAll($order->getOrderProducts());
}
ProductHasCategoryPeer::cleanCache();
stFastCacheManager::clearCache(true);
break;
}
}
}
/**
* Remeber that `$eventOrItems` is hack or appShopgatePlugin.
**/
public static function validateOrderSave($eventOrItems, $ok)
{
if ($ok)
{
$config = stConfig::getInstance('stProduct');
if (!$config->get('depository_enabled', true) || $config->get('get_depository') != 'order')
{
return $ok;
}
if(is_array($eventOrItems))
$items = $eventOrItems;
else
$items = sfContext::getInstance()->getUser()->getBasket()->getItems();
foreach ($items as $item)
{
if (!$item->productValidate()) continue;
if ($item->hasPriceModifiers() && $item->getProduct()->hasStockManagmentWithOptions())
{
self::decreaseProductOptions($item);
}
else
{
stDepository::decrease($item->getProduct(), $item->getQuantity());
}
if ($item instanceof BasketProduct && $item->getProductSetDiscountId())
{
$c = new Criteria();
$c->addSelectColumn(DiscountHasProductPeer::PRODUCT_ID);
$c->add(DiscountHasProductPeer::DISCOUNT_ID, $item->getProductSetDiscountId());
$rs = DiscountHasProductPeer::doSelectRs($c);
while($rs->next())
{
$row = $rs->getRow();
stDepository::decrease($row[0], $item->getQuantity());
}
}
}
ProductHasCategoryPeer::cleanCache();
stFastCacheManager::clearCache(true);
}
return $ok;
}
public static function increaseAll($items)
{
foreach ($items as $item)
{
if (!$item->productValidate()) continue;
if ($item->hasPriceModifiers() && $item->getProduct()->hasStockManagmentWithOptions())
{
self::increaseProductOptions($item);
}
else
{
stDepository::increase($item->getProductId(), $item->getQuantity());
}
foreach ($item->getOrderProductHasSets() as $set)
{
if ($set->getProductId() != $item->getProductId())
{
stDepository::increase($set->getProductId(), $item->getQuantity());
}
}
}
}
public static function decreaseAll($items)
{
foreach ($items as $item)
{
if (!$item->productValidate()) continue;
if ($item->hasPriceModifiers() && $item->getProduct()->hasStockManagmentWithOptions())
{
self::decreaseProductOptions($item);
}
else
{
stDepository::decrease($item->getProductId(), $item->getQuantity());
}
foreach ($item->getOrderProductHasSets() as $set)
{
if ($set->getProductId() != $item->getProductId())
{
stDepository::decrease($set->getProductId(), $item->getQuantity());
}
}
}
}
private static function increaseProductOptions($item)
{
$ids = self::getProductOptionsIds($item);
if ($ids)
{
stDepository::increaseProductOptions($ids, $item->getQuantity());
ProductOptionsValuePeer::updateStock($item->getProductId());
AllegroAuctionPeer::updateRequiresSync($item->getProductId(), end($ids));
}
}
private static function decreaseProductOptions($item)
{
$ids = self::getProductOptionsIds($item);
if ($ids)
{
stDepository::decreaseProductOptions($ids, $item->getQuantity());
ProductOptionsValuePeer::updateStock($item->getProductId());
AllegroAuctionPeer::updateRequiresSync($item->getProductId(), end($ids));
}
}
private static function getProductOptionsIds($item)
{
$ids = array();
foreach ($item->getPriceModifiers() as $option)
{
if (isset($option['custom']['id']))
{
$ids[] = $option['custom']['id'];
}
}
return $ids;
}
}

View File

@@ -0,0 +1,76 @@
<?php
/**
* SOTESHOP/stDepositoryPlugin
*
* Ten plik należy do aplikacji stDepositoryPlugin opartej na licencji (Professional License 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 stDepositoryPlugin
* @subpackage libs
* @copyright SOTE (www.sote.pl)
* @license http://www.sote.pl/license/sote (Professional License SOTE)
* @version $Id: stPropelProduct.class.php 1942 2009-06-30 14:19:44Z krzysiek $
* @author Krzysztof Bebło <krzysztof.beblo@sote.pl>
*/
/**
* stDepositoryFrontend
*
* @author Krzysztof Bebło <krzysztof.beblo@sote.pl>
* @package stDepositoryPlugin
* @subpackage libs
*/
class stPropelProduct
{
/**
* statyczna funkcje pobierania stanu magazynowego dla importu eksportu
*
* @param Product $product
* @return string
*/
public static function getProductDepository(Product $product)
{
if (!$product->hasStockManagmentWithOptions())
{
$stock = $product->getStock();
}
else
{
$c = new Criteria();
$c->addSelectColumn('SUM('.ProductOptionsValuePeer::STOCK.')');
$c->add(ProductOptionsValuePeer::PRODUCT_ID, $product->getId());
$c->add(ProductOptionsValuePeer::LFT, sprintf('%s - %s = 1', ProductOptionsValuePeer::RGT, ProductOptionsValuePeer::LFT) , Criteria::CUSTOM);
$rs = ProductOptionsValuePeer::doSelectRS($c);
$stock = $rs->next() ? $rs->get(1) : 0;
}
return stPrice::round($stock);
}
/**
* statyczna funkcje pobierania stanu magazynowego dla importu eksportu
*
* @param Product $product
* @param string $value
*/
public static function setProductDepository(Product $product, $value = '')
{
if (!$product->hasStockManagmentWithOptions())
{
if (is_numeric($value))
{
$product->setStock($value);
}
else
{
$product->setStock(NULL);
}
}
}
}
?>