Exemplo n.º 1
0
 /**
  * Cancels the authorization for the given order if supported.
  *
  * @param MShop_Order_Item_Interface $order Order invoice object
  */
 public function cancel(MShop_Order_Item_Interface $order)
 {
     $orderManager = MShop_Factory::createManager($this->_getContext(), 'order');
     if (($tid = $this->_getOrderServiceItem($order->getBaseId())->getAttribute('TRANSACTIONID')) === null) {
         $msg = sprintf('PayPal Express: Payment transaction ID for order ID "%1$s" not available', $order->getId());
         throw new MShop_Service_Exception($msg);
     }
     $values = $this->_getAuthParameter();
     $values['METHOD'] = 'DoVoid';
     $values['AUTHORIZATIONID'] = $tid;
     $urlQuery = http_build_query($values, '', '&');
     $response = $this->_getCommunication()->transmit($this->_apiendpoint, 'POST', $urlQuery);
     $this->_checkResponse($order->getId(), $response, __METHOD__);
     $order->setPaymentStatus(MShop_Order_Item_Abstract::PAY_CANCELED);
     $orderManager->saveItem($order);
 }
Exemplo n.º 2
0
 /**
  * Adds the services from the given order item to the basket.
  *
  * @param MShop_Order_Item_Base_Interface $order Basket object
  * @param MShop_Order_Item_Interface $item Existing order to fetch the services from
  */
 protected function _setServices(MShop_Order_Item_Base_Interface $order, MShop_Order_Item_Interface $item)
 {
     $services = $order->getServices();
     if (empty($services) && $this->_getConfigValue('autofill.orderservice', true) == true) {
         $manager = MShop_Factory::createManager($this->_getContext(), 'order/base/service');
         $search = $manager->createSearch();
         $search->setConditions($search->compare('==', 'order.base.service.baseid', $item->getBaseId()));
         $services = $manager->searchItems($search);
         foreach ($services as $service) {
             $type = $service->getType();
             if (($item = $this->_getServiceItem($order, $type, $service->getCode())) !== null) {
                 $order->setService($item, $type);
             }
         }
     }
 }
Exemplo n.º 3
0
 /**
  * Builds a complete XML string including the order data
  *
  * @param MShop_Order_Item_Interface $invoice Order of the customer
  * @return string Validated XML string with order data
  * @throws MShop_Service_Exception If an error occurs
  */
 public function buildXML(MShop_Order_Item_Interface $invoice)
 {
     $base = $this->_getOrderBase($invoice->getBaseId(), MShop_Order_Manager_Base_Abstract::PARTS_ALL);
     try {
         $dom = new DOMDocument('1.0', 'UTF-8');
         $orderlist = $dom->createElement('orderlist');
         $orderitem = $dom->createElement('orderitem');
         $this->_buildXMLHeader($invoice, $base, $dom, $orderitem);
         $this->_buildXMLService($base, $dom, $orderitem);
         $this->_buildXMLPrice($base, $dom, $orderitem);
         $this->_buildXMLProducts($base, $dom, $orderitem);
         $this->_buildXMLAddresses($base, $dom, $orderitem);
         $this->_buildXMLAdditional($base, $dom, $orderitem);
         $orderlist->appendChild($orderitem);
         $dom->appendChild($orderlist);
     } catch (DOMException $e) {
         $msg = 'Creating XML file with order data for delivery provider failed: %1$s';
         throw new MShop_Service_Exception(sprintf($msg, $e->getMessage()), 0, $e);
     }
     $requestXSD = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'xsd' . DIRECTORY_SEPARATOR . 'order-request_v1.xsd';
     if ($dom->schemaValidate($requestXSD) !== true) {
         $msg = 'Validation of XML response from delivery provider against schema "%1$s" failed: %2$s';
         throw new MShop_Service_Exception(sprintf($msg, $requestXSD, $dom->saveXML()), parent::ERR_SCHEMA);
     }
     if (($xml = $dom->saveXML()) === false) {
         $msg = 'DOM tree of XML response from delivery provider could not be converted to XML string';
         throw new MShop_Service_Exception(sprintf($msg), parent::ERR_XML);
     }
     return $xml;
 }
Exemplo n.º 4
0
 /**
  * Increases or decreses the stock levels of the products referenced in the order by the given value.
  *
  * @param MShop_Order_Item_Interface $orderItem Order item object
  * @param integer $how Positive or negative integer number for increasing or decreasing the stock levels
  */
 protected function _updateStock(MShop_Order_Item_Interface $orderItem, $how = +1)
 {
     $context = $this->_getContext();
     $manager = MShop_Factory::createManager($context, 'order/base/product');
     $stockManager = MShop_Factory::createManager($context, 'product/stock');
     $search = $manager->createSearch();
     $search->setConditions($search->compare('==', 'order.base.product.baseid', $orderItem->getBaseId()));
     $start = 0;
     $stockManager->begin();
     do {
         $items = $manager->searchItems($search);
         foreach ($items as $item) {
             $stockManager->increase($item->getProductCode(), $item->getWarehouseCode(), $how * $item->getQuantity());
         }
         $count = count($items);
         $start += $count;
         $search->setSlice($start);
     } while ($count >= $search->getSliceSize());
     $stockManager->commit();
 }