Magento Forum

   
Compare or sum attributes and show the result in the cart and in the order
 
ricardoinvent
Member
 
Total Posts:  37
Joined:  2012-10-29
 

Friends how are you?

I need your help please!!. Maybe this is quite simple but I can’t figure it out what is the best way to achieve this. I have an attribute (named time for delivery) and it has values like (7, 14, 21, 28) representing the days each product has for delivery. Then I need to show a sentence in the cart that shows the user the time of delivery for the entire order.

For example:
Product “A” (time for delivery) = 1 day
Product “B” (time for delivery) = 2 days

Then I need to compare and set the major number as the default entire order delivery time. In php this is quite simple but in Magento I don’t know exactly what file I need to override or where I can create a function to show that value in my template template/checkout/cart.phtml and finally send it by email or store it in the DB.

I know the logic of the script and the function could be something like this:

public function getCustomDeliveryTime(){

$delivery
=array();

foreach(...)
//This is part of my doubt, what array I should iterate to get the product with the attribute data ??
$product=Mage::getModel('catalog/product')->load($_item->getProductId());
$delivery[]=$product->getAttributeText('time_for_delivery');
}
$delivery_time 
="The time for delivery for this order is: ".max($delivery);

return 
$delivery_time;

}

Any kind of help will be highly appreciated.

Warming regards and many thanks!!

 
Magento Community Magento Community
Magento Community
Magento Community
 
ricardoinvent
Member
 
Total Posts:  37
Joined:  2012-10-29
 

Friends,

Could someone give me an idea ?..

Warming regards!!

 
Magento Community Magento Community
Magento Community
Magento Community
 
ricardoinvent
Member
 
Total Posts:  37
Joined:  2012-10-29
 

Friends, any update on this?

I was thinking if use a session variable could be an option.. Maybe to store the delivery attribute in a session variable could be usefull?

Regards!!

 
Magento Community Magento Community
Magento Community
Magento Community
 
ricardoinvent
Member
 
Total Posts:  37
Joined:  2012-10-29
 

Hello,

I’ve succesfully get this mod by using observers. I use checkout_cart_product_add_after… (hope it helps somebody else)…

class Sixplus_TiempoEntrega_Model_Observer {
    
    
public function tiempo_entrega_total(Varien_Event_Observer $observer){

    $tiempo_envio
=array();
        
    
$session Mage::getSingleton('checkout/session');
    foreach (
$session->getQuote()->getAllItems() as $item{
        
    $productId 
$item->getProduct()->getId();
        
$productList Mage::getModel('catalog/product')->getCollection()
             ->
addAttributeToSelect('tiempo_de_entrega_aproximado')
            ->
addIdFilter($productId);
        
        foreach(
$productList as $product)
        
{            
            $tiempo_envio[]
$product->getAttributeText('tiempo_de_entrega_aproximado');
        
}
        
    }
    
(int)$tiempo_envio_total=max($tiempo_envio);

//You can save it in the DB or in a session or whatever you need =)    


     
return $this;
    
}
}

Regards!

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