first commit
This commit is contained in:
@@ -0,0 +1,142 @@
|
||||
<?php
|
||||
|
||||
class AllegroApiShippingRatePeer
|
||||
{
|
||||
const TABLE_NAME = 'st_allegro_api_shipping_rate';
|
||||
|
||||
const ID = self::TABLE_NAME.'.id';
|
||||
const NAME = self::TABLE_NAME.'.name';
|
||||
const LAST_MODIFIED = self::TABLE_NAME.'.last_modified';
|
||||
|
||||
/**
|
||||
* Ostatnio wykonane kryteria
|
||||
*
|
||||
* @var Criteria
|
||||
*/
|
||||
protected static $lastCriteria = null;
|
||||
|
||||
protected static $lastResults = null;
|
||||
|
||||
/**
|
||||
* Zwraca cennik dostawy według GUID
|
||||
*
|
||||
* @param string $id GUID
|
||||
* @return AllegroApiShippingRate
|
||||
*/
|
||||
public static function retrieveByPK($id)
|
||||
{
|
||||
$rates = array();
|
||||
|
||||
$shippingRate = stAllegroApi::getInstance()->getShippingRate($id);
|
||||
|
||||
foreach ($shippingRate->rates as $methodId => $rate)
|
||||
{
|
||||
$rates[$methodId] = array(
|
||||
'first_item_rate' => array(
|
||||
'amount' => $rate->firstItemRate->amount,
|
||||
'currency' => $rate->firstItemRate->currency,
|
||||
'default' => 0.00
|
||||
),
|
||||
'next_item_rate' => array(
|
||||
'amount' => $rate->nextItemRate->amount,
|
||||
'currency' => $rate->firstItemRate->currency,
|
||||
'default' => 0.00
|
||||
),
|
||||
'max_quantity_per_package' => $rate->maxQuantityPerPackage,
|
||||
);
|
||||
}
|
||||
|
||||
$allegroApiShippingRate = new AllegroApiShippingRate();
|
||||
$allegroApiShippingRate->setId($shippingRate->id);
|
||||
$allegroApiShippingRate->setName($shippingRate->name);
|
||||
$allegroApiShippingRate->setRates($rates);
|
||||
$allegroApiShippingRate->setLastModified($shippingRate->lastModified ? strtotime($shippingRate->lastModified) : null);
|
||||
$allegroApiShippingRate->setNew(false);
|
||||
|
||||
return $allegroApiShippingRate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Zwraca cennik dostaw na podstawie przekazanych kryteriów
|
||||
*
|
||||
* @param Criteria $c Kryteria
|
||||
* @return AllegroApiShippingRate
|
||||
*/
|
||||
public static function doSelectOne(Criteria $c)
|
||||
{
|
||||
$results = self::doSelect($c);
|
||||
|
||||
return $results ? $results[0] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Zwraca tablicę cenników dostaw na podstawie przekazanych kryteriów
|
||||
*
|
||||
* @param Criteria $c Kryteria
|
||||
* @return AllegroApiShippingRate[]
|
||||
*/
|
||||
public static function doSelect(Criteria $c)
|
||||
{
|
||||
if (null === self::$lastCriteria || !self::$lastCriteria->equals($c))
|
||||
{
|
||||
$results = array();
|
||||
|
||||
$query = trim($c->get(self::NAME), '%');
|
||||
|
||||
foreach (stAllegroApi::getInstance()->getShippingRates() as $shippingRate)
|
||||
{
|
||||
if (null === $query || "" === $query || false !== stripos($shippingRate->name, $query))
|
||||
{
|
||||
$allegroApiShippingRate = new AllegroApiShippingRate();
|
||||
$allegroApiShippingRate->setId($shippingRate->id);
|
||||
$allegroApiShippingRate->setName($shippingRate->name);
|
||||
$allegroApiShippingRate->setNew(false);
|
||||
$results[] = $allegroApiShippingRate;
|
||||
}
|
||||
}
|
||||
|
||||
self::$lastCriteria = $c;
|
||||
self::$lastResults = array_slice($results, $c->getOffset(), $c->getLimit() > 0 ? $c->getLimit() : null);
|
||||
}
|
||||
|
||||
return self::$lastResults;
|
||||
}
|
||||
|
||||
public static function doCount(Criteria $c)
|
||||
{
|
||||
$c = clone $c;
|
||||
|
||||
$c->clearOrderByColumns();
|
||||
$c->setOffset(0);
|
||||
$c->setLimit(null);
|
||||
|
||||
$results = self::doSelect($c);
|
||||
|
||||
return count($results);
|
||||
}
|
||||
|
||||
public static function getMapBuilder()
|
||||
{
|
||||
return BasePeer::getMapBuilder(AllegroApiShippingRateMapBuilder::CLASS_NAME);
|
||||
}
|
||||
|
||||
public static function translateFieldName($name, $fromType, $toType)
|
||||
{
|
||||
return $name;
|
||||
}
|
||||
}
|
||||
|
||||
// static code to register the map builder for this Peer with the main Propel class
|
||||
if (Propel::isInit()) {
|
||||
// the MapBuilder classes register themselves with Propel during initialization
|
||||
// so we need to load them here.
|
||||
try {
|
||||
AllegroApiShippingRatePeer::getMapBuilder();
|
||||
} catch (Exception $e) {
|
||||
Propel::log('Could not initialize Peer: ' . $e->getMessage(), Propel::LOG_ERR);
|
||||
}
|
||||
} else {
|
||||
// even if Propel is not yet initialized, the map builder class can be registered
|
||||
// now and then it will be loaded when Propel initializes.
|
||||
Propel::registerMapBuilder(AllegroApiShippingRateMapBuilder::CLASS_NAME);
|
||||
}
|
||||
Reference in New Issue
Block a user