Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

How do I get the product id on shipping module? 
 
PedroTeixeira
Sr. Member
 
Avatar
Total Posts:  136
Joined:  2008-05-28
Berlin, Germany
 

Hi guys,

Sorry for my English, I’m from Brazil.

I’m developing the shipping module for a Brazilian carrier and we have an exception here, the module has three carriers, and just one can post products with more than 1,50 centimeters.

For doing this I have to get the width and height of all the products in the cart and look for it in all Magento forum and I haven’t found anything.

Does anybody know how I get the width and/or height variable in the shipping module?

If no one knows, I have another solution: select the products that can’t use this carrier, to do that, I need to know the products id’s and this is another question, how do I get the products id in the shopping cart on the shipping module?

That’s all!

Thanks to all!

 
Magento Community Magento Community
Magento Community
Magento Community
 
cwpollock
Sr. Member
 
Avatar
Total Posts:  117
Joined:  2008-01-09
Rochester, NY
 

This is how I got at a custom attribute from the shipping module in the collectRates function

$_items $request->getAllItems();
        
foreach (
$_items as $_item)
{
          $_prod_id 
$_item->getProductId();
            
          
// get the attributes of a product
          
$product Mage::getModel('catalog/product')->load($_prod_id); 

          
$shipping_type $product->getResource()->getAttribute('shipping_flag')->getFrontend()->getValue($product);

         
// ... more stuff here... 
        
}
 
Magento Community Magento Community
Magento Community
Magento Community
 
PedroTeixeira
Sr. Member
 
Avatar
Total Posts:  136
Joined:  2008-05-28
Berlin, Germany
 

Hi cwpollock,

Thank you very very much!

As soon as I test the code I post the feedback here.

Thank’s again!

 
Magento Community Magento Community
Magento Community
Magento Community
 
PedroTeixeira
Sr. Member
 
Avatar
Total Posts:  136
Joined:  2008-05-28
Berlin, Germany
 

Hi cwpollock,

Sorry to bother you.

I try this:

$_items = $request->getAllItems();

foreach ($_items as $_item)
{
$_prod_id = $_item->getProductId();
echo $_prod_id . “<br />”;
}

And the return is:

Warning: Invalid argument supplied for foreach() in /home/universoexecutivo/public_html/app/code/community/Exportafacil/Shipping/Model/Carrier/ExportaPost.php on line 106
Trace:
#0 /home/universoexecutivo/public_html/app/code/community/Exportafacil/Shipping/Model/Carrier/ExportaPost.php(106): mageCoreErrorHandler(2, ‘Invalid argumen...’, ‘/home/universoe...’, 106, Array)
#1 /home/universoexecutivo/public_html/app/code/core/Mage/Shipping/Model/Shipping.php(132): Exportafacil_Shipping_Model_Carrier_ExportaPost->collectRates(Object(Mage_Shipping_Model_Rate_Request))
#2 /home/universoexecutivo/public_html/app/code/core/Mage/Shipping/Model/Shipping.php(101): Mage_Shipping_Model_Shipping->collectCarrierRates(’exportapost’, Object(Mage_Shipping_Model_Rate_Request))
#3 /home/universoexecutivo/public_html/app/code/core/Mage/Sales/Model/Quote/Address.php(463): Mage_Shipping_Model_Shipping->collectRates(Object(Mage_Shipping_Model_Rate_Request))
#4 /home/universoexecutivo/public_html/app/code/core/Mage/Sales/Model/Quote/Address/Total/Shipping.php(59): Mage_Sales_Model_Quote_Address->collectShippingRates()
#5 /home/universoexecutivo/public_html/app/code/core/Mage/Sales/Model/Quote/Address.php(517): Mage_Sales_Model_Quote_Address_Total_Shipping->collect(Object(Mage_Sales_Model_Quote_Address))
#6 /home/universoexecutivo/public_html/app/code/core/Mage/Sales/Model/Quote.php(841): Mage_Sales_Model_Quote_Address->collectTotals()
#7 /home/universoexecutivo/public_html/app/code/core/Mage/Checkout/Model/Cart.php(395): Mage_Sales_Model_Quote->collectTotals()
#8 /home/universoexecutivo/public_html/app/code/core/Mage/Checkout/controllers/CartController.php(71): Mage_Checkout_Model_Cart->save()
#9 /home/universoexecutivo/public_html/app/code/core/Mage/Core/Controller/Varien/Action.php(342): Mage_Checkout_CartController->indexAction()
#10 /home/universoexecutivo/public_html/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(159): Mage_Core_Controller_Varien_Action->dispatch(’index’)
#11 /home/universoexecutivo/public_html/app/code/core/Mage/Core/Controller/Varien/Front.php(146): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#12 /home/universoexecutivo/public_html/app/Mage.php(427): Mage_Core_Controller_Varien_Front->dispatch()
#13 /home/universoexecutivo/public_html/index.php(40): Mage::run()
#14 {main}

What I made wrong?

 
Magento Community Magento Community
Magento Community
Magento Community
 
PedroTeixeira
Sr. Member
 
Avatar
Total Posts:  136
Joined:  2008-05-28
Berlin, Germany
 

No one is gonna help me?

I realy need this.

Thank’s!

 
Magento Community Magento Community
Magento Community
Magento Community
 
jonshawver
Jr. Member
 
Total Posts:  7
Joined:  2011-10-29
 

I know this post is ancient but that code just worked a treat on 1.7.0.2 thanks @cwpollock

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top