939 lines
34 KiB
PHP
939 lines
34 KiB
PHP
<?php
|
|
/**
|
|
* SOTESHOP/stWebApiPlugin
|
|
*
|
|
* Ten plik należy do aplikacji stWebApiPlugin opartej na licencji (Open License SOTE) Otwarta Licencja SOTE.
|
|
* Nie zmieniaj tego pliku, jeśli chcesz korzystać z automatycznych aktualizacji oprogramowania.
|
|
* Jeśli chcesz wprowadzać swoje modyfikacje do programu, zapoznaj się z dokumentacją, jak zmieniać
|
|
* oprogramowanie bez zmiany kodu bazowego http://www.sote.pl/modifications
|
|
*
|
|
* @package stWebApiPlugin
|
|
* @subpackage libs
|
|
* @copyright SOTE (www.sote.pl)
|
|
* @license http://www.sote.pl/license/open (Open License SOTE) Otwarta Licencja SOTE
|
|
* @version $Id: stModuleWebApi.class.php 16567 2011-12-21 13:38:08Z piotr $
|
|
* @author Michal Prochowski <michal.prochowski@sote.pl>
|
|
*/
|
|
|
|
/**
|
|
* Klasa stOrderWebApi
|
|
*
|
|
* @package stWebApiPlugin
|
|
* @subpackage libs
|
|
*/
|
|
class stOrderWebApi extends autoStOrderWebApi
|
|
{
|
|
/**
|
|
*
|
|
* @var Order
|
|
*/
|
|
protected $currentOrder = null;
|
|
|
|
protected $updateOrderStatus = false;
|
|
|
|
public static function setStatusId(Order $order, int $statusId)
|
|
{
|
|
$orderStatus = OrderStatusPeer::retrieveByPKCached($statusId);
|
|
|
|
if (null === $orderStatus)
|
|
{
|
|
self::throwSoapFault('INVALID_ORDER_STATUS_ID', 'Status o id "%%id%%" - nie istnieje', [
|
|
'%%id%%' => $statusId,
|
|
]);
|
|
}
|
|
|
|
$order->setOrderStatus($orderStatus);
|
|
}
|
|
|
|
public static function setUser(Order $order, stdClass $userData)
|
|
{
|
|
$guardUser = sfGuardUserPeer::retrieveByUsername($userData->email);
|
|
|
|
if (null === $guardUser)
|
|
{
|
|
$guardUser = sfGuardUserPeer::createAnonymous($userData->email);
|
|
}
|
|
|
|
$order->setSfGuardUser($guardUser);
|
|
|
|
$billingCountry = CountriesPeer::retrieveByIsoA2($userData->billing->country);
|
|
$deliveryCountry = CountriesPeer::retrieveByIsoA2($userData->delivery->country);
|
|
|
|
unset($userData->billing->country);
|
|
unset($userData->delivery->country);
|
|
|
|
if (null === $billingCountry)
|
|
{
|
|
self::throwSoapFault('INVALID_ORDER_USER_DATA_BILLING_COUNTRY', 'Kraj o kodzie "%%iso_code%%" - nie istnieje lub nie jest aktywny');
|
|
}
|
|
|
|
if (null === $deliveryCountry)
|
|
{
|
|
self::throwSoapFault('INVALID_ORDER_USER_DATA_DELIVERY_COUNTRY', 'Kraj o kodzie "%%iso_code%%" - nie istnieje lub nie jest aktywny');
|
|
}
|
|
|
|
|
|
|
|
$order->getOrderUserDataBilling()->fromArray(get_object_vars($userData->billing), BasePeer::TYPE_FIELDNAME);
|
|
$order->getOrderUserDataBilling()->setZipCode($userData->billing->zip_code);
|
|
$order->getOrderUserDataBilling()->setCountries($deliveryCountry);
|
|
|
|
$order->getOrderUserDataDelivery()->fromArray(get_object_vars($userData->delivery), BasePeer::TYPE_FIELDNAME);
|
|
$order->getOrderUserDataDelivery()->setZipCode($userData->delivery->zip_code);
|
|
$order->getOrderUserDataDelivery()->setCountries($deliveryCountry);
|
|
}
|
|
|
|
public function getGetOrderListCriteria($object)
|
|
{
|
|
$criteria = parent::getGetOrderListCriteria($object);
|
|
|
|
if (isset($object->order_status_id))
|
|
{
|
|
$criteria->add(OrderPeer::ORDER_STATUS_ID, $object->order_status_id);
|
|
}
|
|
|
|
if (isset($object->sf_guard_user_id))
|
|
{
|
|
$criteria->add(OrderPeer::SF_GUARD_USER_ID, $object->sf_guard_user_id);
|
|
}
|
|
|
|
if (isset($object->client_email))
|
|
{
|
|
$criteria->add(OrderPeer::OPT_CLIENT_EMAIL, $object->client_email);
|
|
}
|
|
|
|
if (isset($object->number))
|
|
{
|
|
$criteria->add(OrderPeer::NUMBER, $object->number);
|
|
}
|
|
|
|
if (isset($object->is_confirmed))
|
|
{
|
|
$criteria->add(OrderPeer::IS_CONFIRMED, $object->is_confirmed);
|
|
}
|
|
|
|
if (isset($object->is_allegro_order))
|
|
{
|
|
$criteria->add(OrderPeer::OPT_ALLEGRO_CHECKOUT_FORM_ID, null, $object->is_allegro_order ? Criteria::ISNOTNULL : Criteria::ISNULL);
|
|
}
|
|
|
|
return $criteria;
|
|
}
|
|
|
|
public static function setPayments(Order $order, array $paymentsData)
|
|
{
|
|
foreach ($paymentsData as $paymentData)
|
|
{
|
|
$deliveryPaymentType = $order->getOrderDelivery()->getDelivery()->getDeliveryPaymentType($paymentData->payment_type_id);
|
|
|
|
if (null === $deliveryPaymentType)
|
|
{
|
|
self::throwSoapFault('INVALID_PAYMENT_TYPE_ID', 'Typ płatności o id "%%id%%" - nie istnieje lub nie jest dostępny dla wybranej dostawy', ['%%id%%' => $paymentData->payment_type_id]);
|
|
}
|
|
|
|
if (!$deliveryPaymentType->getIsActive())
|
|
{
|
|
self::throwSoapFault('INVALID_DELIVERY_PAYMENT_TYPE_ID', 'Typ płatności o id "%%id%%" - nie jest dostępny dla wybranej dostawy', ['%%id%%' => $paymentData->payment_type_id]);
|
|
}
|
|
|
|
$payment = stPayment::newPaymentInstance($paymentData->payment_type_id, $order->getUnpaidAmount(), [
|
|
'is_paid' => isset($paymentData->is_paid) && $paymentData->is_paid
|
|
]);
|
|
|
|
$orderHasPayment = new OrderHasPayment();
|
|
$orderHasPayment->setPayment($payment);
|
|
$order->addOrderHasPayment($orderHasPayment);
|
|
}
|
|
}
|
|
|
|
public static function setProducts(Order $order, array $productsData)
|
|
{
|
|
foreach ($productsData as $productData)
|
|
{
|
|
$product = ProductPeer::retrieveByPK($productData->product_id);
|
|
|
|
if (!isset($productData->quantity))
|
|
{
|
|
$productData->quantity = 1;
|
|
}
|
|
|
|
if (null === $product)
|
|
{
|
|
self::throwSoapFault('INVALID_PRODUCT_ID', 'Produkt o id "%%id%%" - nie istnieje', ['%%id%%' => $productData->product_id]);
|
|
}
|
|
|
|
if (!$product->getActive())
|
|
{
|
|
self::throwSoapFault('INACTIVE_PRODUCT', 'Produkt o id "%%id%%" - nie jest aktywny', ['%%id%%' => $productData->product_id]);
|
|
}
|
|
|
|
if ($product->hasOptions() && (!isset($productData->options) || empty($productData->options)))
|
|
{
|
|
self::throwSoapFault('PRODUCT_REQUIRE_PRODUCT_OPTIONS', 'Produkt o id "%%id%%" - wymaga przekazania opcji produktu', ['%%id%%' => $productData->product_id]);
|
|
}
|
|
|
|
if ($product->hasOptions())
|
|
{
|
|
self::addProductOptions($product, $productData->options);
|
|
}
|
|
|
|
if ($product->getIsStockValidated() && $product->getStock() < $productData->quantity)
|
|
{
|
|
self::throwSoapFault('PRODUCT_OUTOFSTOCK', 'Produkt o id "%%id%%" - nie ma dostępnej ilości w magazynie (dostępnych: %%available%%)', [
|
|
'%%id%%' => $productData->product_id,
|
|
'%%available%%' => $product->getStock(),
|
|
]);
|
|
}
|
|
|
|
if (isset($productData->discount))
|
|
{
|
|
$product->setDiscount([
|
|
'value' => $productData->discount->value,
|
|
'type' => isset($productData->discount->value) ? $productData->discount->value : '%',
|
|
]);
|
|
}
|
|
|
|
$orderProduct = OrderProductPeer::createFromProduct($product, $productData->quantity);
|
|
$order->addOrderProduct($orderProduct);
|
|
}
|
|
}
|
|
|
|
public static function setCurrency(Order $order, string $isoCode)
|
|
{
|
|
$currency = CurrencyPeer::retrieveByIso($isoCode);
|
|
|
|
if (null === $currency)
|
|
{
|
|
self::throwSoapFault('INVALID_CURRENCY', 'Waluta "%%iso%%" - nie istnieje', ['%%iso%%' => $isoCode]);
|
|
}
|
|
|
|
if (!$currency->getActive())
|
|
{
|
|
self::throwSoapFault('INACTIVE_CURRENCY', 'Waluta "%%iso%%" - nie jest aktywna', ['%%iso%%' => $isoCode]);
|
|
}
|
|
|
|
$orderCurrency = OrderCurrencyPeer::create($currency);
|
|
$order->setOrderCurrency($orderCurrency);
|
|
}
|
|
|
|
public static function setDelivery(Order $order, stdClass $deliveryData)
|
|
{
|
|
$delivery = DeliveryPeer::retrieveByPK($deliveryData->delivery_id);
|
|
|
|
if (null === $delivery)
|
|
{
|
|
self::throwSoapFault('INVALID_DELIVERY_ID', 'Dostawa o id "%%id%%" - nie istnieje', ['%%id%%' => $deliveryData->delivery_id]);
|
|
}
|
|
|
|
if (!$delivery->getIsActive())
|
|
{
|
|
self::throwSoapFault('INACTIVE_DELIVERY', 'Dostawa o id "%%id%%" - nie jest aktywna', ['%%id%%' => $deliveryData->delivery_id]);
|
|
}
|
|
|
|
$productInfo = new stDeliveryOrderProductInfo($order, $order->getOrderCurrency());
|
|
$orderDelivery = OrderDeliveryPeer::create($delivery, $productInfo);
|
|
$orderDelivery->setIsExpressDelivery(isset($deliveryData->is_express_delivery) && $deliveryData->is_express_delivery);
|
|
$orderDelivery->setIsWeekendDelivery(isset($deliveryData->is_weekend_delivery) && $deliveryData->is_weekend_delivery);
|
|
|
|
if (isset($deliveryData->tracking_numbers))
|
|
{
|
|
$orderDelivery->setTrackingNumbers($deliveryData->tracking_numbers);
|
|
}
|
|
|
|
$order->setOrderDelivery($orderDelivery);
|
|
}
|
|
|
|
public static function getOrderUserDataDeliveryCountry($item) {
|
|
return $item->getOrderUserDataDelivery()->getCountry();
|
|
}
|
|
|
|
public static function getHasAllegroSmartDelivery(Order $order)
|
|
{
|
|
return $order->getOrderDelivery() ? $order->getOrderDelivery()->getOptAllegroDeliverySmart() : false;
|
|
}
|
|
|
|
public static function getOrderUserDataDeliveryName($item) {
|
|
return $item->getOrderUserDataDelivery()->getName();
|
|
}
|
|
|
|
public static function getOrderUserDataDeliverySurname($item) {
|
|
return $item->getOrderUserDataDelivery()->getSurname();
|
|
}
|
|
|
|
public static function getOrderUserDataDeliveryStreet($item) {
|
|
return $item->getOrderUserDataDelivery()->getStreet();
|
|
}
|
|
|
|
public static function getOrderUserDataDeliveryHouse($item) {
|
|
return $item->getOrderUserDataDelivery()->getHouse();
|
|
}
|
|
|
|
public static function getOrderUserDataDeliveryFlat($item) {
|
|
return $item->getOrderUserDataDelivery()->getFlat();
|
|
}
|
|
|
|
public static function getOrderUserDataDeliveryCode($item) {
|
|
return $item->getOrderUserDataDelivery()->getCode();
|
|
}
|
|
|
|
public static function getOrderUserDataDeliveryTown($item) {
|
|
return $item->getOrderUserDataDelivery()->getTown();
|
|
}
|
|
|
|
public static function getOrderUserDataDeliveryPhone($item) {
|
|
return $item->getOrderUserDataDelivery()->getPhone();
|
|
}
|
|
|
|
public static function getOrderUserDataDeliveryCompany($item) {
|
|
return $item->getOrderUserDataDelivery()->getCompany();
|
|
}
|
|
|
|
public static function getOrderUserDataDeliveryVatNumber($item) {
|
|
return $item->getOrderUserDataDelivery()->getVatNumber();
|
|
}
|
|
|
|
public static function getOrderUserDataBillingCountry($item) {
|
|
return $item->getOrderUserDataBilling()->getCountry();
|
|
}
|
|
|
|
public static function getOrderUserDataBillingName($item) {
|
|
return $item->getOrderUserDataBilling()->getName();
|
|
}
|
|
|
|
public static function getOrderUserDataBillingSurname($item) {
|
|
return $item->getOrderUserDataBilling()->getSurname();
|
|
}
|
|
|
|
public static function getOrderUserDataBillingStreet($item) {
|
|
return $item->getOrderUserDataBilling()->getStreet();
|
|
}
|
|
|
|
public static function getOrderUserDataBillingHouse($item) {
|
|
return $item->getOrderUserDataBilling()->getHouse();
|
|
}
|
|
|
|
public static function getOrderUserDataBillingFlat($item) {
|
|
return $item->getOrderUserDataBilling()->getFlat();
|
|
}
|
|
|
|
public static function getOrderUserDataBillingCode($item) {
|
|
return $item->getOrderUserDataBilling()->getCode();
|
|
}
|
|
|
|
public static function getOrderUserDataBillingTown($item) {
|
|
return $item->getOrderUserDataBilling()->getTown();
|
|
}
|
|
|
|
public static function getOrderUserDataBillingPhone($item) {
|
|
return $item->getOrderUserDataBilling()->getPhone();
|
|
}
|
|
|
|
public static function getOrderUserDataBillingCompany($item) {
|
|
return $item->getOrderUserDataBilling()->getCompany();
|
|
}
|
|
|
|
public static function getOrderUserDataBillingVatNumber($item) {
|
|
return $item->getOrderUserDataBilling()->getVatNumber();
|
|
}
|
|
|
|
public static function getOrderDeliveryName($item) {
|
|
return $item->getOrderDelivery()->getName();
|
|
}
|
|
|
|
public static function getOrderDeliveryCost($item) {
|
|
return $item->getOrderDelivery()->getCost(true, true);
|
|
}
|
|
|
|
public static function getOrderDeliveryTax($item) {
|
|
return $item->getOrderDelivery()->getOptTax();
|
|
}
|
|
|
|
public static function getOrderDeliveryNumber($item) {
|
|
return $item->getOrderDelivery()->getNumber();
|
|
}
|
|
|
|
public static function getOrderDeliveryInpost($item) {
|
|
return $item->getOrderDelivery()->getPaczkomatyNumber();
|
|
}
|
|
|
|
public static function getOrderCurrencyName($item) {
|
|
return $item->getOrderCurrency()->getName();
|
|
}
|
|
|
|
public static function getOrderCurrencyExchange($item) {
|
|
return $item->getOrderCurrency()->getExchange();
|
|
}
|
|
|
|
public static function getOrderCurrencyShortcut($item) {
|
|
return $item->getOrderCurrency()->getShortcut();
|
|
}
|
|
|
|
public static function setOrderDeliveryNumber($item, $value) {
|
|
return $item->getOrderDelivery()->setNumber($value);
|
|
}
|
|
|
|
public static function getOrderUserDataBillingAddress($item) {
|
|
return $item->getOrderUserDataBilling()->getAddress();
|
|
}
|
|
|
|
public static function getOrderUserDataBillingAddressMore($item) {
|
|
return $item->getOrderUserDataBilling()->getAddressMore();
|
|
}
|
|
|
|
public static function getOrderUserDataBillingFullName($item) {
|
|
return $item->getOrderUserDataBilling()->getFullName();
|
|
}
|
|
|
|
public static function getOrderUserDataDeliveryAddress($item) {
|
|
return $item->getOrderUserDataDelivery()->getAddress();
|
|
}
|
|
|
|
public static function getOrderUserDataDeliveryAddressMore($item) {
|
|
return $item->getOrderUserDataDelivery()->getAddressMore();
|
|
}
|
|
|
|
public static function getOrderUserDataDeliveryFullName($item) {
|
|
return $item->getOrderUserDataDelivery()->getFullName();
|
|
}
|
|
|
|
public static function getOptions($item) {
|
|
return $item->getPriceModifierLabels();
|
|
}
|
|
|
|
public static function getOrderAllegroDeliveryMethodId(Order $order)
|
|
{
|
|
return $order->getOrderDelivery()->getOptAllegroDeliveryMethodId();
|
|
}
|
|
|
|
public static function getOrderAllegroCheckoutFormId(Order $order)
|
|
{
|
|
return $order->getOptAllegroCheckoutFormId();
|
|
}
|
|
|
|
public static function getOrderAllegroUsername(Order $order)
|
|
{
|
|
return $order->getOptAllegroNick();
|
|
}
|
|
|
|
public static function getClientEmail(Order $order)
|
|
{
|
|
return $order->getOptClientEmail();
|
|
}
|
|
|
|
public static function getAllegroOfferId(OrderProduct $orderProduct)
|
|
{
|
|
return $orderProduct->getAllegroAuctionId();
|
|
}
|
|
|
|
public static function getOrderDeliveryType(Order $order)
|
|
{
|
|
$delivery = $order->getOrderDelivery()->getDelivery();
|
|
|
|
return $delivery && $delivery->getDeliveryType() ? $delivery->getDeliveryType()->getType() : null;
|
|
}
|
|
|
|
public static function getOrderDeliveryPickupPoint(Order $order)
|
|
{
|
|
return $order->getOrderDelivery()->getPickupPoint();
|
|
}
|
|
|
|
public function getFieldsForGetOrderProductList( $object, $item ) {
|
|
parent::getFieldsForGetOrderProductList($object, $item);
|
|
$object->discount_amount = stWebApi::formatData($item->getDiscountValue(), "double");
|
|
$object->discount_type = stWebApi::formatData($item->getDiscountType(), "string");
|
|
}
|
|
|
|
/**
|
|
* Pobieranie danych
|
|
*
|
|
* @param object $object obiekt z parametrami
|
|
* @return object okiekt z danymi
|
|
* @throws WEBAPI_INCORRECT_ID WEBAPI_REQUIRE_ERROR
|
|
*/
|
|
public function GetOrderProductList( $object )
|
|
{
|
|
if (isset($object->_culture)) { $this->__setCulture($object->_culture);}
|
|
stWebApi::getLogin($object->_session_hash, 'webapi_read');
|
|
$this->TestAndValidateGetOrderProductListFields( $object );
|
|
$c = new Criteria( );
|
|
|
|
if (isset($object->_modified_from) && isset($object->_modified_to)) {
|
|
$criterion = $c->getNewCriterion(OrderProductPeer::UPDATED_AT, $object->_modified_from, Criteria::GREATER_EQUAL);
|
|
$criterion->addAnd($c->getNewCriterion(OrderProductPeer::UPDATED_AT, $object->_modified_to, Criteria::LESS_EQUAL));
|
|
$c->add($criterion);
|
|
} else {
|
|
if (isset($object->_modified_from)) {
|
|
$criterion = $c->getNewCriterion(OrderProductPeer::UPDATED_AT, $object->_modified_from, Criteria::GREATER_EQUAL);
|
|
$c->add($criterion);
|
|
}
|
|
|
|
if (isset($object->_modified_to)) {
|
|
$criterion = $c->getNewCriterion(OrderProductPeer::UPDATED_AT, $object->_modified_to, Criteria::LESS_EQUAL);
|
|
$c->add($criterion);
|
|
}
|
|
}
|
|
|
|
if (!isset($object->_limit)) $object->_limit = 20;
|
|
|
|
// ustawiamy kryteria wyboru
|
|
$c->setLimit( $object->_limit );
|
|
$c->setOffset( $object->_offset );
|
|
$c->add(OrderProductPeer::ORDER_ID, $object->order_id);
|
|
|
|
$items = OrderProductPeer::doSelect( $c );
|
|
|
|
$without_discount = isset($object->without_discount) && $object->without_discount;
|
|
|
|
if ( $items )
|
|
{
|
|
// Zwracanie wyniku, dla wszystkich pol z tablicy 'out'
|
|
$items_array = array();
|
|
$order = OrderPeer::retrieveByPK($object->order_id);
|
|
$prev = self::initOrder($order);
|
|
foreach ( $items as $item )
|
|
{
|
|
$order_product = new StdClass( );
|
|
$this->getFieldsForGetOrderProductList( $order_product, $item );
|
|
|
|
if ($without_discount)
|
|
{
|
|
$order_product->price = stWebApi::formatData($item->getPriceNetto(true, false), "double");
|
|
$order_product->price_brutto = stWebApi::formatData($item->getPriceBrutto(true, false), "double");
|
|
}
|
|
|
|
if ($item->getIsSet() && $item->getVersion() < 3)
|
|
{
|
|
$c = new Criteria();
|
|
$c->addJoin(ProductPeer::ID, OrderProductHasSetPeer::PRODUCT_ID);
|
|
$c->add(OrderProductHasSetPeer::ORDER_PRODUCT_ID, $item->getId());
|
|
|
|
$product = $item->getProduct();
|
|
|
|
$product->setCulture($order->getClientCulture());
|
|
|
|
$total = $order_product->price_brutto;
|
|
|
|
$products = ProductPeer::doSelectWithI18n($c);
|
|
|
|
$cnt = count($products) + 1;
|
|
|
|
$price_brutto = stPrice::round($total / $cnt);
|
|
|
|
$price_netto = stPrice::extract($price_brutto, $order_product->vat);
|
|
|
|
$left = stPrice::round($total - $price_brutto * $cnt);
|
|
|
|
$set = array(
|
|
self::createSet($product->getId(), $product->getCode(), $product->getName(), stPrice::extract($price_brutto + $left, $order_product->vat), $price_brutto + $left)
|
|
);
|
|
|
|
foreach ($products as $index => $product)
|
|
{
|
|
$set[] = self::createSet($product->getId(), $product->getCode(), $product->getName(), $price_netto, $price_brutto);
|
|
}
|
|
|
|
$order_product->set = $set;
|
|
}
|
|
elseif ($item->getIsSet())
|
|
{
|
|
$set = array();
|
|
|
|
$c = new Criteria();
|
|
$c->add(OrderProductHasSetPeer::ORDER_PRODUCT_ID, $item->getId());
|
|
|
|
$ophs = OrderProductHasSetPeer::doSelect($c);
|
|
|
|
foreach ($ophs as $current)
|
|
{
|
|
$set[] = self::createSet($current->getProductId(), $current->getCode(), $current->getName(), $current->getPriceNetto(), $current->getPriceBrutto());
|
|
}
|
|
|
|
$order_product->set = $set;
|
|
}
|
|
else
|
|
{
|
|
$order_product->set = array();
|
|
}
|
|
|
|
$items_array[] = $order_product;
|
|
}
|
|
self::restoreDefaults($prev);
|
|
return $items_array;
|
|
} else {
|
|
return array( );
|
|
}
|
|
}
|
|
|
|
public function GetOrderPayment( $object )
|
|
{
|
|
if (isset($object->_culture)) { $this->__setCulture($object->_culture);}
|
|
stWebApi::getLogin($object->_session_hash, 'webapi_read');
|
|
$this->TestAndValidateGetOrderPaymentFields( $object );
|
|
|
|
$c = new Criteria();
|
|
$c->add(OrderHasPaymentPeer::ORDER_ID,$object->order_id);
|
|
$c->addJoin(OrderHasPaymentPeer::PAYMENT_ID, PaymentPeer::ID);
|
|
|
|
$items = PaymentPeer::doSelect( $c );
|
|
if ( $items )
|
|
{
|
|
$items_array = array();
|
|
foreach ( $items as $item )
|
|
{
|
|
$object = new StdClass( );
|
|
$this->getFieldsForGetOrderPayment( $object, $item );
|
|
$items_array[] = $object;
|
|
}
|
|
return $items_array;
|
|
} else {
|
|
throw new SoapFault( "1", $this->__(WEBAPI_INCORRECT_ID) );
|
|
}
|
|
}
|
|
|
|
public static function getPaymentOptName($item) {
|
|
if (is_object($item->getPaymentType())) {
|
|
$name = $item->getPaymentType()->getOptName();
|
|
|
|
if ($item->getAllegroPaymentType()) {
|
|
sfLoader::loadHelpers(array('Helper', 'stAllegro'));
|
|
$name .= " - ".st_allegro_payment_type($item->getAllegroPaymentType());
|
|
}
|
|
|
|
return $name;
|
|
}
|
|
else if (is_object($item->getGiftCard())) {
|
|
return "Kod: ".$item->getGiftCard()->getCode();
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* Aktualizacja danych
|
|
*
|
|
* @param object $object obiekt z parametrami
|
|
* @return object obiekt z true
|
|
* @throws WEBAPI_INCORRECT_ID WEBAPI_UPDATE_ERROR WEBAPI_REQUIRE_ERROR
|
|
* @todo dodać walidacje danych
|
|
*/
|
|
public function SetOrderPaymentStatus( $object )
|
|
{
|
|
if (isset($object->_culture)) { $this->__setCulture($object->_culture);}
|
|
stWebApi::getLogin($object->_session_hash, 'webapi_write');
|
|
$this->TestAndValidateSetOrderPaymentStatusFields( $object );
|
|
|
|
$c = new Criteria();
|
|
$c->add(OrderHasPaymentPeer::ORDER_ID,$object->order_id);
|
|
$c->addJoin(OrderHasPaymentPeer::PAYMENT_ID, PaymentPeer::ID);
|
|
|
|
$item = PaymentPeer::doSelectOne( $c );
|
|
if ( $item )
|
|
{
|
|
$this->setFieldsForSetOrderPaymentStatus( $object, $item );
|
|
//Zapisywanie danych do bazy
|
|
try {
|
|
$item->save( );
|
|
} catch ( Exception $e ) {
|
|
throw new SoapFault( "2", sprintf($this->__(WEBAPI_UPDATE_ERROR),$e->getMessage()) );
|
|
}
|
|
|
|
// Zwracanie danych
|
|
$object = new StdClass( );
|
|
$object->_update = true;
|
|
return $object;
|
|
|
|
} else {
|
|
throw new SoapFault( "1", $this->__(WEBAPI_INCORRECT_ID) );
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Pobieranie danych
|
|
*
|
|
* @param object $object obiekt z parametrami
|
|
* @return object okiekt z danymi
|
|
* @throws WEBAPI_INCORRECT_ID WEBAPI_REQUIRE_ERROR
|
|
*/
|
|
public function GetOrderByNumber( $object )
|
|
{
|
|
if (isset($object->_culture)) { $this->__setCulture($object->_culture);}
|
|
stWebApi::getLogin($object->_session_hash, 'webapi_read');
|
|
$this->TestAndValidateGetOrderByNumberFields( $object );
|
|
|
|
$item = OrderPeer::retrieveByNumber( $object->number );
|
|
|
|
if ( $item )
|
|
{
|
|
$object = new StdClass( );
|
|
$this->getFieldsForGetOrderByNumber( $object, $item );
|
|
return $object;
|
|
} else {
|
|
throw new SoapFault( "1", $this->__(WEBAPI_INCORRECT_ID) );
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Pobieranie danych
|
|
*
|
|
* @param object $object obiekt z parametrami
|
|
* @return object okiekt z danymi
|
|
* @throws WEBAPI_INCORRECT_ID WEBAPI_REQUIRE_ERROR
|
|
*/
|
|
public function GetOrderListByUser( $object )
|
|
{
|
|
if (isset($object->_culture)) { $this->__setCulture($object->_culture);}
|
|
stWebApi::getLogin($object->_session_hash, 'webapi_read');
|
|
$this->TestAndValidateGetOrderListFields( $object );
|
|
|
|
if (!isset($object->user_id) && !isset($object->user_name)) return array();
|
|
|
|
$userId = null;
|
|
if (isset($object->user_id)) $userId = $object->user_id;
|
|
|
|
if ($userId == null && isset($object->user_name))
|
|
{
|
|
$userC = new Criteria();
|
|
$userC->add(sfGuardUserPeer::USERNAME, $object->user_name);
|
|
$user = sfGuardUserPeer::doSelectOne($userC);
|
|
|
|
if(!is_object($user)) return array();
|
|
$userId = $user->getId();
|
|
}
|
|
|
|
if ($userId == null) return array();
|
|
|
|
$c = new Criteria( );
|
|
|
|
$c->add(OrderPeer::SF_GUARD_USER_ID, $userId);
|
|
|
|
if (isset($object->_modified_from) && isset($object->_modified_to)) {
|
|
$criterion = $c->getNewCriterion(OrderPeer::UPDATED_AT, $object->_modified_from, Criteria::GREATER_EQUAL);
|
|
$criterion->addAnd($c->getNewCriterion(OrderPeer::UPDATED_AT, $object->_modified_to, Criteria::LESS_EQUAL));
|
|
$c->add($criterion);
|
|
} else {
|
|
if (isset($object->_modified_from)) {
|
|
$criterion = $c->getNewCriterion(OrderPeer::UPDATED_AT, $object->_modified_from, Criteria::GREATER_EQUAL);
|
|
$c->add($criterion);
|
|
}
|
|
|
|
if (isset($object->_modified_to)) {
|
|
$criterion = $c->getNewCriterion(OrderPeer::UPDATED_AT, $object->_modified_to, Criteria::LESS_EQUAL);
|
|
$c->add($criterion);
|
|
}
|
|
}
|
|
|
|
if (!isset($object->_limit)) $object->_limit = 20;
|
|
|
|
// ustawiamy kryteria wyboru
|
|
$c->setLimit( $object->_limit );
|
|
$c->setOffset( $object->_offset );
|
|
|
|
$items = OrderPeer::doSelect( $c );
|
|
|
|
if ( $items )
|
|
{
|
|
// Zwracanie wyniku, dla wszystkich pol z tablicy 'out'
|
|
$items_array = array();
|
|
foreach ( $items as $item )
|
|
{
|
|
$object = new StdClass( );
|
|
$this->getFieldsForGetOrderList( $object, $item );
|
|
$items_array[] = $object;
|
|
}
|
|
return $items_array;
|
|
} else {
|
|
return array( );
|
|
}
|
|
}
|
|
|
|
public function GetOrderProductCount( $object )
|
|
{
|
|
if (isset($object->_culture)) { $this->__setCulture($object->_culture);}
|
|
stWebApi::getLogin($object->_session_hash, 'webapi_read');
|
|
|
|
try{
|
|
$c = new Criteria( );
|
|
$c->add(OrderProductPeer::ORDER_ID, $object->order_id);
|
|
|
|
if (isset($object->_modified_from) && isset($object->_modified_to)) {
|
|
$criterion = $c->getNewCriterion(OrderProductPeer::UPDATED_AT, $object->_modified_from, Criteria::GREATER_EQUAL);
|
|
$criterion->addAnd($c->getNewCriterion(OrderProductPeer::UPDATED_AT, $object->_modified_to, Criteria::LESS_EQUAL));
|
|
$c->add($criterion);
|
|
} else {
|
|
if (isset($object->_modified_from)) {
|
|
$criterion = $c->getNewCriterion(OrderProductPeer::UPDATED_AT, $object->_modified_from, Criteria::GREATER_EQUAL);
|
|
$c->add($criterion);
|
|
}
|
|
|
|
if (isset($object->_modified_to)) {
|
|
$criterion = $c->getNewCriterion(OrderProductPeer::UPDATED_AT, $object->_modified_to, Criteria::LESS_EQUAL);
|
|
$c->add($criterion);
|
|
}
|
|
}
|
|
|
|
//Zwracanie danych
|
|
$obj = new StdClass( );
|
|
$obj->_count = OrderProductPeer::doCount($c);
|
|
return $obj;
|
|
} catch ( Exception $e ) {
|
|
throw new SoapFault( "1", sprintf($this->__(WEBAPI_COUNT_ERROR),$e->getMessage()) );
|
|
}
|
|
}
|
|
|
|
public function UpdateOrderStatus($object) {
|
|
$return = parent::UpdateOrderStatus($object);
|
|
|
|
if ($this->updateOrderStatus) {
|
|
$notification = new stOrderMailNotification(sfContext::getInstance());
|
|
$notification->sendStatusChangeNotification($this->currentOrder);
|
|
}
|
|
|
|
$obj = new StdClass();
|
|
$obj->order = $this->currentOrder;
|
|
stEventDispatcher::getInstance()->notify(new sfEvent($obj, 'stOrderApiActions.postUpdateStatus', array()));
|
|
|
|
return $return;
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param object $object
|
|
* @param Order $item
|
|
* @return void
|
|
*/
|
|
public function setFieldsForUpdateOrderStatus( $object, $item ) {
|
|
parent::setFieldsForUpdateOrderStatus($object, $item);
|
|
|
|
$this->currentOrder = $item;
|
|
$this->updateOrderStatus = $item->isColumnModified(OrderPeer::ORDER_STATUS_ID);
|
|
}
|
|
|
|
public static function initOrder(Order $order)
|
|
{
|
|
$context = sfContext::getInstance();
|
|
$currency = stCurrency::getInstance($context);
|
|
$prev_culture = $context->getUser()->getCulture();
|
|
$context->getUser()->setCulture($order->getClientCulture());
|
|
|
|
$prev_currency_id = $currency->get()->getId();
|
|
|
|
$order_currency = CurrencyPeer::retrieveByIso($order->getOrderCurrency()->getShortcut());
|
|
|
|
if ($order_currency) {
|
|
$currency->set($order_currency->getId());
|
|
$dispatcher = $context->getController()->getDispatcher();
|
|
$dispatcher->connect('Product.postHydrate', array('appAddPricePluginListener', 'productPostHydrate'));
|
|
$dispatcher->connect('ProductOptionsValue.postHydrate', array('appAddPricePluginListener', 'productOptionsValuePostHydrate'));
|
|
$dispatcher->connect('ProductPeer.postAddSelectColumns', array('appAddPricePluginListener', 'productPostAddSelectColumns'));
|
|
$dispatcher->connect('BasePeer.preDoSelectRs', array('appAddPricePluginListener', 'preDoSelectRs'));
|
|
}
|
|
|
|
Product::enableFrontendFunctions();
|
|
|
|
return array('currency' => $prev_currency_id, );
|
|
}
|
|
|
|
public static function restoreDefaults($prev)
|
|
{
|
|
$currency = stCurrency::getInstance(sfContext::getInstance());
|
|
$currency->set($prev['currency']);
|
|
|
|
Product::enableFrontendFunctions(false);
|
|
}
|
|
|
|
public static function createSet($id, $code, $name, $price_netto = null, $price_brutto = null)
|
|
{
|
|
return array(
|
|
'id' => stWebApi::formatData($id, 'integer'),
|
|
'code' => stWebApi::formatData($code, 'string'),
|
|
'name' => stWebApi::formatData($name, 'string'),
|
|
'price' => stWebApi::formatData($price_netto, 'double'),
|
|
'price_brutto' => stWebApi::formatData($price_brutto, 'double'),
|
|
);
|
|
}
|
|
|
|
public static function getOrderDiscountValue(Order $order)
|
|
{
|
|
$discount = $order->getOrderDiscount();
|
|
|
|
return $discount ? $discount['value'] : 0;
|
|
}
|
|
|
|
public static function getOrderDiscountType(Order $order)
|
|
{
|
|
$discount = $order->getOrderDiscount();
|
|
|
|
return $discount ? $discount['type'] : 0;
|
|
}
|
|
|
|
public static function getTotalAmount(Order $order)
|
|
{
|
|
return $order->getOptTotalAmount();
|
|
}
|
|
|
|
public static function getOrderAllegroAuctionId(Order $order)
|
|
{
|
|
return null !== $order->getOptAllegroCheckoutFormId() || null !== $order->getOptAllegroNick();
|
|
}
|
|
|
|
protected function saveOrderForAddOrder(Order $item): int
|
|
{
|
|
$result = parent::saveOrderForAddOrder($item);
|
|
|
|
$proforma = stInvoice::createInvoiceProforma($item);
|
|
|
|
if ($item->getClientRequestInvoice())
|
|
{
|
|
stInvoice::createInvoiceRequest($item, $proforma);
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
protected static function addProductOptions(Product $product, array $productOptionsIds)
|
|
{
|
|
$allowedParentIds = [];
|
|
$selectedfieldIds = [];
|
|
|
|
$c = new Criteria();
|
|
$c->add(ProductOptionsValuePeer::ID, $productOptionsIds, Criteria::IN);
|
|
$c->add(ProductOptionsValuePeer::PRODUCT_ID, $product->getId());
|
|
|
|
$productOptions = ProductOptionsValuePeer::doSelectJoinProductOptionsField($c);
|
|
|
|
if (count($productOptions) < count($productOptionsIds))
|
|
{
|
|
$currentProductOptionIds = [];
|
|
|
|
foreach ($productOptions as $productOption)
|
|
{
|
|
$currentProductOptionIds[] = $productOption->getId();
|
|
}
|
|
|
|
$invalidProductOptionIds = array_diff($productOptionsIds, $currentProductOptionIds);
|
|
|
|
self::throwSoapFault('INVALID_PRODUT_OPTION_ID', 'Opcje o id "%%option_id%%" nie istnieją lub nie należą do produktu o id "%%id%%"', [
|
|
'%%option_id%%' => implode('", "C', $invalidProductOptionIds),
|
|
'%%id%%' => $product->getId(),
|
|
]);
|
|
}
|
|
|
|
foreach ($productOptions as $productOption)
|
|
{
|
|
if (!$productOption->isLeaf())
|
|
{
|
|
self::throwSoapFault('INVALID_PRODUCT_OPTION', 'Opcja o id "%%option_id%%" - musi być opcją ostatniego poziomu', [
|
|
'%%option_id%%' => $productOption->getId(),
|
|
]);
|
|
}
|
|
|
|
if (!stNewProductOptions::updateProductBySelectedOptions($product, $productOption->getPathWithoutRoot(true), $allowedParentIds, $selectedfieldIds))
|
|
{
|
|
self::throwSoapFault('INVALID_PRODUCT_OPTION_COMBINATION', 'Produktu o id "%%id%%" - posiada niedozwoloną kombinację opcji', [
|
|
'%%id%%' => $product->getId(),
|
|
]);
|
|
}
|
|
}
|
|
}
|
|
}
|