문제

우리는 기본 Magento CE v 1.9.1.0 USPS 배송 기능을 사용하고 있습니다.배송 라벨을 생성할 수 있는 API 자격 증명이 있습니다.

그러나 usps.com 웹사이트에서 USPS 배송 라벨을 생성할 때 주문 번호를 라벨에 추가하는 데 사용하는 배송 라벨에 참조 번호를 추가하는 옵션이 있습니다.

그러나 이제 Magento를 사용하여 배송 라벨을 생성하므로 Magento 개발자가 배송 라벨에 주문 번호를 볼 수 없으며 이제 USPS에 참조 번호로 주문 번호를 보내도록 코드를 변경하는 방법을 알고 싶습니다. Magento는 배송 라벨을 생성합니다.

편집할 파일에 대한 제안 사항이 있나요?

도움이 되었습니까?

해결책

라벨에 정보를 추가하려면 USPS로 전송된 xml을 수정해야 합니다.Magento는 배송 정보를 수집하여 xml로 변환한 다음 USPS API로 보내 이미지 파일을 반환합니다.그런 다음 Magento는 해당 이미지를 가져와 "배송 라벨 인쇄"를 클릭하면 얻을 수 있는 PDF를 생성합니다.

API에는 귀하의 목적에 맞는 "CustomerRefNo"라는 태그가 있습니다.다른 것을 시도하고 싶다면 usps 참조는 다음과 같습니다. 여기

이를 달성하기 위해 Yourcompany_UspsLabel이라는 모듈을 만들었습니다.명확성을 위해 모든 내용을 포함하겠습니다.

앱/코드/로컬/Yourcompany/UspsLabel/etc/config.xml

기본적으로 Magento는 귀하가 다시 작성 중인 내용을 알 수 있습니다.

<?xml version="1.0"?>
<config>
    <modules>
        <Yourcompany_UspsLabel>
            <version>0.1.0</version>
        </Yourcompany_UspsLabel>
    </modules>
    <global>
        <models>
            <yourcompany_uspslabel>
                <class>Yourcompany_UspsLabel_Model</class>
                <resourceModel>yourcompany_uspslabel_resource</resourceModel>
            </yourcompany_uspslabel>
            <yourcompany_uspslabel_resource>
                <class>Yourcompany_UspsLabel_Model_Resource</class>
            </yourcompany_uspslabel_resource>
            <shipping>
                <rewrite>
                    <shipping>Yourcompany_UspsLabel_Model_Shipping_Shipping</shipping>
                </rewrite>
            </shipping>
            <usa>
                <rewrite>
                    <shipping_carrier_usps>Yourcompany_UspsLabel_Model_Usa_Shipping_Carrier_Usps</shipping_carrier_usps>
                </rewrite>
            </usa>
        </models>
        <helpers>
            <yourcompany_uspslabel>
                <class>Yourcompany_UspsLabel_Helper</class>
            </yourcompany_uspslabel>
        </helpers>
    </global>
</config>

앱/코드/로컬/Yourcompany/UspsLabel/Model/Shipping/Shipment/Request.php

이 개체가 전달될 때 이를 사용할 수 있도록 하려면 끝에 있는 @methods(getOrderId 및 setOrderId)에 유의하세요.

/**
 * @method Yourcompany_UspsLabel_Model_Shipping_Shipment_Request setOrderShipment(Mage_Sales_Model_Order_Shipment $orderShipment)
 * @method Mage_Sales_Model_Order_Shipment getOrderShipment()
 * @method Yourcompany_UspsLabel_Model_Shipping_Shipment_Request setShipperContactPersonName(string $value)
 * @method string getShipperContactPersonName()
 * @method Yourcompany_UspsLabel_Model_Shipping_Shipment_Request setShipperContactPersonFirstName(string $value)
 * @method string getShipperContactPersonFirstName()
 * @method Yourcompany_UspsLabel_Model_Shipping_Shipment_Request setShipperContactPersonLastName(string $value)
 * @method string getShipperContactPersonLastName()
 * @method Yourcompany_UspsLabel_Model_Shipping_Shipment_Request setShipperContactCompanyName(string $value)
 * @method string getShipperContactCompanyName()
 * @method Yourcompany_UspsLabel_Model_Shipping_Shipment_Request setShipperContactPhoneNumber(int $value)
 * @method int getShipperContactPhoneNumber()
 * @method Yourcompany_UspsLabel_Model_Shipping_Shipment_Request setShipperAddressStreet(string $value)
 * @method string getShipperAddressStreet()
 * @method Yourcompany_UspsLabel_Model_Shipping_Shipment_Request setShipperAddressStreet1(string $value)
 * @method string getShipperAddressStreet1()
 * @method Yourcompany_UspsLabel_Model_Shipping_Shipment_Request setShipperAddressStreet2(string $value)
 * @method string getShipperAddressStreet2()
 * @method Yourcompany_UspsLabel_Model_Shipping_Shipment_Request setShipperAddressCity(string $value)
 * @method string getShipperAddressCity()
 * @method Yourcompany_UspsLabel_Model_Shipping_Shipment_Request setShipperAddressStateOrProvinceCode(string $value)
 * @method string getShipperAddressStateOrProvinceCode()
 * @method Yourcompany_UspsLabel_Model_Shipping_Shipment_Request setShipperAddressPostalCode(int $value)
 * @method int getShipperAddressPostalCode()
 * @method Yourcompany_UspsLabel_Model_Shipping_Shipment_Request setShipperAddressCountryCode(string $value)
 * @method string getShipperAddressCountryCode()
 * @method Yourcompany_UspsLabel_Model_Shipping_Shipment_Request setRecipientContactPersonName(string $value)
 * @method string getRecipientContactPersonName()
 * @method Yourcompany_UspsLabel_Model_Shipping_Shipment_Request setRecipientContactPersonFirstName(string $value)
 * @method string getRecipientContactPersonFirstName()
 * @method Yourcompany_UspsLabel_Model_Shipping_Shipment_Request setRecipientContactPersonLastName(string $value)
 * @method string getRecipientContactPersonLastName()
 * @method Yourcompany_UspsLabel_Model_Shipping_Shipment_Request setRecipientContactCompanyName(string $value)
 * @method string getRecipientContactCompanyName()
 * @method Yourcompany_UspsLabel_Model_Shipping_Shipment_Request setRecipientContactPhoneNumber(int $value)
 * @method int getRecipientContactPhoneNumber()
 * @method Yourcompany_UspsLabel_Model_Shipping_Shipment_Request setRecipientAddressStreet(string $value)
 * @method string getRecipientAddressStreet()
 * @method Yourcompany_UspsLabel_Model_Shipping_Shipment_Request setRecipientAddressStreet1(string $value)
 * @method string getRecipientAddressStreet1()
 * @method Yourcompany_UspsLabel_Model_Shipping_Shipment_Request setRecipientAddressStreet2(string $value)
 * @method string getRecipientAddressStreet2()
 * @method Yourcompany_UspsLabel_Model_Shipping_Shipment_Request setRecipientAddressCity(string $value)
 * @method string getRecipientAddressCity()
 * @method Yourcompany_UspsLabel_Model_Shipping_Shipment_Request setRecipientAddressStateOrProvinceCode(string $value)
 * @method string getRecipientAddressStateOrProvinceCode()
 * @method Yourcompany_UspsLabel_Model_Shipping_Shipment_Request setRecipientAddressPostalCode(int $value)
 * @method int getRecipientAddressPostalCode()
 * @method Yourcompany_UspsLabel_Model_Shipping_Shipment_Request setRecipientAddressCountryCode(string $value)
 * @method string getRecipientAddressCountryCode()
 * @method Yourcompany_UspsLabel_Model_Shipping_Shipment_Request setShippingMethod(string $value)
 * @method string getShippingMethod()
 * @method Yourcompany_UspsLabel_Model_Shipping_Shipment_Request setPackageWeight(float $value)
 * @method float getPackageWeight()
 * @method Yourcompany_UspsLabel_Model_Shipping_Shipment_Request setOrderId(string $value)
 * @method string getOrderId()
 *
 * @category    Mage
 * @package     Mage_Shipping
 * @author      Magento Core Team <core@magentocommerce.com>
 */
class Yourcompany_UspsLabel_Model_Shipping_Shipment_Request extends Mage_Shipping_Model_Shipment_Request
{
}

앱/코드/로컬/Yourcompany/UspsLabel/Model/Shipping/Shipping.php

여기서 유일한 변경 사항은 주문의 증분 ID를 추가하는 것입니다. $request->setOrderId($order->getIncrementId());, 의 끝에서 requestToShipment 기능.

<?php

class Yourcompany_UspsLabel_Model_Shipping_Shipping extends Mage_Shipping_Model_Shipping {

    public function requestToShipment(Mage_Sales_Model_Order_Shipment $orderShipment)
    {
        $admin = Mage::getSingleton('admin/session')->getUser();
        $order = $orderShipment->getOrder();
        $address = $order->getShippingAddress();
        $shippingMethod = $order->getShippingMethod(true);
        $shipmentStoreId = $orderShipment->getStoreId();
        $shipmentCarrier = $order->getShippingCarrier();
        $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);
        $request->setOrderId($order->getIncrementId());

        return $shipmentCarrier->requestToShipment($request);
    }
}

앱/코드/로컬/Yourcompany/UspsLabel/Model/Usa/Shipping/Carrier/Usps.php

StackExchange가 글자 수 제한을 초과하여 다음 비트를 붙여넣을 수 없게 했습니다.페이스트를 만들었어요 여기.이 파일의 변경 사항은 간단합니다. 추가하기만 하면 됩니다. $xml->addChild('CustomerRefNo', $request->getOrderId()); 각 XML 생성 기능에 - _formUsExpressShipmentRequest, _formUsSignatureConfirmationShipmentRequest, 그리고 _formIntlShipmentRequest.이것은 추가되어야합니다 ~ 후에 그만큼 $xml->addChild('ImageType', 'PDF'); 전화.

앱/etc/modules/Yourcompany_UspsLabel.xml왜냐면, 당신은 하나가 필요할 것이기 때문입니다.

<?xml version="1.0"?>
<config>
    <modules>
        <Yourcompany_UspsLabel>
            <active>true</active>
            <codePool>local</codePool>
        </Yourcompany_UspsLabel>
    </modules>
</config>

라벨에서 주문 번호를 볼 수 있습니다. 오른쪽, 무게 아래에 있습니다. Ref:145000008.

label with order number

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 magento.stackexchange
scroll top