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,97 @@
<?php
class stAllegroCategoriesBar {
protected $allegro = null;
protected $i18n;
public function __construct() {
$this->i18n = sfContext::getInstance()->getI18n();
$this->initAllegro();
}
public function initAllegro() {
if ($this->allegro == null) {
$request = sfContext::getInstance()->getRequest();
if ($request->hasParameter('environment'))
$environment = $request->getParameter('environment');
else
list(, $environment) = explode('-', $request->getParameter('name'), 2);
$this->allegro = new stAllegro($environment);
}
}
public function getCategories($offset = 0) {
if ($offset == 0)
{
$con = Propel::getConnection();
$c = new Criteria();
$c->add(AllegroCategoryPeer::SITE, $this->allegro->getEnvironment());
$cu = new Criteria();
$cu->add(AllegroCategoryPeer::IS_OLD, 1);
BasePeer::doUpdate($c, $cu, $con);
}
$this->msg = $this->i18n->__('Pobrano %count% z %countAll% kategorii.', array('%count%' => ($offset * 500), '%countAll%' => $this->allegro->getCategoryCount()), 'stAllegroBackend');
$categories = $this->allegro->getCategories($offset, 500);
$this->saveCategories($categories);
return $offset+1;
}
public function saveCategories($categories) {
$ids = array();
foreach ($categories as $category) {
if (is_array($category)) {
$ids[] = $category['catId'];
}
}
$c = new Criteria();
$c->add(AllegroCategoryPeer::CAT_ID, $ids, Criteria::IN);
$c->add(AllegroCategoryPeer::SITE, $this->allegro->getEnvironment());
$selected = array();
foreach (AllegroCategoryPeer::doSelect($c) as $category)
{
$selected[$category->getCatId()] = $category;
}
foreach ($categories as $category) {
if (is_array($category)) {
$allegroCategory = isset($selected[$category['catId']]) ? $selected[$category['catId']] : null;
if (!$allegroCategory) {
$allegroCategory = new AllegroCategory();
$allegroCategory->setCatId($category['catId']);
$allegroCategory->setSite($this->allegro->getEnvironment());
}
$allegroCategory->setName($category['catName']);
$allegroCategory->setParent($category['catParent']);
$allegroCategory->setPosition($category['catPosition']);
$allegroCategory->setIsOld(0);
$allegroCategory->save();
}
}
}
public function getTitle() {
return ' ';
}
public function getMessage() {
return $this->msg;
}
public function close() {
$this->msg = sprintf($this->i18n->__('Kategorie zostały pobrane. Ilość pobranych kategorii wynosi %d.', null, 'stAllegroBackend'), $this->allegro->getCategoryCount());
$ac = new stAllegroCategory($this->allegro);
$ac->saveCategoryVersion();
}
}

View File

@@ -0,0 +1,61 @@
<?php
class stAllegroCreateAuctionsBar {
protected $i18n;
protected $msg = null;
protected $auctionIds = array();
public function __construct() {
$this->i18n = sfContext::getInstance()->getI18n();
$this->auctionIds = sfContext::getInstance()->getUser()->getAttribute('auctionsIds', array(), 'stAllegroPlugin');
}
public function init() {
sfContext::getInstance()->getUser()->setAttribute('auctionsInformations', array(), 'stAllegroPlugin');
}
public function getTitle() {
return $this->i18n->__('Wystawianie aukcji w serwisie aukcyjnym', null, 'stAllegroBackend');
}
public function getMessage() {
return $this->msg;
}
public function createAuction($step = 0) {
if (isset($this->auctionIds[$step])) {
$auction = AllegroAuctionPeer::retrieveByPK($this->auctionIds[$step]);
if (is_object($auction)) {
$this->msg = $this->i18n->__('Wystawianie aukcji', null, 'stAllegroBackend').': '.$auction->getName();
if (!$auction->getAuctionId()) {
try {
$stAllegro =stAllegro::getInstance($auction->getEnvironment());
$response = $stAllegro->createAuction($auction);
if ($response === false)
$response = $stAllegro->getLastError();
} catch(Exception $e) {
$response = $e->getMessage();
}
} else {
$response = $this->i18n->__('Aukcja została wystawiona wcześniej. Proszę utworzyć kopie aukcji i wystawić ją ponownie.', null, 'stAllegroBackend');
}
$messages = sfContext::getInstance()->getUser()->getAttribute('auctionsInformations', array(), 'stAllegroPlugin');
$messages[$auction->getId()] = $response;
sfContext::getInstance()->getUser()->setAttribute('auctionsInformations', $messages, 'stAllegroPlugin');
}
}
return ($step+1);
}
public function close() {
sfLoader::loadHelpers(array('Helper', 'stPartial', 'stAdminGenerator'));
$this->msg = st_get_partial('stAllegroBackend/createManyAuction', array('messages' => sfContext::getInstance()->getUser()->getAttribute('auctionsInformations', array(), 'stAllegroPlugin')));
}
}

View File

@@ -0,0 +1,75 @@
<?php
class stAllegroProductUpdateBar {
protected $i18n;
protected $msg;
public function __construct() {
$this->i18n = sfContext::getInstance()->getI18n();
}
public function execute($offset = 0) {
$c = new Criteria();
$c->setOffset($offset);
$c->setLimit(5);
$api = stAllegroApi::getInstance();
foreach (AllegroAuctionPeer::doSelect($c) as $auction)
{
try {
// throw new Exception("test");
$offer = $api->getOffer($auction->getAuctionId());
// throw new Exception("test");
$offer->external = stAllegroApi::arrayToObject(array(
'id' => $auction->getProductId(),
));
$api->updateOffer($offer->id, $offer);
}
catch(stAllegroException $e)
{
}
$auction->setName($offer->name);
$auction->save();
$offset++;
}
sleep(1);
return $offset;
}
public function getTitle() {
return $this->i18n->__('Aktualizacja ofert - Proszę czekać');
}
public function getMessage() {
return $this->msg;
}
public function close() {
$message = $this->i18n->__('Wszystie oferty zostały zaktualizowane pomyślnie', null, 'stAllegroBackend');
$link = $this->i18n->__('Przejdź do ofert');
$html =<<<HTML
<p style="text-align: center">$message</p>
<p style="text-align: center"><a href="#" onclick="location.reload(); return false">$link</a></p>
HTML;
$this->msg = $html;
$config = stConfig::getInstance('stAllegroBackend');
$config->set('offers_updated', true);
$config->save(true);
}
}