Question

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'];
    }
}

}

Was it helpful?

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');
   }
}

OTHER TIPS

This looks like Smarty template code. In that case, the function you're looking for is htmlentities():

foreach($features as $feature)
{
  if ($feature->name == "Units per box")
  {
     $UnitsPerBox = htmlentities($feature->value, ENT_QUOTES, 'UTF-8');
  }
}

I have modified my file

classes/PaymentModule.php 

I can print short and Long Description of the product, but I'm just not being able to put the features of the product on the order confirmation mail template, I came up with a solution using this page and also this https://www.prestashop.com/forums/topic/658353-15-add-products-features-in-order-confirmation-email/, using this last solution I was just able to print the ID of the order confirmation.

I added the following around line 353

$lesfeatures = Product::getFrontFeaturesStatic((int)$id_lang,      `$product['id_product']);`

foreach ($lesfeatures as $key => $lafeature) {                        
    $machin .= print_r($lafeature);
    $machin .= $lafeature['id_feature'].'name:'.$lafeature['name'].'value:'.$lafeature['value'].'<br>';}

and then the following around line 400

<strong>'.$product['name'].(isset($product['attributes']) ? ' - '.$product['attributes'] : '').'</strong>'.$machin.'

That's when I just get the Order ID

This is my current working code around line 400 for printing descriptions

<strong>
Cantidad de Piezas: '.$product['quantity'].'
<br/>
'.$product['name'].(isset($product['attributes']) ? ' - '.$product['attributes'] : '').'
<br/>Descripci贸n: '.$product['description_short'].'
</strong>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top