first commit
This commit is contained in:
114
plugins/stAllegroPlugin/lib/model/AllegroAuction.php
Normal file
114
plugins/stAllegroPlugin/lib/model/AllegroAuction.php
Normal file
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
|
||||
class AllegroAuction extends BaseAllegroAuction {
|
||||
protected $productPrice = null;
|
||||
|
||||
protected $productOptionsArray = null;
|
||||
|
||||
public function productHasOptions()
|
||||
{
|
||||
return $this->getProduct() && $this->getProduct()->getOptHasOptions() > 1;
|
||||
}
|
||||
|
||||
public function addCommand($uuid, $type)
|
||||
{
|
||||
$commands = $this->getCommands() ? $this->getCommands() : array();
|
||||
|
||||
$commands[$type] = $uuid;
|
||||
|
||||
$this->setCommands($commands);
|
||||
}
|
||||
|
||||
public function getCommands()
|
||||
{
|
||||
$commands = parent::getCommands();
|
||||
|
||||
return $commands ? $commands : array();
|
||||
}
|
||||
|
||||
public function getCommand($type)
|
||||
{
|
||||
$commands = $this->getCommands();
|
||||
|
||||
return $commands && isset($commands[$type]) ? $commands[$type] : null;
|
||||
}
|
||||
|
||||
public function getEnvironment()
|
||||
{
|
||||
return 'AllegroPl';
|
||||
}
|
||||
|
||||
public function getAuctionLink()
|
||||
{
|
||||
return stAllegroApi::getOfferUrl($this->getAuctionId());
|
||||
}
|
||||
|
||||
public function setProductOptions($v)
|
||||
{
|
||||
|
||||
// throw new Exception($v);
|
||||
|
||||
parent::setProductOptions($v);
|
||||
$this->productOptionsArray = null;
|
||||
}
|
||||
|
||||
public function getProductOptionsArray()
|
||||
{
|
||||
if (null === $this->productOptionsArray)
|
||||
{
|
||||
$ids = array();
|
||||
|
||||
if ($this->productHasOptions())
|
||||
{
|
||||
$selected = $this->getProductOptions() ? explode(",", $this->getProductOptions()) : array();
|
||||
|
||||
$values = array();
|
||||
|
||||
$index = 0;
|
||||
|
||||
foreach ($selected as $id)
|
||||
{
|
||||
$option = ProductOptionsValuePeer::retrieveByPK($id);
|
||||
|
||||
if ($option)
|
||||
{
|
||||
$values[$index][trim($option->getOptValue())] = $option->getId();
|
||||
}
|
||||
|
||||
$index++;
|
||||
}
|
||||
|
||||
$product = $this->getProduct();
|
||||
|
||||
if (null === $this->productPrice)
|
||||
{
|
||||
$this->productPrice = $product->getPriceBrutto();
|
||||
}
|
||||
|
||||
$ids = stNewProductOptions::updateProduct($product, $ids, $values, false);
|
||||
|
||||
$price = stPrice::computePriceModifiers($product, $this->productPrice, 'brutto');
|
||||
|
||||
$product->setPriceBrutto($price);
|
||||
|
||||
$product->resetModified();
|
||||
|
||||
stNewProductOptions::clearStaticPool();
|
||||
}
|
||||
|
||||
$this->productOptionsArray = $ids;
|
||||
}
|
||||
|
||||
return $this->productOptionsArray;
|
||||
}
|
||||
|
||||
public function save($con = null)
|
||||
{
|
||||
if (!$this->productHasOptions())
|
||||
{
|
||||
$this->setProductOptions(null);
|
||||
}
|
||||
|
||||
return parent::save($con);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user