本文整理汇总了PHP中Magento\Framework\Object::getShipperAddressCountryCode方法的典型用法代码示例。如果您正苦于以下问题:PHP Object::getShipperAddressCountryCode方法的具体用法?PHP Object::getShipperAddressCountryCode怎么用?PHP Object::getShipperAddressCountryCode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\Object
的用法示例。
在下文中一共展示了Object::getShipperAddressCountryCode方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _formShipmentRequest
/**
* Form array with appropriate structure for shipment request
*
* @param \Magento\Framework\Object $request
* @return array
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
protected function _formShipmentRequest(\Magento\Framework\Object $request)
{
if ($request->getReferenceData()) {
$referenceData = $request->getReferenceData() . $request->getPackageId();
} else {
$referenceData = 'Order #' . $request->getOrderShipment()->getOrder()->getIncrementId() . ' P' . $request->getPackageId();
}
$packageParams = $request->getPackageParams();
$customsValue = $packageParams->getCustomsValue();
$height = $packageParams->getHeight();
$width = $packageParams->getWidth();
$length = $packageParams->getLength();
$weightUnits = $packageParams->getWeightUnits() == \Zend_Measure_Weight::POUND ? 'LB' : 'KG';
$dimensionsUnits = $packageParams->getDimensionUnits() == \Zend_Measure_Length::INCH ? 'IN' : 'CM';
$unitPrice = 0;
$itemsQty = 0;
$itemsDesc = [];
$countriesOfManufacture = [];
$productIds = [];
$packageItems = $request->getPackageItems();
foreach ($packageItems as $itemShipment) {
$item = new \Magento\Framework\Object();
$item->setData($itemShipment);
$unitPrice += $item->getPrice();
$itemsQty += $item->getQty();
$itemsDesc[] = $item->getName();
$productIds[] = $item->getProductId();
}
// get countries of manufacture
$productCollection = $this->_productCollectionFactory->create()->addStoreFilter($request->getStoreId())->addFieldToFilter('entity_id', ['in' => $productIds])->addAttributeToSelect('country_of_manufacture');
foreach ($productCollection as $product) {
$countriesOfManufacture[] = $product->getCountryOfManufacture();
}
$paymentType = $request->getIsReturn() ? 'RECIPIENT' : 'SENDER';
$requestClient = ['RequestedShipment' => ['ShipTimestamp' => time(), 'DropoffType' => $this->getConfigData('dropoff'), 'PackagingType' => $request->getPackagingType(), 'ServiceType' => $request->getShippingMethod(), 'Shipper' => ['Contact' => ['PersonName' => $request->getShipperContactPersonName(), 'CompanyName' => $request->getShipperContactCompanyName(), 'PhoneNumber' => $request->getShipperContactPhoneNumber()], 'Address' => ['StreetLines' => [$request->getShipperAddressStreet()], 'City' => $request->getShipperAddressCity(), 'StateOrProvinceCode' => $request->getShipperAddressStateOrProvinceCode(), 'PostalCode' => $request->getShipperAddressPostalCode(), 'CountryCode' => $request->getShipperAddressCountryCode()]], 'Recipient' => ['Contact' => ['PersonName' => $request->getRecipientContactPersonName(), 'CompanyName' => $request->getRecipientContactCompanyName(), 'PhoneNumber' => $request->getRecipientContactPhoneNumber()], 'Address' => ['StreetLines' => [$request->getRecipientAddressStreet()], 'City' => $request->getRecipientAddressCity(), 'StateOrProvinceCode' => $request->getRecipientAddressStateOrProvinceCode(), 'PostalCode' => $request->getRecipientAddressPostalCode(), 'CountryCode' => $request->getRecipientAddressCountryCode(), 'Residential' => (bool) $this->getConfigData('residence_delivery')]], 'ShippingChargesPayment' => ['PaymentType' => $paymentType, 'Payor' => ['AccountNumber' => $this->getConfigData('account'), 'CountryCode' => $this->_scopeConfig->getValue(\Magento\Sales\Model\Order\Shipment::XML_PATH_STORE_COUNTRY_ID, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $request->getStoreId())]], 'LabelSpecification' => ['LabelFormatType' => 'COMMON2D', 'ImageType' => 'PNG', 'LabelStockType' => 'PAPER_8.5X11_TOP_HALF_LABEL'], 'RateRequestTypes' => ['ACCOUNT'], 'PackageCount' => 1, 'RequestedPackageLineItems' => ['SequenceNumber' => '1', 'Weight' => ['Units' => $weightUnits, 'Value' => $request->getPackageWeight()], 'CustomerReferences' => ['CustomerReferenceType' => 'CUSTOMER_REFERENCE', 'Value' => $referenceData], 'SpecialServicesRequested' => ['SpecialServiceTypes' => 'SIGNATURE_OPTION', 'SignatureOptionDetail' => ['OptionType' => $packageParams->getDeliveryConfirmation()]]]]];
// for international shipping
if ($request->getShipperAddressCountryCode() != $request->getRecipientAddressCountryCode()) {
$requestClient['RequestedShipment']['CustomsClearanceDetail'] = ['CustomsValue' => ['Currency' => $request->getBaseCurrencyCode(), 'Amount' => $customsValue], 'DutiesPayment' => ['PaymentType' => $paymentType, 'Payor' => ['AccountNumber' => $this->getConfigData('account'), 'CountryCode' => $this->_scopeConfig->getValue(\Magento\Sales\Model\Order\Shipment::XML_PATH_STORE_COUNTRY_ID, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $request->getStoreId())]], 'Commodities' => ['Weight' => ['Units' => $weightUnits, 'Value' => $request->getPackageWeight()], 'NumberOfPieces' => 1, 'CountryOfManufacture' => implode(',', array_unique($countriesOfManufacture)), 'Description' => implode(', ', $itemsDesc), 'Quantity' => ceil($itemsQty), 'QuantityUnits' => 'pcs', 'UnitPrice' => ['Currency' => $request->getBaseCurrencyCode(), 'Amount' => $unitPrice], 'CustomsValue' => ['Currency' => $request->getBaseCurrencyCode(), 'Amount' => $customsValue]]];
}
if ($request->getMasterTrackingId()) {
$requestClient['RequestedShipment']['MasterTrackingId'] = $request->getMasterTrackingId();
}
// set dimensions
if ($length || $width || $height) {
$requestClient['RequestedShipment']['RequestedPackageLineItems']['Dimensions'] = [];
$dimenssions =& $requestClient['RequestedShipment']['RequestedPackageLineItems']['Dimensions'];
$dimenssions['Length'] = $length;
$dimenssions['Width'] = $width;
$dimenssions['Height'] = $height;
$dimenssions['Units'] = $dimensionsUnits;
}
return $this->_getAuthDetails() + $requestClient;
}
示例2: _mapRequestToShipment
/**
* Map request to shipment
*
* @param \Magento\Framework\Object $request
* @return void
* @throws \Magento\Framework\Model\Exception
*/
protected function _mapRequestToShipment(\Magento\Framework\Object $request)
{
$request->setOrigCountryId($request->getShipperAddressCountryCode());
$this->setRawRequest($request);
$customsValue = 0;
$packageWeight = 0;
$packages = $request->getPackages();
foreach ($packages as &$piece) {
$params = $piece['params'];
if ($params['width'] || $params['length'] || $params['height']) {
$minValue = $this->_getMinDimension($params['dimension_units']);
if ($params['width'] < $minValue || $params['length'] < $minValue || $params['height'] < $minValue) {
$message = __('Height, width and length should be equal or greater than %1', $minValue);
throw new \Magento\Framework\Model\Exception($message);
}
}
$weightUnits = $piece['params']['weight_units'];
$piece['params']['height'] = $this->_getDimension($piece['params']['height'], $weightUnits);
$piece['params']['length'] = $this->_getDimension($piece['params']['length'], $weightUnits);
$piece['params']['width'] = $this->_getDimension($piece['params']['width'], $weightUnits);
$piece['params']['dimension_units'] = $this->_getDimensionUnit();
$piece['params']['weight'] = $this->_getWeight($piece['params']['weight'], false, $weightUnits);
$piece['params']['weight_units'] = $this->_getWeightUnit();
$customsValue += $piece['params']['customs_value'];
$packageWeight += $piece['params']['weight'];
}
$request->setPackages($packages)->setPackageWeight($packageWeight)->setPackageValue($customsValue)->setValueWithDiscount($customsValue)->setPackageCustomsValue($customsValue)->setFreeMethodWeight(0);
}
示例3: _formShipmentRequest
/**
* Form XML for shipment request
*
* @param \Magento\Framework\Object $request
* @return string
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
protected function _formShipmentRequest(\Magento\Framework\Object $request)
{
$packageParams = $request->getPackageParams();
$height = $packageParams->getHeight();
$width = $packageParams->getWidth();
$length = $packageParams->getLength();
$weightUnits = $packageParams->getWeightUnits() == \Zend_Measure_Weight::POUND ? 'LBS' : 'KGS';
$dimensionsUnits = $packageParams->getDimensionUnits() == \Zend_Measure_Length::INCH ? 'IN' : 'CM';
$itemsDesc = [];
$itemsShipment = $request->getPackageItems();
foreach ($itemsShipment as $itemShipment) {
$item = new \Magento\Framework\Object();
$item->setData($itemShipment);
$itemsDesc[] = $item->getName();
}
$xmlRequest = $this->_xmlElFactory->create(['data' => '<?xml version = "1.0" ?><ShipmentConfirmRequest xml:lang="en-US"/>']);
$requestPart = $xmlRequest->addChild('Request');
$requestPart->addChild('RequestAction', 'ShipConfirm');
$requestPart->addChild('RequestOption', 'nonvalidate');
$shipmentPart = $xmlRequest->addChild('Shipment');
if ($request->getIsReturn()) {
$returnPart = $shipmentPart->addChild('ReturnService');
// UPS Print Return Label
$returnPart->addChild('Code', '9');
}
$shipmentPart->addChild('Description', substr(implode(' ', $itemsDesc), 0, 35));
//empirical
$shipperPart = $shipmentPart->addChild('Shipper');
if ($request->getIsReturn()) {
$shipperPart->addChild('Name', $request->getRecipientContactCompanyName());
$shipperPart->addChild('AttentionName', $request->getRecipientContactPersonName());
$shipperPart->addChild('ShipperNumber', $this->getConfigData('shipper_number'));
$shipperPart->addChild('PhoneNumber', $request->getRecipientContactPhoneNumber());
$addressPart = $shipperPart->addChild('Address');
$addressPart->addChild('AddressLine1', $request->getRecipientAddressStreet());
$addressPart->addChild('AddressLine2', $request->getRecipientAddressStreet2());
$addressPart->addChild('City', $request->getRecipientAddressCity());
$addressPart->addChild('CountryCode', $request->getRecipientAddressCountryCode());
$addressPart->addChild('PostalCode', $request->getRecipientAddressPostalCode());
if ($request->getRecipientAddressStateOrProvinceCode()) {
$addressPart->addChild('StateProvinceCode', $request->getRecipientAddressStateOrProvinceCode());
}
} else {
$shipperPart->addChild('Name', $request->getShipperContactCompanyName());
$shipperPart->addChild('AttentionName', $request->getShipperContactPersonName());
$shipperPart->addChild('ShipperNumber', $this->getConfigData('shipper_number'));
$shipperPart->addChild('PhoneNumber', $request->getShipperContactPhoneNumber());
$addressPart = $shipperPart->addChild('Address');
$addressPart->addChild('AddressLine1', $request->getShipperAddressStreet());
$addressPart->addChild('AddressLine2', $request->getShipperAddressStreet2());
$addressPart->addChild('City', $request->getShipperAddressCity());
$addressPart->addChild('CountryCode', $request->getShipperAddressCountryCode());
$addressPart->addChild('PostalCode', $request->getShipperAddressPostalCode());
if ($request->getShipperAddressStateOrProvinceCode()) {
$addressPart->addChild('StateProvinceCode', $request->getShipperAddressStateOrProvinceCode());
}
}
$shipToPart = $shipmentPart->addChild('ShipTo');
$shipToPart->addChild('AttentionName', $request->getRecipientContactPersonName());
$shipToPart->addChild('CompanyName', $request->getRecipientContactCompanyName() ? $request->getRecipientContactCompanyName() : 'N/A');
$shipToPart->addChild('PhoneNumber', $request->getRecipientContactPhoneNumber());
$addressPart = $shipToPart->addChild('Address');
$addressPart->addChild('AddressLine1', $request->getRecipientAddressStreet1());
$addressPart->addChild('AddressLine2', $request->getRecipientAddressStreet2());
$addressPart->addChild('City', $request->getRecipientAddressCity());
$addressPart->addChild('CountryCode', $request->getRecipientAddressCountryCode());
$addressPart->addChild('PostalCode', $request->getRecipientAddressPostalCode());
if ($request->getRecipientAddressStateOrProvinceCode()) {
$addressPart->addChild('StateProvinceCode', $request->getRecipientAddressRegionCode());
}
if ($this->getConfigData('dest_type') == 'RES') {
$addressPart->addChild('ResidentialAddress');
}
if ($request->getIsReturn()) {
$shipFromPart = $shipmentPart->addChild('ShipFrom');
$shipFromPart->addChild('AttentionName', $request->getShipperContactPersonName());
$shipFromPart->addChild('CompanyName', $request->getShipperContactCompanyName() ? $request->getShipperContactCompanyName() : $request->getShipperContactPersonName());
$shipFromAddress = $shipFromPart->addChild('Address');
$shipFromAddress->addChild('AddressLine1', $request->getShipperAddressStreet1());
$shipFromAddress->addChild('AddressLine2', $request->getShipperAddressStreet2());
$shipFromAddress->addChild('City', $request->getShipperAddressCity());
$shipFromAddress->addChild('CountryCode', $request->getShipperAddressCountryCode());
$shipFromAddress->addChild('PostalCode', $request->getShipperAddressPostalCode());
if ($request->getShipperAddressStateOrProvinceCode()) {
$shipFromAddress->addChild('StateProvinceCode', $request->getShipperAddressStateOrProvinceCode());
}
$addressPart = $shipToPart->addChild('Address');
$addressPart->addChild('AddressLine1', $request->getShipperAddressStreet1());
$addressPart->addChild('AddressLine2', $request->getShipperAddressStreet2());
$addressPart->addChild('City', $request->getShipperAddressCity());
$addressPart->addChild('CountryCode', $request->getShipperAddressCountryCode());
//.........这里部分代码省略.........