/** * Returns the price when using the provider. * Usually, this is the lowest price that is available in the service item but can also be a calculated based on * the basket content, e.g. 2% of the value as transaction cost. * * @param MShop_Order_Item_Base_Interface $basket Basket object * @return MShop_Price_Item_Interface Price item containing the price, shipping, rebate */ public function calcPrice(MShop_Order_Item_Base_Interface $basket) { $config = $this->getServiceItem()->getConfig(); if (!isset($config['costs.percent'])) { throw new MShop_Service_Provider_Exception(sprintf('Missing configuration "%1$s"', 'costs.percent')); } $value = $basket->getPrice()->getValue() * $config['costs.percent'] / 100; $price = $this->_getProvider()->calcPrice($basket); $price->setCosts($price->getCosts() + $value); return $price; }
/** * Checks for the min/max order value. * * @param MShop_Order_Item_Base_Interface $base Basic order of the customer * @return boolean True if the basket matches the constraints, false if not */ public function isAvailable(MShop_Order_Item_Base_Interface $base) { $price = $base->getPrice(); $currency = $price->getCurrencyId(); $value = $price->getValue() + $price->getRebate(); $minvalue = $this->_getConfigValue('basketvalues.total-value-min', array()); if (isset($minvalue[$currency]) && $minvalue[$currency] > $value) { return false; } $maxvalue = $this->_getConfigValue('basketvalues.total-value-max', array()); if (isset($maxvalue[$currency]) && $maxvalue[$currency] < $value) { return false; } return parent::isAvailable($base); }
/** * 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; }
/** * Adds the price item to the XML object * * @param MShop_Order_Item_Base_Interface $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 _buildXMLPrice(MShop_Order_Item_Base_Interface $base, DOMDocument $dom, DOMElement $orderitem) { $price = $base->getPrice(); $total = $price->getValue() + $price->getCosts(); $priceitem = $dom->createElement('priceitem'); $this->_appendChildCDATA('price', number_format($price->getValue(), 2, '.', ''), $dom, $priceitem); $this->_appendChildCDATA('shipping', number_format($price->getCosts(), 2, '.', ''), $dom, $priceitem); $this->_appendChildCDATA('discount', number_format(0.0, 2, '.', ''), $dom, $priceitem); $this->_appendChildCDATA('total', number_format($total, 2, '.', ''), $dom, $priceitem); $orderitem->appendChild($priceitem); }