first commit
This commit is contained in:
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
class stInPostParcelSizeValidator extends sfValidator
|
||||
{
|
||||
public function initialize($context, $parameters = array())
|
||||
{
|
||||
$result = parent::initialize($context, $parameters);
|
||||
|
||||
$this->setParameter('allegro_courier_error', 'Paczka %%number%% - Suma wymiarów paczki nie może być większa niż %%max_package_dimension_sum%%cm, maksymalna długość boku %%max_size%%cm, maksymalna waga %%max_weight%%kg');
|
||||
$this->setParameter('inpost_courier_standard_error', 'Paczka %%number%% - Maksymalne wymiary paczki %%max_dimensions%%cm, maksymalna waga %%max_weight%%kg');
|
||||
$this->setParameter('inpot_minimum_dimensions', 'Paczka %%number%% - Wymiary oraz waga przesyłki musi być większa od 0');
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function execute(&$parcels, &$error)
|
||||
{
|
||||
$parcelsErrors = [];
|
||||
$parcelNumber = 0;
|
||||
|
||||
$service = $this->getParameter('service');
|
||||
|
||||
$i18n = $this->getContext()->getI18N();
|
||||
|
||||
foreach ($parcels as $parcel)
|
||||
{
|
||||
$parcelNumber++;
|
||||
|
||||
if (empty($parcel['weight']) || empty($parcel['width']) || empty($parcel['height']) || empty($parcel['length']))
|
||||
{
|
||||
$parcelsErrors[] = $i18n->__($this->getParameter('inpot_minimum_dimensions'), [
|
||||
'%%number%%' => '#' . $parcelNumber,
|
||||
]);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$packageDimensionSum = $parcel['width'] + $parcel['height'] + $parcel['length'];
|
||||
|
||||
if ($service == 'inpost_courier_allegro' && ($parcel['weight'] > 30 || $packageDimensionSum > 160 || $parcel['width'] > 80 || $parcel['height'] > 80 || $parcel['length'] > 80))
|
||||
{
|
||||
$parcelsErrors[] = $i18n->__($this->getParameter('allegro_courier_error'), [
|
||||
'%%number%%' => '#' . $parcelNumber,
|
||||
'%%max_package_dimension_sum%%' => 160,
|
||||
'%%max_size%%' => 80,
|
||||
'%%max_weight%%' => 30,
|
||||
]);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($service == 'inpost_letter_allegro' && ($parcel['weight'] > 10 || $packageDimensionSum > 160 || $parcel['width'] > 80 || $parcel['height'] > 80 || $parcel['length'] > 80))
|
||||
{
|
||||
$parcelsErrors[] = $i18n->__($this->getParameter('allegro_courier_error'), [
|
||||
'%%number%%' => '#' . $parcelNumber,
|
||||
'%%max_package_dimension_sum%%' => 160,
|
||||
'%%max_size%%' => 80,
|
||||
'%%max_weight%%' => 10,
|
||||
]);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($service == 'inpost_courier_standard' && ($parcel['weight'] > 50 || $parcel['width'] > 240 || $parcel['height'] > 350 || $parcel['length'] > 240))
|
||||
{
|
||||
$parcelsErrors[] = $i18n->__($this->getParameter('inpost_courier_standard_error'), [
|
||||
'%%number%%' => '#' . $parcelNumber,
|
||||
'%%max_weight%%' => 50,
|
||||
'%%max_dimensions%%' =>'240x240x350',
|
||||
]);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($parcel['weight'] > 50 || $parcel['width'] > 240 || $parcel['height'] > 350 || $parcel['length'] > 240)
|
||||
{
|
||||
$parcelsErrors[] = $i18n->__($this->getParameter('inpost_courier_standard_error'), [
|
||||
'%%number%%' => '#' . $parcelNumber,
|
||||
'%%max_weight%%' => 30,
|
||||
'%%max_dimensions%%' =>'240x240x350',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($parcelsErrors))
|
||||
{
|
||||
$error = $parcelsErrors;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user