first commit
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
class stAllegroImageValidator extends sfValidator {
|
||||
|
||||
public function execute(&$value, &$error) {
|
||||
if (isset($value['selected']) && count($value['selected']) > 16) {
|
||||
$error = $this->getParameter('msg');
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function initialize($context, $parameters = null) {
|
||||
parent::initialize($context);
|
||||
$this->getParameterHolder()->add($parameters);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
class stAllegroProductOptionsValidator extends sfValidator {
|
||||
|
||||
public function execute(&$value, &$error) {
|
||||
$product = ProductPeer::retrieveByPk($this->getContext()->getRequest()->getParameter('product_id', null));
|
||||
|
||||
if (is_object($product)) {
|
||||
if (empty($value) && $product->getOptHasOptions() > 1) {
|
||||
$error = $this->getParameter('msg');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function initialize($context, $parameters = null) {
|
||||
parent::initialize($context);
|
||||
$this->getParameterHolder()->add($parameters);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
class stAllegroStockValidator extends sfValidator {
|
||||
|
||||
public function execute(&$value, &$error) {
|
||||
|
||||
if (empty($value)) {
|
||||
$error = $this->getParameter('zero_msg');
|
||||
return false;
|
||||
}
|
||||
|
||||
$auction = $this->getContext()->getRequest()->getParameter('allegro_auction', null);
|
||||
|
||||
$product = ProductPeer::retrieveByPk($this->getContext()->getRequest()->getParameter('product_id', null));
|
||||
if (is_object($product)) {
|
||||
if ($product->getOptHasOptions() > 1) {
|
||||
if (!isset($auction['product_options'])) {
|
||||
$error = $this->getParameter('null_options');
|
||||
return false;
|
||||
}
|
||||
$ids = explode(',', $auction['product_options']);
|
||||
$options = ProductOptionsValuePeer::retrieveByPKs($ids);
|
||||
stNewProductOptions::updateProductBySelectedOptions($product, $options);
|
||||
}
|
||||
|
||||
$stock = (int) $product->getStock();
|
||||
|
||||
$productConfig = stConfig::getInstance('stProduct');
|
||||
if ($productConfig->get('depository_enabled'))
|
||||
if ($value > $stock) {
|
||||
$error = $this->getParameter('stock_msg');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function initialize($context, $parameters = null) {
|
||||
parent::initialize($context);
|
||||
$this->getParameterHolder()->add($parameters);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
class stAllegroVariantsValidator extends sfValidator {
|
||||
|
||||
public function execute(&$value, &$error) {
|
||||
|
||||
$product = ProductPeer::retrieveByPk($this->getContext()->getRequest()->getParameter('product_id', null));
|
||||
|
||||
$i18n = $this->getContext()->getI18n();
|
||||
|
||||
$variant = null;
|
||||
foreach ($value['attributes'] as $attributeId => $attribute) {
|
||||
$attributeJson = json_decode($attribute['attribute'], true);
|
||||
if ($attributeJson['sellFormTitle'] == 'Rozmiar') {
|
||||
$variant = $attribute;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($variant !== null) {
|
||||
$size = array_combine(explode('|', $attributeJson['sellFormOptsValues']), explode('|', $attributeJson['sellFormDesc']));
|
||||
if ($product->getOptHasOptions() > 1) {
|
||||
|
||||
if (!isset($variant['value']) || empty($variant['value'])) {
|
||||
$error = $i18n->__('<b>(Rozmiar)</b> - proszę wybrać minimuj jedną opcje.');
|
||||
return false;
|
||||
}
|
||||
|
||||
$variant['options'];
|
||||
foreach ($variant['value'] as $id) {
|
||||
if (empty($variant['quantity'][$id])) {
|
||||
$error = $i18n->__('<b>(Rozmiar: %size%)</b> - ilość produktów do wystawienia musi być większa od 0.', array('%size%' => $size[$id]));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!isset($variant['options'][$id]) && empty($variant['options'][$id])) {
|
||||
$error = $i18n->__('<b>(Rozmiar: %size%)</b> - każda opcja musi mieć wybraną opcje produktów.', array('%size%' => $size[$id]));
|
||||
return false;
|
||||
}
|
||||
|
||||
$options = ProductOptionsValuePeer::retrieveByPKs(explode(',', $variant['options'][$id]));
|
||||
stNewProductOptions::updateProductBySelectedOptions($product, $options);
|
||||
|
||||
if ($variant['quantity'][$id] > $product->getStock()) {
|
||||
$error = $i18n->__('<b>(Rozmiar: %size%)</b> - brak dostępnej ilości produktów w magazynie.', array('%size%' => $size[$id]));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$sumStock = 0;
|
||||
foreach ($variant['quantity'] as $key => $quantity) {
|
||||
if (isset($variant['value'][$key])) {
|
||||
$sumStock += (int) $quantity;
|
||||
if ((int) $quantity == 0) {
|
||||
$error = $i18n->__('<b>(Rozmiar: %size%)</b> - ilość produktów do wystawienia musi być większa od 0.', array('%size%' => $size[$id]));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($sumStock > $product->getStock()) {
|
||||
$error = $i18n->__('<b>(Rozmiar: %size%)</b> - brak dostępnej ilości produktów w magazynie.', array('%size%' => $size[$id]));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function initialize($context, $parameters = null) {
|
||||
parent::initialize($context);
|
||||
$this->getParameterHolder()->add($parameters);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user