0

This has to do with coming up with php for the google trusted store badge - specifically setting the estimated delivery date.

I have this code on my success page that prints the data:

<?php
$order_items = $order->getAllItems();

foreach($order_items as $item) {
    $product = Mage::getModel('catalog/product')->load($item->getProductId());

    echo $product->getAttributeText('estdelivery'); //changed getAttributeText to getData
    echo '|';
}


 ?>

if there is more than one item in the order it will print the attribute data - in this case 6 and 7

as one item has 6 days set in the attribute the other item has 7 days set in the attribute

I need a way in php to only print the higher number i.e. 7

the code i am currently using in the badge is

<span id="gts-o-est-delivery-date"><?php echo $deliveryDate=Date('Y-m-d', strtotime("+7 days")); ?></span>

But I need it to find all the delivery date attributes of all the items and enter the larger number into that code for delivery date

updated so I am using this and it successfully returns the higher of the variables

<?php
$order_items = $order->getAllItems();

foreach($order_items as $item) {
    $product = Mage::getModel('catalog/product')->load($item->getProductId());



}

$a=array($product->getAttributeText('estdelivery'));
$c=0;
foreach($a as $b)
{
if($b>$c)
$c=$b;

}
echo $c;

 ?>

So how do i got from that to the code I am using for estimated delivery date?? will this work below?

<span id="gts-o-est-delivery-date"><?php echo $deliveryDate=Date('Y-m-d', strtotime("$order_items = $order->getAllItems();

foreach($order_items as $item) {
    $product = Mage::getModel('catalog/product')->load($item->getProductId());



}

$a=array($product->getAttributeText('estdelivery'));
$c=0;
foreach($a as $b)
{
if($b>$c)
$c=$b;

}
echo $c;
 days")); ?></span>
0

If I'm understanding the issue correctly, it seems like this should fix it:

<?php 
    $order_items = $order->getAllItems();
    $maxDelivery = 0;
    foreach($order_items as $item) {
        $product = Mage::getModel('catalog/product')->load($item->getProductId());

        if ($product->getAttributeText('estdelivery') > $maxDelivery) { 
            $maxDelivery = $product->getAttributeText('estdelivery');
        }

    }
    echo $maxDelivery;
?>

Loop through the products and keep track of the largest estdelivery value seen, and print that.

  • thanks for the input I actually edited my question and have it printinng the higher value but will use your method instead looks m,ore up to date :) – user3677211 May 27 '16 at 20:19
  • so my question now is how do i translate that into <span id="gts-o-est-delivery-date"><?php echo $deliveryDate=Date('Y-m-d', strtotime("+7 days")); ?></span> – user3677211 May 27 '16 at 20:20
  • "+($order_items = $order->getAllItems(); $maxDelivery = 0; foreach($order_items as $item) { $product = Mage::getModel('catalog/product')->load($item->getProductId()); if ($product->getAttributeText('estdelivery') > $maxDelivery) { $maxDelivery = $product->getAttributeText('estdelivery'); } } echo $maxDelivery;) days" – user3677211 May 27 '16 at 20:21
  • <span id="gts-o-est-delivery-date"><?php echo $deliveryDate=Date('Y-m-d', strtotime("+7 days")); ?></span> change ("+7 days") to ("?????????") so close but still not figuring it out – user3677211 May 27 '16 at 20:30
  • He won't use your code now haha – Mike Tim Turner May 27 '16 at 22:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.