/** * Checks if the country code is allowed for the service provider. * * @param \Aimeos\MShop\Order\Item\Base\Iface $basket Basket object * @return boolean True if payment provider can be used, false if not */ public function isAvailable(\Aimeos\MShop\Order\Item\Base\Iface $basket) { $addresses = $basket->getAddresses(); $paymentType = \Aimeos\MShop\Order\Item\Base\Address\Base::TYPE_PAYMENT; $deliveryType = \Aimeos\MShop\Order\Item\Base\Address\Base::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 \Aimeos\MShop\Order\Item\Base\Iface $basket Basket containing address items */ protected function storeAddresses(\Aimeos\MShop\Order\Item\Base\Iface $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 \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 buildXMLAddresses(\Aimeos\MShop\Order\Item\Base\Iface $base, \DOMDocument $dom, \DOMElement $orderitem) { $addresslist = $dom->createElement('addresslist'); foreach ($base->getAddresses() as $address) { $this->buildXMLAddress($address, $dom, $addresslist); } $orderitem->appendChild($addresslist); }
/** * Adds the default addresses to the basket if they are not available. * * @param \Aimeos\MShop\Order\Item\Base\Iface $order Basket object */ protected function setAddressDefault(\Aimeos\MShop\Order\Item\Base\Iface $order) { $context = $this->getContext(); $addresses = $order->getAddresses(); $type = \Aimeos\MShop\Order\Item\Base\Address\Base::TYPE_PAYMENT; if ($context->getUserId() !== null && !isset($addresses[$type]) && (bool) $this->getConfigValue('autofill.address', false) === true) { $customerManager = \Aimeos\MShop\Factory::createManager($context, 'customer'); $orderAddressManager = \Aimeos\MShop\Factory::createManager($context, 'order/base/address'); $address = $customerManager->getItem($context->getUserId())->getPaymentAddress(); $orderAddressItem = $orderAddressManager->createItem(); $orderAddressItem->copyFrom($address); $order->setAddress($orderAddressItem, $type); } }
/** * Migrates the addresses 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 * @param string $localeKey Unique identifier of the site, language and currency * @return array Associative list of errors occured */ protected function copyAddresses(\Aimeos\MShop\Order\Item\Base\Iface $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()), \Aimeos\MW\Logger\Base::INFO); $errors['address'][$type] = $e->getMessage(); } } return $errors; }
/** * Adds the addresses from the given order item to the basket. * * @param \Aimeos\MShop\Order\Item\Base\Iface $order Basket object * @param \Aimeos\MShop\Order\Item\Iface $item Existing order to fetch the addresses from */ protected function setAddresses(\Aimeos\MShop\Order\Item\Base\Iface $order, \Aimeos\MShop\Order\Item\Iface $item) { $addresses = $order->getAddresses(); if (empty($addresses) && $this->getConfigValue('autofill.orderaddress', true) == true) { $manager = \Aimeos\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()); } } }
/** * Returns an Omnipay credit card object * * @param \Aimeos\MShop\Order\Item\Base\Iface $base Order base object with addresses and services * @param array $params POST parameters passed to the provider * @return \Omnipay\Common\CreditCard Credit card object */ protected function getCardDetails(\Aimeos\MShop\Order\Item\Base\Iface $base, array $params) { if ($this->getValue('address')) { $addresses = $base->getAddresses(); if (isset($addresses[\Aimeos\MShop\Order\Item\Base\Address\Base::TYPE_PAYMENT])) { $addr = $addresses[\Aimeos\MShop\Order\Item\Base\Address\Base::TYPE_PAYMENT]; $params['billingName'] = $addr->getFirstname() . ' ' . $addr->getLastname(); $params['billingFirstName'] = $addr->getFirstname(); $params['billingLastName'] = $addr->getLastname(); $params['billingCompany'] = $addr->getCompany(); $params['billingAddress1'] = $addr->getAddress1(); $params['billingAddress2'] = $addr->getAddress2(); $params['billingCity'] = $addr->getCity(); $params['billingPostcode'] = $addr->getPostal(); $params['billingState'] = $addr->getState(); $params['billingCountry'] = $addr->getCountryId(); $params['billingPhone'] = $addr->getTelephone(); $params['billingFax'] = $addr->getTelefax(); $params['email'] = $addr->getEmail(); if (isset($addresses[\Aimeos\MShop\Order\Item\Base\Address\Base::TYPE_DELIVERY])) { $addr = $addresses[\Aimeos\MShop\Order\Item\Base\Address\Base::TYPE_DELIVERY]; } $params['shippingName'] = $addr->getFirstname() . ' ' . $addr->getLastname(); $params['shippingFirstName'] = $addr->getFirstname(); $params['shippingLastName'] = $addr->getLastname(); $params['shippingCompany'] = $addr->getCompany(); $params['shippingAddress1'] = $addr->getAddress1(); $params['shippingAddress2'] = $addr->getAddress2(); $params['shippingCity'] = $addr->getCity(); $params['shippingPostcode'] = $addr->getPostal(); $params['shippingState'] = $addr->getState(); $params['shippingCountry'] = $addr->getCountryId(); $params['shippingPhone'] = $addr->getTelephone(); $params['shippingFax'] = $addr->getTelefax(); } } return new \Omnipay\Common\CreditCard($params); }