Beispiel #1
0
 /**
  * Saves the services of the order to the storage.
  *
  * @param \Aimeos\MShop\Order\Item\Base\Iface $basket Basket containing service items
  */
 protected function storeServices(\Aimeos\MShop\Order\Item\Base\Iface $basket)
 {
     $manager = $this->getSubManager('service');
     $attrManager = $manager->getSubManager('attribute');
     foreach ($basket->getServices() as $type => $item) {
         $item->setBaseId($basket->getId());
         $item->setType($type);
         $manager->saveItem($item);
         foreach ($item->getAttributes() as $attribute) {
             $attribute->setServiceId($item->getId());
             $attrManager->saveItem($attribute);
         }
     }
 }
Beispiel #2
0
 /**
  * Adds the delivery/payment item to the XML object
  *
  * @param \Aimeos\MShop\Order\Item\Base\Iface $base Order base object
  * @param \DOMDocument $dom DOM document object with contains the XML structure
  * @param \DOMElement $orderitem DOM element which will be the parent of the new child
  * @throws DOMException If an error occures
  */
 protected function buildXMLService(\Aimeos\MShop\Order\Item\Base\Iface $base, \DOMDocument $dom, \DOMElement $orderitem)
 {
     foreach ($base->getServices() as $service) {
         switch ($service->getType()) {
             case 'delivery':
                 $deliveryitem = $dom->createElement('deliveryitem');
                 $this->appendChildCDATA('code', $service->getCode(), $dom, $deliveryitem);
                 $this->appendChildCDATA('name', $service->getName(), $dom, $deliveryitem);
                 $orderitem->appendChild($deliveryitem);
                 break;
             case 'payment':
                 $paymentitem = $dom->createElement('paymentitem');
                 $this->appendChildCDATA('code', $service->getCode(), $dom, $paymentitem);
                 $this->appendChildCDATA('name', $service->getName(), $dom, $paymentitem);
                 $fieldlist = $dom->createElement('fieldlist');
                 foreach ($service->getAttributes() as $attribute) {
                     $fielditem = $dom->createElement('fielditem');
                     $this->appendChildCDATA('name', $attribute->getCode(), $dom, $fielditem);
                     $this->appendChildCDATA('value', $attribute->getValue(), $dom, $fielditem);
                     $this->appendChildCDATA('type', $attribute->getType(), $dom, $fielditem);
                     $fieldlist->appendChild($fielditem);
                 }
                 $paymentitem->appendChild($fieldlist);
                 $orderitem->appendChild($paymentitem);
                 break;
         }
     }
 }
Beispiel #3
0
 /**
  * Migrates the services from the old basket to the current one.
  *
  * @param \Aimeos\MShop\Order\Item\Base\Iface $basket Basket object
  * @param array $errors Associative list of previous errors
  * @return array Associative list of errors occured
  */
 protected function copyServices(\Aimeos\MShop\Order\Item\Base\Iface $basket, array $errors)
 {
     foreach ($basket->getServices() as $type => $item) {
         try {
             $attributes = array();
             foreach ($item->getAttributes() as $attrItem) {
                 $attributes[$attrItem->getCode()] = $attrItem->getValue();
             }
             $this->setService($type, $item->getServiceId(), $attributes);
             $basket->deleteService($type);
         } catch (\Exception $e) {
         }
         // Don't notify the user as appropriate services can be added automatically
     }
     return $errors;
 }
Beispiel #4
0
 /**
  * Adds the default services to the basket if they are not available.
  *
  * @param \Aimeos\MShop\Order\Item\Base\Iface $order Basket object
  */
 protected function setServicesDefault(\Aimeos\MShop\Order\Item\Base\Iface $order)
 {
     $services = $order->getServices();
     $type = \Aimeos\MShop\Order\Item\Base\Service\Base::TYPE_DELIVERY;
     if (!isset($services[$type]) && (bool) $this->getConfigValue('autofill.delivery', false) === true && (($item = $this->getServiceItem($order, $type, $this->getConfigValue('autofill.deliverycode'))) !== null || ($item = $this->getServiceItem($order, $type)) !== null)) {
         $order->setService($item, $type);
     }
     $type = \Aimeos\MShop\Order\Item\Base\Service\Base::TYPE_PAYMENT;
     if (!isset($services[$type]) && (bool) $this->getConfigValue('autofill.payment', false) === true && (($item = $this->getServiceItem($order, $type, $this->getConfigValue('autofill.paymentcode'))) !== null || ($item = $this->getServiceItem($order, $type)) !== null)) {
         $order->setService($item, $type);
     }
 }
Beispiel #5
0
 /**
  * Returns an list of order data required by PayPal.
  *
  * @param \Aimeos\MShop\Order\Item\Base\Iface $orderBase Order base item
  * @return array Associative list of key/value pairs with order data required by PayPal
  */
 protected function getOrderDetails(\Aimeos\MShop\Order\Item\Base\Iface $orderBase)
 {
     $values = $this->getAuthParameter();
     try {
         $orderAddressDelivery = $orderBase->getAddress(\Aimeos\MShop\Order\Item\Base\Address\Base::TYPE_DELIVERY);
         /* setting up the shipping address details (ReviewOrder) */
         $values['ADDROVERRIDE'] = 1;
         $values['PAYMENTREQUEST_0_SHIPTONAME'] = $orderAddressDelivery->getFirstName() . ' ' . $orderAddressDelivery->getLastName();
         $values['PAYMENTREQUEST_0_SHIPTOSTREET'] = $orderAddressDelivery->getAddress1() . ' ' . $orderAddressDelivery->getAddress2() . ' ' . $orderAddressDelivery->getAddress3();
         $values['PAYMENTREQUEST_0_SHIPTOCITY'] = $orderAddressDelivery->getCity();
         $values['PAYMENTREQUEST_0_SHIPTOSTATE'] = $orderAddressDelivery->getState();
         $values['PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE'] = $orderAddressDelivery->getCountryId();
         $values['PAYMENTREQUEST_0_SHIPTOZIP'] = $orderAddressDelivery->getPostal();
     } catch (\Exception $e) {
     }
     // If no address is available
     $lastPos = 0;
     foreach ($orderBase->getProducts() as $product) {
         $lastPos = $product->getPosition() - 1;
         $values['L_PAYMENTREQUEST_0_NUMBER' . $lastPos] = $product->getId();
         $values['L_PAYMENTREQUEST_0_NAME' . $lastPos] = $product->getName();
         $values['L_PAYMENTREQUEST_0_QTY' . $lastPos] = $product->getQuantity();
         $values['L_PAYMENTREQUEST_0_AMT' . $lastPos] = $product->getPrice()->getValue();
     }
     foreach ($orderBase->getServices() as $service) {
         if (($val = $service->getPrice()->getValue()) > '0.00') {
             $lastPos++;
             $values['L_PAYMENTREQUEST_0_NAME' . $lastPos] = $service->getName();
             $values['L_PAYMENTREQUEST_0_QTY' . $lastPos] = '1';
             $values['L_PAYMENTREQUEST_0_AMT' . $lastPos] = $val;
         }
     }
     $paymentItem = $orderBase->getService('payment');
     if (($paymentCosts = $paymentItem->getPrice()->getCosts()) > '0.00') {
         $lastPos++;
         $values['L_PAYMENTREQUEST_0_NAME' . $lastPos] = $this->getContext()->getI18n()->dt('mshop', 'Payment costs');
         $values['L_PAYMENTREQUEST_0_QTY' . $lastPos] = '1';
         $values['L_PAYMENTREQUEST_0_AMT' . $lastPos] = $paymentCosts;
     }
     $price = $orderBase->getPrice();
     $amount = $price->getValue() + $price->getCosts();
     $values['MAXAMT'] = $amount + 0.01;
     // @todo rounding error?
     $values['PAYMENTREQUEST_0_AMT'] = number_format($amount, 2, '.', '');
     $values['PAYMENTREQUEST_0_ITEMAMT'] = (string) ($price->getValue() + $paymentCosts);
     $values['PAYMENTREQUEST_0_SHIPPINGAMT'] = (string) ($price->getCosts() - $paymentCosts);
     $values['PAYMENTREQUEST_0_INSURANCEAMT'] = '0.00';
     $values['PAYMENTREQUEST_0_INSURANCEOPTIONOFFERED'] = 'false';
     $values['PAYMENTREQUEST_0_SHIPDISCAMT'] = '0.00';
     $values['PAYMENTREQUEST_0_TAXAMT'] = $price->getTaxRate();
     $values['PAYMENTREQUEST_0_CURRENCYCODE'] = $orderBase->getPrice()->getCurrencyId();
     $values['PAYMENTREQUEST_0_PAYMENTACTION'] = $this->getConfigValue(array('paypalexpress.PaymentAction'), 'sale');
     try {
         $orderServiceDeliveryItem = $orderBase->getService('delivery');
         $values['L_SHIPPINGOPTIONAMOUNT0'] = (string) ($price->getCosts() - $paymentCosts);
         $values['L_SHIPPINGOPTIONLABEL0'] = $orderServiceDeliveryItem->getName();
         $values['L_SHIPPINGOPTIONNAME0'] = $orderServiceDeliveryItem->getCode();
         $values['L_SHIPPINGOPTIONISDEFAULT0'] = 'true';
     } catch (\Exception $e) {
     }
     // If no delivery service is available
     return $values;
 }