我正在尝试将自定义magento 1.9扩展迁移到magento 2.2 . 我已经做了很多搜索,并且可以尝试迁移 . 我最初跟随this tutorial进行1.9扩展 . 我知道有一个工具来帮助端口扩展,但我试图手动执行此操作,因为我无法让该工具为我的功能 .
每次更新购物车时,自定义送货延期都会运行,以计算自定义送货率 . 目标是在magento 2.2中重新创建此扩展,以便每次打开或更新购物车时,它将运行并计算运输成本,然后通过结账流程传播 .
以下是magento 1.9扩展的概述 . 关于如何将其转换为magento 2.2的任何建议?
/app/etc/modules/Extensions_Shipper.xml
<?xml version="1.0"?>
<config>
<modules>
<Extensions_Shipper>
<active>true</active>
<codePool>local</codePool>
<depends>
<Mage_Shipping />
</depends>
</Extensions_Shipper>
</modules>
/app/code/local/Extensions/Shipper/etc/config.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Extensions_Shipper>
<module>0.0.1</module>
</Extensions_Shipper>
</modules>
<global>
<models>
<extensions_shipper>
<class>Extensions_Shipper_Model</class>
</extensions_shipper>
</models>
</global>
<default>
<carriers>
<extensions_shipper>
<active>1</active>
<model>extensions_shipper/carrier</model>
<title>Shipping Options</title>
<sort_order>10</sort_order>
<sallowspecific>0</sallowspecific>
</extensions_shipper>
</carriers>
</default>
/app/code/local/Extensions/Shipper/Model/Carrier.php
<?php
class Extensions_Shipper_Model_Carrier extends Mage_Shipping_Model_Carrier_Abstract implements Mage_Shipping_Model_Carrier_Interface
{
public function collectRates(Mage_Shipping_Model_Rate_Request $request)
{
//Are there magento 2.2 equivalence for the following?
$addressInfo = Mage::getSingleton('checkout/session')->getQuote()->getShippingAddress()->getData();
$result = Mage::getModel('shipping/rate_result');
$items = Mage::getSingleton('checkout/session')->getQuote()->getAllItems();
$currentItem = Mage::getModel('catalog/product')->load($items[$itemsArray[$i]]->getProduct()->getId());
Mage::getSingleton('core/session')->addNotice('some text');
//$result = some calculations for shipping rate
return $result;
}
public function getAllowedMethods()
{
return array();
}
}
1 回答
您可以在
checkout_cart_add_product_complete
事件上创建事件观察器以执行逻辑以更新运输成本 .订阅
events.xml
中的活动:有关事件和观察员的信息,请参阅Magento文档:http://devdocs.magento.com/guides/v2.0/extension-dev-guide/events-and-observers.html
有关所有Magento 2.2事件的列表,请参阅:https://cyrillschumacher.com/magento-2.2-list-of-all-dispatched-events/