/** * Prepare and do request to shipment * * @param Mage_Sales_Model_Order_Shipment $orderShipment * @return Varien_Object */ public function requestToShipment(Mage_Sales_Model_Order_Shipment $orderShipment) { $admin = Mage::getSingleton('admin/session')->getUser(); $order = $orderShipment->getOrder(); $address = $order->getShippingAddress(); $selectedShipMethod = $this->_mapShipMethod($order->getShippingMethod(true), $order->getShippingCarrier(), $address); $shipmentStoreId = $orderShipment->getStoreId(); $shipmentCarrier = Mage::getModel('wsaendicia/carrier_endicia'); $shippingMethod = $this->_getShipmentCarrier($selectedShipMethod, $shipmentCarrier->getCarrierCode()); $baseCurrencyCode = Mage::app()->getStore($shipmentStoreId)->getBaseCurrencyCode(); if (!$shipmentCarrier) { Mage::throwException('Invalid carrier: ' . $shippingMethod->getCarrierCode()); } $shipperRegionCode = Mage::getStoreConfig(self::XML_PATH_STORE_REGION_ID, $shipmentStoreId); if (is_numeric($shipperRegionCode)) { $shipperRegionCode = Mage::getModel('directory/region')->load($shipperRegionCode)->getCode(); } $recipientRegionCode = Mage::getModel('directory/region')->load($address->getRegionId())->getCode(); $originStreet1 = Mage::getStoreConfig(self::XML_PATH_STORE_ADDRESS1, $shipmentStoreId); $originStreet2 = Mage::getStoreConfig(self::XML_PATH_STORE_ADDRESS2, $shipmentStoreId); $storeInfo = new Varien_Object(Mage::getStoreConfig('general/store_information', $shipmentStoreId)); if (!$admin->getFirstname() || !$admin->getLastname() || !$storeInfo->getName() || !$storeInfo->getPhone() || !$originStreet1 || !Mage::getStoreConfig(self::XML_PATH_STORE_CITY, $shipmentStoreId) || !$shipperRegionCode || !Mage::getStoreConfig(self::XML_PATH_STORE_ZIP, $shipmentStoreId) || !Mage::getStoreConfig(self::XML_PATH_STORE_COUNTRY_ID, $shipmentStoreId)) { Mage::throwException(Mage::helper('sales')->__('Insufficient information to create shipping label(s). Please verify your Store Information and Shipping Settings.')); } /** @var $request Mage_Shipping_Model_Shipment_Request */ $request = Mage::getModel('shipping/shipment_request'); $request->setOrderShipment($orderShipment); $request->setShipperContactPersonName($admin->getName()); $request->setShipperContactPersonFirstName($admin->getFirstname()); $request->setShipperContactPersonLastName($admin->getLastname()); $request->setShipperContactCompanyName($storeInfo->getName()); $request->setShipperContactPhoneNumber($storeInfo->getPhone()); $request->setShipperEmail($admin->getEmail()); $request->setShipperAddressStreet(trim($originStreet1 . ' ' . $originStreet2)); $request->setShipperAddressStreet1($originStreet1); $request->setShipperAddressStreet2($originStreet2); $request->setShipperAddressCity(Mage::getStoreConfig(self::XML_PATH_STORE_CITY, $shipmentStoreId)); $request->setShipperAddressStateOrProvinceCode($shipperRegionCode); $request->setShipperAddressPostalCode(Mage::getStoreConfig(self::XML_PATH_STORE_ZIP, $shipmentStoreId)); $request->setShipperAddressCountryCode(Mage::getStoreConfig(self::XML_PATH_STORE_COUNTRY_ID, $shipmentStoreId)); $request->setRecipientContactPersonName(trim($address->getFirstname() . ' ' . $address->getLastname())); $request->setRecipientContactPersonFirstName($address->getFirstname()); $request->setRecipientContactPersonLastName($address->getLastname()); $request->setRecipientContactCompanyName($address->getCompany()); $request->setRecipientContactPhoneNumber($address->getTelephone()); $request->setRecipientEmail($address->getEmail()); $request->setRecipientAddressStreet(trim($address->getStreet1() . ' ' . $address->getStreet2())); $request->setRecipientAddressStreet1($address->getStreet1()); $request->setRecipientAddressStreet2($address->getStreet2()); $request->setRecipientAddressCity($address->getCity()); $request->setRecipientAddressStateOrProvinceCode($address->getRegionCode()); $request->setRecipientAddressRegionCode($recipientRegionCode); $request->setRecipientAddressPostalCode($address->getPostcode()); $request->setRecipientAddressCountryCode($address->getCountryId()); $request->setShippingMethod($shippingMethod->getMethod()); $request->setPackageWeight($order->getWeight()); $request->setPackages($orderShipment->getPackages()); $request->setBaseCurrencyCode($baseCurrencyCode); $request->setStoreId($shipmentStoreId); return $shipmentCarrier->requestToShipment($request); }
/** * Provision a new account with SmartBear's AlertSite API and return any response * * @param $parameters * @throws Exception - error message encountered when provisioning * @return bool - was the account successfully provisioned? */ public function provisionAccount(Varien_Object $parameters) { //get the provisioning URL $url = self::ALERTSITE_PROVISION_API_URL; $apiFriendlyParams = array(); $apiFriendlyParams['fname'] = urlencode($parameters->getFirstName()); $apiFriendlyParams['lname'] = urlencode($parameters->getLastName()); $apiFriendlyParams['phone'] = urlencode($parameters->getPhone()); $apiFriendlyParams['company'] = urlencode($parameters->getCompanyName()); $apiFriendlyParams['api_version'] = urlencode('1.0'); $apiFriendlyParams['order_type'] = urlencode('magento'); $apiFriendlyParams['response_type'] = urlencode('xml'); $apiFriendlyParams['login_email'] = urlencode(strtolower($parameters->getLoginEmail())); $apiFriendlyParams['monitor_url'] = urlencode($parameters->getMonitorUrl()); $this->setPhone($parameters->getPhone()); $this->setCompany($apiFriendlyParams['company']); $this->setFName($apiFriendlyParams['fname']); $this->setLName($apiFriendlyParams['lname']); $response = $this->getCurlResponse($url, $apiFriendlyParams, 'POST', false); if (!$response) { throw new Exception("There was a problem provisioning your new account. Please try again or contact AlertSite support."); return false; } $status = (string) $response["status"]; if ($status == 'failed') { $error = $response->Error; $errorMessage = (string) $error['description']; if ((string) $error['code'] == "0001") { if ($error->missing_fields) { $count = count($error->missing_fields); $missingFields = ""; if ($count > 1) { foreach ($error->missing_fields as $missingField) { if ((string) $missingField['name'] == 'monitor_url') { $missingFields .= " - Monitor URL Required"; } else { if ((string) $missingField['name'] == 'login_email') { $missingFields .= " - Login Email Required"; } } } } else { if ((string) $error->missing_fields['name'] == 'monitor_url') { $missingFields .= " - Monitor URL Required"; } else { if ((string) $error->missing_fields['name'] == 'login_email') { $missingFields .= " - Login Email Required"; } } } $errorMessage .= $missingFields; } } throw new Exception($errorMessage); } else { if ($status == 'success') { $this->_newAlertSiteConfig($response->AccountCreated); return true; } } return false; }
/** * Prepare and do return of shipment * * @return Varien_Object */ public function requestToShipment() { $shipmentStoreId = $this->getRma()->getStoreId(); $storeInfo = new Varien_Object(Mage::getStoreConfig('general/store_information', $shipmentStoreId)); /** @var $order Mage_Sales_Model_Order */ $order = Mage::getModel('sales/order')->load($this->getRma()->getOrderId()); $shipperAddress = $order->getShippingAddress(); $recipientAddress = Mage::helper('enterprise_rma')->getReturnAddressModel($this->getRma()->getStoreId()); list($carrierCode, $shippingMethod) = explode('_', $this->getCode(), 2); $shipmentCarrier = Mage::helper('enterprise_rma')->getCarrier($this->getCode(), $shipmentStoreId); $baseCurrencyCode = Mage::app()->getStore($shipmentStoreId)->getBaseCurrencyCode(); if (!$shipmentCarrier) { Mage::throwException(Mage::helper('enterprise_rma')->__('Invalid carrier: %s.', $carrierCode)); } $shipperRegionCode = Mage::getModel('directory/region')->load($shipperAddress->getRegionId())->getCode(); $recipientRegionCode = $recipientAddress->getRegionId(); $recipientContactName = Mage::helper('enterprise_rma')->getReturnContactName($this->getRma()->getStoreId()); if (!$recipientContactName->getName() || !$recipientContactName->getLastName() || !$recipientAddress->getCompany() || !$storeInfo->getPhone() || !$recipientAddress->getStreet(-1) || !$recipientAddress->getCity() || !$shipperRegionCode || !$recipientAddress->getPostcode() || !$recipientAddress->getCountryId()) { Mage::throwException(Mage::helper('enterprise_rma')->__('Insufficient information to create shipping label(s). Please verify your Store Information and Shipping Settings.')); } /** @var $request Mage_Shipping_Model_Shipment_Request */ $request = Mage::getModel('shipping/shipment_return'); $request->setOrderShipment($this); $request->setShipperContactPersonName($order->getCustomerName()); $request->setShipperContactPersonFirstName($order->getCustomerFirstname()); $request->setShipperContactPersonLastName($order->getCustomerLastname()); $companyName = $shipperAddress->getCompany(); if (empty($companyName)) { $companyName = $order->getCustomerName(); } $request->setShipperContactCompanyName($companyName); $request->setShipperContactPhoneNumber($shipperAddress->getTelephone()); $request->setShipperEmail($shipperAddress->getEmail()); $request->setShipperAddressStreet($shipperAddress->getStreetFull()); $request->setShipperAddressStreet1($shipperAddress->getStreet1()); $request->setShipperAddressStreet2($shipperAddress->getStreet2()); $request->setShipperAddressCity($shipperAddress->getCity()); $request->setShipperAddressStateOrProvinceCode($shipperRegionCode); $request->setShipperAddressPostalCode($shipperAddress->getPostcode()); $request->setShipperAddressCountryCode($shipperAddress->getCountryId()); $request->setRecipientContactPersonName($recipientContactName->getName()); $request->setRecipientContactPersonFirstName($recipientContactName->getFirstName()); $request->setRecipientContactPersonLastName($recipientContactName->getLastName()); $request->setRecipientContactCompanyName($recipientAddress->getCompany()); $request->setRecipientContactPhoneNumber($storeInfo->getPhone()); $request->setRecipientEmail($recipientAddress->getEmail()); $request->setRecipientAddressStreet($recipientAddress->getStreet(-1)); $request->setRecipientAddressStreet1($recipientAddress->getStreet(1)); $request->setRecipientAddressStreet2($recipientAddress->getStreet2(2)); $request->setRecipientAddressCity($recipientAddress->getCity()); $request->setRecipientAddressStateOrProvinceCode($recipientRegionCode); $request->setRecipientAddressRegionCode($recipientRegionCode); $request->setRecipientAddressPostalCode($recipientAddress->getPostcode()); $request->setRecipientAddressCountryCode($recipientAddress->getCountryId()); $request->setShippingMethod($shippingMethod); $request->setPackageWeight($this->getWeight()); $request->setPackages($this->getPackages()); $request->setBaseCurrencyCode($baseCurrencyCode); $request->setStoreId($shipmentStoreId); $referenceData = 'RMA #' . $request->getOrderShipment()->getRma()->getIncrementId() . ' P'; $request->setReferenceData($referenceData); return $shipmentCarrier->returnOfShipment($request); }
/** * Sobrecarga da função assignData, acrecentado dados adicionais. * * @return Mage_Payment_Model_Method_Cc */ public function assignData($data) { $details = array(); if (!$data instanceof Varien_Object) { $data = new Varien_Object($data); } $info = $this->getInfoInstance(); $additionaldata = array('cc_parcelas' => $data->getCcParcelas(), 'cc_cid_enc' => $info->encrypt($data->getCcCid()), 'cpf_titular' => $data->getCcCpftitular(), 'day_titular' => $data->getCcDobDay(), 'month_titular' => $data->getCcDobMonth(), 'year_titular' => $data->getCcDobYear(), 'tel_titular' => $data->getPhone(), 'forma_pagamento' => $data->getCheckFormapagamento()); $info->setAdditionalData(serialize($additionaldata)); $info->setCcType($data->getCcType()); $info->setCcOwner($data->getCcOwner()); $info->setCcExpMonth($data->getCcExpMonth()); $info->setCcExpYear($data->getCcExpYear()); $info->setCcNumberEnc($info->encrypt($data->getCcNumber())); $info->setCcCidEnc($info->encrypt($data->getCcCid())); $info->setCcLast4(substr($data->getCcNumber(), -4)); $this->formaPagamento = $data->getCheckFormapagamento(); return $this; }