/** * Returns a list of tax rates and their price items for the given basket. * * @param MShop_Order_Item_Base_Interface $basket Basket containing the products, services, etc. * @return array Associative list of tax rates as key and corresponding price items as value */ protected function _getPriceByTaxRate(MShop_Order_Item_Base_Interface $basket) { $taxrates = array(); foreach ($basket->getProducts() as $product) { $price = $product->getPrice(); $taxrate = $price->getTaxRate(); if (isset($taxrates[$taxrate])) { $taxrates[$taxrate]->addItem($price); } else { $taxrates[$taxrate] = $price; } } try { $price = $basket->getService('delivery')->getPrice(); $taxrate = $price->getTaxRate(); if (isset($taxrates[$taxrate])) { $taxrates[$taxrate]->addItem($price); } else { $taxrates[$taxrate] = $price; } } catch (Exception $e) { } // if delivery service isn't available try { $price = $basket->getService('payment')->getPrice(); $taxrate = $price->getTaxRate(); if (isset($taxrates[$taxrate])) { $taxrates[$taxrate]->addItem($price); } else { $taxrates[$taxrate] = $price; } } catch (Exception $e) { } // if payment service isn't available return $taxrates; }
/** * Returns an list of order data required by PayPal. * * @param MShop_Order_Item_Base_Interface $orderBase Order base item * @return array Associative list of key/value pairs with order data required by PayPal */ protected function _getOrderDetails(MShop_Order_Item_Base_Interface $orderBase) { $values = $this->_getAuthParameter(); try { $orderAddressDelivery = $orderBase->getAddress(MShop_Order_Item_Base_Address_Abstract::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; }
/** * Returns a list of tax rates and their price items for the given basket. * * @param MShop_Order_Item_Base_Interface $basket Basket containing the products, services, etc. * @return array Associative list of tax rates as key and corresponding price items as value */ protected function _getPriceByTaxRate(MShop_Order_Item_Base_Interface $basket) { $taxrates = array(); $manager = MShop_Factory::createManager($this->_getContext(), 'price'); foreach ($basket->getProducts() as $product) { $price = $product->getPrice(); $taxrate = $price->getTaxRate(); if (!isset($taxrates[$taxrate])) { $taxrates[$taxrate] = $manager->createItem(); } $taxrates[$taxrate]->addItem($price, $product->getQuantity()); } try { $price = $basket->getService('delivery')->getPrice(); $taxrate = $price->getTaxRate(); if (!isset($taxrates[$taxrate])) { $taxrates[$taxrate] = $manager->createItem(); } $taxrates[$taxrate]->addItem($price); } catch (Exception $e) { } // if delivery service isn't available try { $price = $basket->getService('payment')->getPrice(); $taxrate = $price->getTaxRate(); if (!isset($taxrates[$taxrate])) { $taxrates[$taxrate] = $manager->createItem(); } $taxrates[$taxrate]->addItem($price); } catch (Exception $e) { } // if payment service isn't available return $taxrates; }