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,664 @@
<?php
class AllegroApiOffer extends BaseObject implements Persistent
{
/**
* Oferta allegro
*
* @var object|null
*/
protected $allegroOffer;
/**
* Wybrane opcje produktu
*
* @var array|null
*/
protected $selectedProductOptionsIds = null;
/**
* Oferta Allegro po stronie sklepu
*
* @var AllegroAuction
*/
protected $allegroAuction = null;
public function buildPkeyCriteria()
{
$c = new Criteria();
$c->add(constant($this->getPeer().'::ID'), $this->getId());
return $c;
}
public function getPeer()
{
return get_class($this).'Peer';
}
public function getPrimaryKeyFields($keyType = BasePeer::TYPE_FIELDNAME)
{
$fields = call_user_func(array($this->getPeer(), 'translateFieldName'), 'id', BasePeer::TYPE_FIELDNAME, $keyType);
return array($fields);
}
public function setAfterSalesServices(array $afterSalesServices)
{
foreach ($afterSalesServices as $index => $service)
{
if (empty($service['id']))
{
$service = null;
}
$afterSalesServices[$index] = $service;
}
$this->__call('setAfterSalesServices', [$afterSalesServices]);
}
public function __toString()
{
return $this->getAdminGeneratorTitle();
}
/**
* Undocumented function
*
* @param object|null $allegroOffer
*/
public function __construct($allegroOffer = null)
{
$this->allegroOffer = $allegroOffer;
if (null === $this->allegroOffer)
{
$this->allegroOffer = stAllegroApi::arrayToObject(array(
'product' => null,
'category' => null,
'parameters' => null,
'publication' => null,
'afterSalesServices' => null,
'sizeTable' => null,
'discounts' => null,
'location' => null,
'images' => null,
'tax' => null,
'name' => null,
'external' => null,
'sellingMode' => null,
'stock' => null,
'description' => null,
'delivery' => null,
'payments' => null,
));
}
try
{
if (!isset($allegroOffer->location))
{
$config = stConfig::getInstance('stAllegroBackend');
$this->setLocation(array(
'city' => $config->get('allegro_pl_city'),
'countryCode' => 'PL',
'postCode' => $config->get('allegro_pl_post_code'),
'province' => strtoupper($config->get('allegro_pl_state')),
));
}
}
catch (Exception $e)
{
}
}
public function getAdminGeneratorTitle()
{
return $this->getName() . ' ('.$this->getId().')';
}
public function __clone()
{
if (!$this->isNew())
{
$duration = $this->getPublication()->duration;
$this->allegroOffer->publication = null;
$this->setPublication(array(
'duration' => $duration,
'status' => stAllegroApi::STATUS_INACTIVE,
));
unset($this->allegroOffer->validation);
unset($this->allegroOffer->updatedAt);
unset($this->allegroOffer->createdAt);
$this->setNew(true);
$allegroAuction = new AllegroAuction();
$allegroAuction->fromArray($this->getAllegroAuction()->toArray());
$allegroAuction->setId(null);
$allegroAuction->setCreatedAt(null);
$allegroAuction->setUpdatedAt(null);
$allegroAuction->setCommands(null);
$allegroAuction->setEnded(null);
$allegroAuction->setEndedAt(null);
$this->allegroAuction = $allegroAuction;
$this->allegroOffer->id = null;
}
}
public function setFromArray(array $data)
{
foreach ($data as $name => $value)
{
$property = 'set'.lcfirst(sfInflector::camelize($name));
if ($name == 'description' && $value && !is_array($value))
{
$value = json_decode($value);
}
$this->$property($value);
}
}
public function getPrimaryKey()
{
return $this->getId();
}
public function setPrimaryKey($primaryKey)
{
$this->allegroOffer->id = $primaryKey;
}
/**
* Zwraca GUID oferty
*
* @return string
*/
public function getId()
{
return isset($this->allegroOffer->id) ? $this->allegroOffer->id : null;
}
public function getAllowSync()
{
return $this->getAllegroAuction()->getAllowSync();
}
public function setAllowSync($allowSync)
{
$this->getAllegroAuction()->setAllowSync($allowSync);
}
/**
* Zwraca ofertę Allegro po stronie sklepu
*
* @return AllegroAuction
*/
public function getAllegroAuction()
{
if (null === $this->allegroAuction)
{
$allegroAuction = $this->getId() ? AllegroAuctionPeer::retrieveByAuctionNumber($this->getId()) : null;
if (null === $allegroAuction)
{
$allegroAuction = new AllegroAuction();
$allegroAuction->setName($this->getName());
$allegroAuction->setAuctionId($this->getId());
}
$this->allegroAuction = $allegroAuction;
}
return $this->allegroAuction;
}
/**
* Wystaw ofertę
*
* @return $this
* @throws stAllegroException
* @throws PropelException
*/
public function publish()
{
$api = stAllegroApi::getInstance();
$response = $api->publishOffers(array($this->getId()));
$this->getAllegroAuction()->addCommand($response->id, 'publish');
$this->getAllegroAuction()->setEnded(null);
$this->getAllegroAuction()->setEndedAt(null);
$this->getAllegroAuction()->save();
return $this;
}
/**
* Zakończ ofertę
*
* @return $this
* @throws stAllegroException
* @throws PropelException
*/
public function end()
{
$api = stAllegroApi::getInstance();
$api->publishOffers(array($this->getId()), false);
$this->getAllegroAuction()->setAllowSync(false);
$this->getAllegroAuction()->save();
return $this;
}
public function getStatusLabel()
{
$enum = stAllegroApi::getStatusList();
return isset($enum[$this->getPublication()->status]) ? $enum[$this->getPublication()->status] : '';
}
public function getPrimaryImage()
{
return $this->allegroOffer->primaryImage ? $this->allegroOffer->primaryImage->url : null;
}
public function getStockSold()
{
return $this->getStock()->sold;
}
public function getStockAvailable()
{
return $this->getStock()->available;
}
public function getShopProductStock()
{
$stock = null;
if ($this->getShopProduct())
{
stNewProductOptions::clearCache($this->getShopProduct());
$this->getAllegroAuction()->getProductOptionsArray();
$stock = $this->getShopProduct()->getStock();
}
return $stock;
}
/**
* Ustawia powiązanie produktu z ofertą
*
* @param Product $product
* @return self
*/
public function setShopProduct(Product $product = null)
{
if (null !== $product)
{
$this->getAllegroAuction()->setProduct($product);
$this->setShopProductId($product->getId());
}
return $this;
}
/**
* Zwraca powiązany produkt z ofertą
*
* @return Product
*/
public function getShopProduct()
{
return $this->getAllegroAuction()->getProduct();
}
public function getShopProductCode()
{
return $this->getAllegroAuction()->getProduct() ? $this->getAllegroAuction()->getProduct()->getCode() : null;
}
public function setProductId($id)
{
$this->setShopProductId($id);
}
public function getProductId()
{
return $this->getShopProductId();
}
/**
* Ustawia id powiązanego produktu z ofertą
*
* @param int $id
* @return self
*/
public function setShopProductId($id)
{
$this->getAllegroAuction()->setProductId($id);
$this->setExternal(array('id' => $id));
return $this;
}
/**
* Zwraca id powiązanego produktu z ofertą
*
* @return int
*/
public function getShopProductId()
{
return $this->getShopProduct() ? $this->getShopProduct()->getId() : null;
}
/**
* Zwraca nazwę
*
* @return string|null
*/
public function getName()
{
return $this->allegroOffer ? $this->allegroOffer->name : null;
}
/**
* Ustawia nazwę
*
* @param string $name Nazwa oferty
*
* @return self
*/
public function setName(string $name)
{
$this->allegroOffer->name = $name;
return $this;
}
public function setParameters(array $parameters)
{
$this->allegroOffer->parameters = array();
if (is_numeric(key($parameters)))
{
foreach ($parameters as $parameter)
{
$this->allegroOffer->parameters[$parameter['id']] = stAllegroApi::arrayToObject($parameter);
}
}
else
{
$this->allegroOffer->parameters = $this->transformOfferParameters($parameters);
}
}
public function setShopProductOptions($v)
{
$this->getAllegroAuction()->setProductOptions($v);
}
public function getShopProductOptions()
{
return $this->getAllegroAuction()->getProductOptions();
}
public function isAdminGeneratorActionVisible($name)
{
return $name == 'preview' && $this->getPublication()->status == stAllegroApi::STATUS_ACTIVE ||
$name == 'duplicate' && ($this->getPublication()->status == stAllegroApi::STATUS_ACTIVE || $this->getPublication()->status == stAllegroApi::STATUS_ENDED) ||
$name == '_delete';
}
public function getIsSystemDefault()
{
return $this->getPublication()->status != stAllegroApi::STATUS_INACTIVE;
}
public function getOfferUrl()
{
return stAllegroApi::getOfferUrl($this->getId());
}
public function delete($con = null)
{
stAllegroApi::getInstance()->deleteDraftOffer($this->getId());
}
public function save($con = null)
{
$config = stConfig::getInstance('stAllegroBackend');
$productChanged = $this->getAllegroAuction()->isColumnModified(AllegroAuctionPeer::PRODUCT_ID) || $this->getAllegroAuction()->isColumnModified(AllegroAuctionPeer::PRODUCT_OPTIONS);
if ($this->isNew())
{
$response = stAllegroApi::getInstance()->createOffer($this->allegroOffer);
$this->allegroOffer = $response;
if (null === $this->allegroAuction)
{
$this->allegroAuction = new AllegroAuction();
$this->allegroAuction->setName($response->name);
}
$this->allegroAuction->setAuctionId($response->id);
$this->allegroAuction->save();
$this->setNew(false);
}
else
{
$this->allegroAuction->save();
$product = $this->getAllegroAuction()->getProduct();
if ($productChanged)
{
$this->getAllegroAuction()->getProductOptionsArray();
if ($config->get('offer_sync_product_price'))
{
$commision = new AllegroCommission();
$this->allegroOffer->sellingMode->price->amount = $commision->calculatePrice($product->getPriceBrutto());
}
}
$response = stAllegroApi::getInstance()->updateOffer($this->getId(), $this->allegroOffer);
if ($response->validation && $response->validation->errors)
{
$this->allegroOffer->validation = $response->validation;
}
else
{
$this->allegroOffer = $response;
if ($productChanged)
{
$priceModifiers = $product->getPriceModifiers();
/**
* @see BasketProduct::setPriceModifiers()
**/
foreach ($priceModifiers as $index => $value) {
if (isset($value['custom']['label'])) {
$label = $value['custom']['label'];
unset($value['custom']['label']);
$value['label'] = $label;
$priceModifiers[$index] = $value;
}
}
$stmt = Propel::getConnection()->prepareStatement(sprintf('UPDATE %s SET %s = ?, %s = ?, %s = ?, %s = ?, %s = ? WHERE %s = ?', OrderProductPeer::TABLE_NAME, OrderProductPeer::CODE, OrderProductPeer::IMAGE, OrderProductPeer::NAME, OrderProductPeer::PRODUCT_ID, OrderProductPeer::PRICE_MODIFIERS, OrderProductPeer::ALLEGRO_AUCTION_ID));
$stmt->setString(1, $product->getCode());
$stmt->setString(2, $product->getOptImage());
$stmt->setString(3, $config->get('import_product_name', 'offer') == 'offer' ? $this->getName() : $product->getName());
$stmt->setInt(4, $product->getId());
$stmt->setString(5, serialize($priceModifiers));
$stmt->setString(6, $this->getId());
$stmt->executeQuery();
}
}
}
return true;
}
public function __call($name, $arguments)
{
$type = substr($name, 0, 3);
$property = lcfirst(substr($name, 3));
if (property_exists($this->allegroOffer, $property))
{
if ($type == 'get')
{
return $this->allegroOffer->$property;
}
elseif ($type == 'set')
{
$this->setAllegroApiParameter($property, $arguments[0]);
return;
}
}
throw new \BadMethodCallException('Method does not exist.');
}
protected function setAllegroApiParameter($name, $value)
{
if (is_array($value))
{
if (!isset($value[0]))
{
$this->allegroOffer->$name = stAllegroApi::arrayToObject(array_merge((array)$this->allegroOffer->$name, $value), true);
}
else
{
$this->allegroOffer->$name = stAllegroApi::arrayToObject($value, true);
}
}
else
{
$this->allegroOffer->$name = !empty($value) ? $value : null;
}
}
protected function transformOfferParameters(array $data)
{
$parameters = array();
foreach ($data as $type => $values)
{
switch($type)
{
case 'dictionary':
foreach ($values as $id => $value)
{
if ($value && $value['value'])
{
$parameter = new stdClass();
$parameter->id = $id;
$parameter->valuesIds = is_array($value['value']) ? $value['value'] : array($value['value']);
if (isset($value['custom']) && !empty($value['custom']))
{
$parameter->values = array($value['custom']);
}
$parameters[$id] = $parameter;
}
}
break;
case 'float':
case 'integer':
foreach ($values as $id => $value)
{
$parameter = new stdClass();
$parameter->id = $id;
if (is_array($value))
{
$parameter->rangeValue = new stdClass();
$parameter->rangeValue->from = $value['from'];
$parameter->rangeValue->to = $value['to'];
if ($value['from'] !== "" || $value['to'] !== "")
{
$parameters[$id] = $parameter;
}
}
else
{
$parameter->values = array($value);
if ($value !== "")
{
$parameters[$id] = $parameter;
}
}
}
break;
case 'string':
foreach ($values as $id => $value)
{
$parameter = new stdClass();
$parameter->id = $id;
if (is_array($value))
{
$parameter->values = array();
foreach ($value as $v)
{
if ($v)
{
$parameter->values[] = $v;
}
}
if ($parameter->values)
{
$parameters[$id] = $parameter;
}
}
else
{
$parameter->values = array($value);
if ($value)
{
$parameters[$id] = $parameter;
}
}
}
break;
}
}
return $parameters;
}
}

View File

@@ -0,0 +1,53 @@
<?php
class AllegroApiOfferMapBuilder
{
/**
* The (dot-path) name of this class
*/
const CLASS_NAME = 'plugins.stAllegroPlugin.lib.model.AllegroApiOfferMapBuilder';
/**
* The database map.
*/
private $dbMap;
/**
* Tells us if this DatabaseMapBuilder is built so that we
* don't have to re-build it every time.
*
* @return boolean true if this DatabaseMapBuilder is built, false otherwise.
*/
public function isBuilt()
{
return ($this->dbMap !== null);
}
/**
* Gets the databasemap this map builder built.
*
* @return the databasemap
*/
public function getDatabaseMap()
{
return $this->dbMap;
}
/**
* The doBuild() method builds the DatabaseMap
*
* @return void
* @throws PropelException
*/
public function doBuild()
{
$this->dbMap = Propel::getDatabaseMap('propel');
$tMap = $this->dbMap->addTable('st_allegro_api_offer');
$tMap->setPhpName('AllegroApiOffer');
$tMap->addPrimaryKey('ID', 'Id', 'string', CreoleTypes::CHAR, true, 38);
$tMap->addColumn('NAME', 'Name', 'string', CreoleTypes::VARCHAR, true, 255);
} // doBuild()
}

View File

@@ -0,0 +1,190 @@
<?php
class AllegroApiOfferPeer
{
const TABLE_NAME = 'st_allegro_api_offer';
const ID = self::TABLE_NAME.'.id';
const NAME = self::TABLE_NAME.'.name';
const STATUS = self::TABLE_NAME.'.status';
const PRICE_AMOUNT_FROM = self::TABLE_NAME.'.price_amount_from';
const PRICE_AMOUNT_TO = self::TABLE_NAME.'.price_amount_to';
const PRODUCT_CODE = self::TABLE_NAME.'.product_code';
const SHOP_PRODUCT = self::TABLE_NAME.'.external_id';
const PRODUCT_ID = self::TABLE_NAME.'.product_id';
const ALLEGRO_FIELD_MAPPING = array(
self::ID => 'offer.id',
self::NAME => 'name',
self::STATUS => 'publication.status',
self::PRICE_AMOUNT_FROM => 'sellingMode.price.amount.gte',
self::PRICE_AMOUNT_TO => 'sellingMode.price.amount.lte',
self::SHOP_PRODUCT => 'external.id',
self::PRODUCT_ID => 'external.id',
);
public static function getAllegroField($field)
{
return isset(self::ALLEGRO_FIELD_MAPPING[$field]) ? self::ALLEGRO_FIELD_MAPPING[$field] : null;
}
/**
* Ostatnio wykonane kryteria
*
* @var Criteria
*/
protected static $lastCriteria = null;
protected static $lastResults = null;
/**
* Zwraca cennik dostawy według GUID
*
* @param string $id GUID
* @return AllegroApiOffer
*/
public static function retrieveByPK($id)
{
$response = stAllegroApi::getInstance()->getOffer($id);
// throw new Exception("<pre>".var_export($response, true)."</pre>");
$allegroApiOffer = new AllegroApiOffer($response);
$allegroApiOffer->setNew(false);
return $allegroApiOffer;
}
/**
* Zwraca cennik dostaw na podstawie przekazanych kryteriów
*
* @param Criteria $c Kryteria
* @return AllegroApiOffer
*/
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 AllegroApiOffer[]
*/
public static function doSelect(Criteria $c)
{
if (null === self::$lastCriteria || !self::$lastCriteria->equals($c))
{
$results = array();
$response = self::getAllegroApiOffersResponse($c);
foreach ($response->offers as $offer)
{
$allegroApiOffer = new AllegroApiOffer($offer);
$allegroApiOffer->setNew(false);
$results[] = $allegroApiOffer;
}
self::$lastCriteria = $c;
self::$lastResults = $results;
}
return self::$lastResults;
}
public static function doCount(Criteria $c)
{
$c = clone $c;
$c->clearOrderByColumns();
$c->setOffset(0);
$c->setLimit(null);
$response = self::getAllegroApiOffersResponse($c);
return $response->totalCount;
}
/**
* Zwraca oferty z Allegro API
*
* @param Criteria $c Kryteria
* @return object
* @throws stAllegroException
*/
protected static function getAllegroApiOffersResponse(Criteria $c)
{
$params = array(
'limit' => $c->getLimit(),
'offset' => $c->getOffset(),
'sellingMode.format' => 'BUY_NOW'
);
if (null !== $c->get(self::STATUS) && "" !== $c->get(self::STATUS))
{
$params['publication.status'] = $c->get(self::STATUS);
}
if (null !== $c->get(self::ID) && "" !== $c->get(self::ID))
{
$params[self::getAllegroField(self::ID)] = $c->get(self::ID);
}
if (null !== $c->get(self::NAME) && "" !== $c->get(self::NAME))
{
$params[self::getAllegroField(self::NAME)] = trim($c->get(self::NAME), '%');
}
if (null !== $c->get(self::PRICE_AMOUNT_FROM) && "" !== $c->get(self::PRICE_AMOUNT_FROM))
{
$params[self::getAllegroField(self::PRICE_AMOUNT_FROM)] = $c->get(self::PRICE_AMOUNT_FROM);
}
if (null !== $c->get(self::PRICE_AMOUNT_TO) && "" !== $c->get(self::PRICE_AMOUNT_TO))
{
$params[self::getAllegroField(self::PRICE_AMOUNT_TO)] = $c->get(self::PRICE_AMOUNT_TO);
}
if (null !== $c->get(self::SHOP_PRODUCT) && "" !== $c->get(self::SHOP_PRODUCT))
{
$params[self::getAllegroField(self::SHOP_PRODUCT)] = $c->get(self::SHOP_PRODUCT);
}
if (null !== $c->get(self::PRODUCT_ID) && "" !== $c->get(self::PRODUCT_ID))
{
$params[self::getAllegroField(self::PRODUCT_ID)] = $c->get(self::PRODUCT_ID);
}
return stAllegroApi::getInstance()->getOffers($params);
}
public static function getMapBuilder()
{
return BasePeer::getMapBuilder(AllegroApiOfferMapBuilder::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 {
AllegroApiOfferPeer::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(AllegroApiOfferMapBuilder::CLASS_NAME);
}

View File

@@ -0,0 +1,195 @@
<?php
class AllegroApiShippingRate extends BaseObject implements Persistent
{
/**
* GUID cennika dostaw
*
* @var string
*/
protected $id;
/**
* Nazwa cennika dostaw
*
* @var string
*/
protected $name;
/**
* Data ostatniej modyfikacji cennika dostaw
*
* @var int|null
*/
protected $lastModified;
/**
* Lista stawek cennika dostaw
*
* @var array|null
*/
protected $rates;
public function buildPkeyCriteria()
{
$c = new Criteria();
$c->add(constant($this->getPeer().'::ID'), $this->getId());
return $c;
}
public function getPeer()
{
return get_class($this).'Peer';
}
public function getPrimaryKeyFields($keyType = BasePeer::TYPE_FIELDNAME)
{
$fields = call_user_func(array($this->getPeer(), 'translateFieldName'), 'id', BasePeer::TYPE_FIELDNAME, $keyType);
return array($fields);
}
public function getPrimaryKey()
{
return $this->id;
}
public function setPrimaryKey($primaryKey)
{
$this->id = $primaryKey;
}
/**
* Zwraca GUID cennika dostaw
*
* @return string
*/
public function getId()
{
return $this->id;
}
/**
* Ustawia GUID cennika dostaw
*
* @param string $id GUID cennika dostaw
*
* @return self
*/
public function setId(string $id)
{
$this->id = $id;
return $this;
}
/**
* Zwraca nazwę cennika dostaw
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Ustawia nazwę cennika dostaw
*
* @param string $name Nazwa cennika dostaw
*
* @return self
*/
public function setName(string $name)
{
$this->name = $name;
return $this;
}
/**
* Zwraca datę ostatniej modyfikacji cennika dostaw
*
* @return int|null
*/
public function getLastModified()
{
return $this->lastModified;
}
/**
* Ustawia datę ostatniej modyfikacji cennika dostaw
*
* @param int $lastModified Data ostatniej modyfikacji cennika dostaw
*
* @return self
*/
public function setLastModified(int $lastModified)
{
$this->lastModified = $lastModified;
return $this;
}
/**
* Zwraca listę stawek cennika dostaw
*
* @return array|null
*/
public function getRates()
{
return $this->rates;
}
/**
* Ustawia listę stawek cennika dostaw
*
* @param array $rates Lista stawek cennika dostaw
*
* @return self
*/
public function setRates(array $rates)
{
$this->rates = $rates;
return $this;
}
/**
* Zwraca stawkę cennika dostawy po GUID
*
* @param string $id GUID stawki
* @param string|null $default Wartość domyślna w przypadku braku stawki
* @return array
*/
public function getRate($id, $default = null)
{
return isset($this->rates[$id]) ? $this->rates[$id] : $default;
}
public function delete($con = null)
{
}
public function save($con = null)
{
if ($this->isNew())
{
$response = stAllegroApi::getInstance()->createShippingRate(array(
'name' => $this->name,
'rates' => $this->rates
));
$this->id = $response->id;
}
else
{
stAllegroApi::getInstance()->updateShippingRate($this->id, array(
'name' => $this->name,
'rates' => $this->rates,
));
}
return true;
}
}

View File

@@ -0,0 +1,54 @@
<?php
class AllegroApiShippingRateMapBuilder
{
/**
* The (dot-path) name of this class
*/
const CLASS_NAME = 'plugins.stAllegroPlugin.lib.model.AllegroApiShippingRateMapBuilder';
/**
* The database map.
*/
private $dbMap;
/**
* Tells us if this DatabaseMapBuilder is built so that we
* don't have to re-build it every time.
*
* @return boolean true if this DatabaseMapBuilder is built, false otherwise.
*/
public function isBuilt()
{
return ($this->dbMap !== null);
}
/**
* Gets the databasemap this map builder built.
*
* @return the databasemap
*/
public function getDatabaseMap()
{
return $this->dbMap;
}
/**
* The doBuild() method builds the DatabaseMap
*
* @return void
* @throws PropelException
*/
public function doBuild()
{
$this->dbMap = Propel::getDatabaseMap('propel');
$tMap = $this->dbMap->addTable('st_allegro_api_shipping_rate');
$tMap->setPhpName('AllegroApiShippingRate');
$tMap->addPrimaryKey('ID', 'Id', 'string', CreoleTypes::CHAR, true, 38);
$tMap->addColumn('NAME', 'Name', 'string', CreoleTypes::VARCHAR, true, 255);
$tMap->addColumn('LAST_MODIFIED', 'LastModified', 'int', CreoleTypes::TIMESTAMP);
} // doBuild()
}

View File

@@ -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);
}