Magento Checkout 中的多个来源邮政编码

发布于 2024-11-01 00:59:08 字数 432 浏览 7 评论 0原文

我正在为客户开发 Magento 店面。他们使用直销商,因此单个邮政编码对我们没有多大帮助。我们确实将其设置为客户端发货时最常见的邮政编码,因此,在许多情况下,这是可以的。

但是,在某些情况下,需要使用不同的来源邮政编码。在极少数情况下,我们将有多个来源邮政编码。当有一个 zip 与主 zip 不同时,我们将其存储在名为“origin zip”的属性中(有创意,嗯?)

我应该在哪里进行修改?我们只使用 UPS 运输方式,我想做的是,在计算运输之前,获取购物车中可能存在的任何原产地邮政编码(我认为我们已经有了这部分),但是,然后,取决于结果,我可能需要迭代运输计算并将这些值加在一起 ​​- 即,如果他们订购一种具有原产地邮政编码的产品,而另一种没有原产地邮政编码的产品,则必须计算第一个,然后第二个,然后将它们加在一起。

如果有人能指出我们需要修改哪些 php 文件或类的正确方向,我将不胜感激。

I'm working on a Magento storefront for a client. They use dropshippers, so a single zip code doesn't do us much help. We do have it set for the most common zip code from which the client ships, so, in many cases, it's ok.

However, in some cases, there is a different origin zip code that needs to be used. In more rare cases, we will have multiple origin zip codes. When there is a zip that differs from the main one, we have stored this in an attribute called 'origin zip' (creative, huh?)

Where should I be looking to make the modifications? We're only using the UPS shipping method, and what I'm looking to do is, before calculating shipping, to grab whatever origin zips may be in the cart (I think we've got this part), but then, depending on the results, I may need to iterate through the shipping calculation and add the values together - i.e. in the case they order one product with an origin zip code, and another product without an origin zip code, it would have to calculate the first, then the second, and then add them together.

If someone could point us in the correct direction of which php files or classes we'll need to modify, I would greatly appreciate it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

静谧幽蓝 2024-11-08 00:59:08

首先,您需要将自定义属性添加到将在购物车中使用的属性列表。
请遵循 stackoverflow 上的以下答案:
如何在 magento 1.4.1.1 中将自定义上传的图像添加到购物车?

然后您需要创建自定义的运输方式,也许可以从您的方式扩展。它应该遍历从运输请求中收到的物品并检查不同的邮政编码来源,然后分别计算它们的费率。

我希望您创建一个扩展现有运输方式功能的模块不会成为问题。

干杯!

更新
要将您的属性添加到购物车项目中加载的产品,请使用以下配置:

<config>
     <global>
          <sales>
               <quote>
                    <item>
                        <product_attributes>
                             <origin_zip />
                        </product_attributes>
                    </item>
               </quote>
          </sales>
     </global>
</config>

然后在运输方式模型中使用类似这样的内容(以 USPS 为例):

public function collectRates(Mage_Shipping_Model_Rate_Request $request)
{
    if (!$this->getConfigFlag('active')) {
        return false;
    }

    $defaultOriginZip = Mage::getStoreConfig('shipping/origin/postcode', $this->getStore());

    $requestDataByOriginZip = array();
    // Walking through quote items
    foreach ($request->getAllItems() as $quoteItem) {
        // If virtual or not shippable separately, it should be skipped
        if ($quoteItem->isVirtual() || $quoteItem->isDummy(true)) {
            continue;
        }
        // Retrieving origin zip code
        if ($quoteItem->getProduct()->getOriginZip()) {
            $zipCodeForCalculation = $quoteItem->getProduct()->getOriginZip();
        } else {
            $zipCodeForCalculation = $defaultOriginZip;
        }

        if (!isset($requestDataByOriginZip[$zipCodeForCalculation])) {
            // Default values initialization for this zip code
            $requestDataByOriginZip[$zipCodeForCalculation] = array(
                'orig_postcode' => $zipCodeForCalculation,
                'package_weight' => 0,
                'package_value' => 0,
                // etc...
            );
        }

        $requestDataByOriginZip[$zipCodeForCalculation]['package_weight'] += $quoteItem->getRowWeight();
        $requestDataByOriginZip[$zipCodeForCalculation]['package_value'] += $quoteItem->getBaseRowTotal();
        // Etc...
    }

    $results = array();
    foreach ($requestDataByOriginZip as $requestData) {
       $requestByZip = clone $request; // Cloning to prevent changing logic in other shipment methods.
       $requestByZip->addData($requestData);
       $this->setRequest($requestByZip);
       // Returns rate result for current request
       $results[] = $this->_getQuotes();
    }

    $yourMergedResult = Mage::getModel('shipping/rate_result');

    foreach ($results as $result) {
       // Logic for merging the rate prices....
    }

    return $yourMergedResult;
}

First of all you need to add your custom attributed to list of attributes that will be used in shopping cart.
Follow these answer on stackoverflow:
How to add custom uploaded images to cart in magento 1.4.1.1?

Then you need to create your custom shipping method, maybe extended from yours one. It should walk through items it receives from shipping request and check for different zip origin, then calculate rate for them separately.

I hope for you it will not be a problem to create a module that will extend existing shipping method functionality.

Cheers!

UPDATE
For adding your attribute to product that is loaded in the cart item use such configuration:

<config>
     <global>
          <sales>
               <quote>
                    <item>
                        <product_attributes>
                             <origin_zip />
                        </product_attributes>
                    </item>
               </quote>
          </sales>
     </global>
</config>

Then in shipping method model use something like this (used USPS as example):

public function collectRates(Mage_Shipping_Model_Rate_Request $request)
{
    if (!$this->getConfigFlag('active')) {
        return false;
    }

    $defaultOriginZip = Mage::getStoreConfig('shipping/origin/postcode', $this->getStore());

    $requestDataByOriginZip = array();
    // Walking through quote items
    foreach ($request->getAllItems() as $quoteItem) {
        // If virtual or not shippable separately, it should be skipped
        if ($quoteItem->isVirtual() || $quoteItem->isDummy(true)) {
            continue;
        }
        // Retrieving origin zip code
        if ($quoteItem->getProduct()->getOriginZip()) {
            $zipCodeForCalculation = $quoteItem->getProduct()->getOriginZip();
        } else {
            $zipCodeForCalculation = $defaultOriginZip;
        }

        if (!isset($requestDataByOriginZip[$zipCodeForCalculation])) {
            // Default values initialization for this zip code
            $requestDataByOriginZip[$zipCodeForCalculation] = array(
                'orig_postcode' => $zipCodeForCalculation,
                'package_weight' => 0,
                'package_value' => 0,
                // etc...
            );
        }

        $requestDataByOriginZip[$zipCodeForCalculation]['package_weight'] += $quoteItem->getRowWeight();
        $requestDataByOriginZip[$zipCodeForCalculation]['package_value'] += $quoteItem->getBaseRowTotal();
        // Etc...
    }

    $results = array();
    foreach ($requestDataByOriginZip as $requestData) {
       $requestByZip = clone $request; // Cloning to prevent changing logic in other shipment methods.
       $requestByZip->addData($requestData);
       $this->setRequest($requestByZip);
       // Returns rate result for current request
       $results[] = $this->_getQuotes();
    }

    $yourMergedResult = Mage::getModel('shipping/rate_result');

    foreach ($results as $result) {
       // Logic for merging the rate prices....
    }

    return $yourMergedResult;
}
故事与诗 2024-11-08 00:59:08

usa/shipping_ups 类负责处理这些请求,具体而言,setRequest 方法似乎满足您的需求:

    if ($request->getOrigPostcode()) {
        $r->setOrigPostal($request->getOrigPostcode());
    } else {
        $r->setOrigPostal(Mage::getStoreConfig('shipping/origin/postcode', $this->getStore()));
    }  

如果您可以将 orig_postcode 添加到运输请求中,UPS 将返回基于该来源的报价。

一种方法是重写 Mage_Shipping_Model_Rate_Request 并添加一个名为 getOrigPostcode 的方法。由于是一个真正的方法,这将覆盖默认的 Magento getter/setter 行为。让此方法查询请求的内容以找出需要使用哪个 zip。

希望有帮助!

谢谢,

The class usa/shipping_ups is what handles these requests, and specifically the method setRequest seems to have what you need:

    if ($request->getOrigPostcode()) {
        $r->setOrigPostal($request->getOrigPostcode());
    } else {
        $r->setOrigPostal(Mage::getStoreConfig('shipping/origin/postcode', $this->getStore()));
    }  

If you can add the orig_postcode to the shipping request, UPS will return a quote based on that origin.

One approach to this would be to override Mage_Shipping_Model_Rate_Request and add a method called getOrigPostcode. By virtue of being a real method, this would override the default Magento getter/setter behavior. Have this method query the contents of the request to find out which zip needs to be used.

Hope that helps!

Thanks,
Joe

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文