Search code examples
phparrayssmartyprestashop

Send a product's custom feature in order confirmation email


I want to send the "units per box" custom feature in my confirmation mails in prestashop.

Here's an example if what I want to do

$myprod = new Product($product['id_product']);
$features = $myprod->getFrontFeatures(1));

foreach(from=$features item=feature)
{
  if ($feature.name == "Units per box")
  {
     $UnitsPerBox = $feature.value|escape:'htmlall':'UTF-8';
  }
}

However I need to do this within a php file (PaymentModule.php) rather than a tpl file, so that code won't work. If anybody could point me in the right direction of how to achieve this with php it'd be greatly appreciated.

EDIT:

I used the example code provided which seems to get inside the array but doesn't return any values

When I run some test code like this

$myprod = new Product($product['id_product']);
$features = $myprod->getFrontFeatures(1);
$UnitsPerBox .= '100';
foreach ($features as $feature) 
{
  $UnitsPerBox .= '200';
  if ($feature->name == 'Units Per Box') 
  {
    $UnitsPerBox .= htmlentities($feature->value, 'ENT_QUOTES', 'UTF-8');   
    $UnitsPerBox .= $feature->name;
  }
  else
  {
    $UnitsPerBox .= $feature->name;
    $UnitsPerBox .= htmlentities($feature->name, 'ENT_QUOTES', 'UTF-8');
    $UnitsPerBox .= htmlentities($feature->value, 'ENT_QUOTES', 'UTF-8');
  }
}

I get this output: "100200200200200200"

Any help would be great, thanks.

Thanks, Andrew

EDIT: Solution

Got it working in the end, thanks for the help

$myprod = new Product($product['id_product']);
$features = $myprod->getFrontFeatures(1);
foreach ($features as $feature) 
{
foreach ($feature as $key => $value) 
{
    if($value == "Units per box")
    {
        $UnitsPerBox = $feature['value'];
    }
}

}


Solution

  • $myprod = new Product($product['id_product']);
    $features = $myprod->getFrontFeatures(1);
    
    foreach ($features as $feature) {
       if ($feature->name == 'Units per box') {
          $UnitsPerBox = htmlentities($feature->value, 'ENT_QUOTES', 'UTF-8');
       }
    }