/** * Checks if the country code is allowed for the service provider. * * @param MShop_Order_Item_Base_Interface $basket Basket object * @return boolean True if payment provider can be used, false if not */ public function isAvailable(MShop_Order_Item_Base_Interface $basket) { $addresses = $basket->getAddresses(); $paymentType = MShop_Order_Item_Base_Address_Abstract::TYPE_PAYMENT; $deliveryType = MShop_Order_Item_Base_Address_Abstract::TYPE_DELIVERY; if (isset($addresses[$deliveryType])) { $code = strtoupper($addresses[$deliveryType]->getCountryId()); if ($this->_checkCountryCode($code, 'country.delivery-include') === false || $this->_checkCountryCode($code, 'country.delivery-exclude') === true) { return false; } } else { if (isset($addresses[$paymentType])) { $code = strtoupper($addresses[$paymentType]->getCountryId()); if ($this->_checkCountryCode($code, 'country.delivery-include') === false || $this->_checkCountryCode($code, 'country.delivery-exclude') === true) { return false; } } } if (isset($addresses[$paymentType])) { $code = strtoupper($addresses[$paymentType]->getCountryId()); if ($this->_checkCountryCode($code, 'country.billing-include') === false || $this->_checkCountryCode($code, 'country.billing-exclude') === true) { return false; } } return $this->_getProvider()->isAvailable($basket); }
/** * Saves the addresses of the order to the storage. * * @param MShop_Order_Item_Base_Interface $basket Basket containing address items */ protected function _storeAddresses(MShop_Order_Item_Base_Interface $basket) { $manager = $this->getSubManager('address'); foreach ($basket->getAddresses() as $type => $item) { $item->setBaseId($basket->getId()); $item->setType($type); $manager->saveItem($item); } }
/** * Adds the address list 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 _buildXMLAddresses(MShop_Order_Item_Base_Interface $base, DOMDocument $dom, DOMElement $orderitem) { $addresslist = $dom->createElement('addresslist'); foreach ($base->getAddresses() as $address) { $this->_buildXMLAddress($address, $dom, $addresslist); } $orderitem->appendChild($addresslist); }
/** * Adds the addresses 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 addresses from */ protected function _setAddresses(MShop_Order_Item_Base_Interface $order, MShop_Order_Item_Interface $item) { $addresses = $order->getAddresses(); if (empty($addresses) && $this->_getConfigValue('autofill.orderaddress', true) == true) { $manager = MShop_Factory::createManager($this->_getContext(), 'order/base/address'); $search = $manager->createSearch(); $search->setConditions($search->compare('==', 'order.base.address.baseid', $item->getBaseId())); $addresses = $manager->searchItems($search); foreach ($addresses as $address) { $order->setAddress($address, $address->getType()); } } }
/** * Migrates the addresses from the old basket to the current one. * * @param MShop_Order_Item_Base_Interface $basket Basket object * @param array $errors Associative list of previous errors * @param string $localeKey Unique identifier of the site, language and currency * @return array Associative list of errors occured */ private function _copyAddresses(MShop_Order_Item_Base_Interface $basket, array $errors, $localeKey) { foreach ($basket->getAddresses() as $type => $item) { try { $this->setAddress($type, $item->toArray()); $basket->deleteAddress($type); } catch (Exception $e) { $logger = $this->_getContext()->getLogger(); $str = 'Error migrating address with type "%1$s" in basket to locale "%2$s": %3$s'; $logger->log(sprintf($str, $type, $localeKey, $e->getMessage()), MW_Logger_Abstract::INFO); $errors['address'][$type] = $e->getMessage(); } } return $errors; }