A
A
alex88a2017-07-19 11:46:42
MySQL
alex88a, 2017-07-19 11:46:42

How to set a condition for some goods in modx?

There is such a code for promo codes

<?php
if($view == 1){
    $promo = '';
    if($_SESSION['promo']){
    $promo = $_SESSION['promo'];
}
if($_POST['promo']){
    $promo = $_POST['promo'];
}
return $promo;
 
}
 $_POST['discount'] = 0;
 
if($_SESSION['promo']){
    $promo = $_SESSION['promo'];
}
if($_POST['promo']){
    $_SESSION['promo'] = trim(mysql_real_escape_string($_POST['promo']));
    $promo = $_SESSION['promo'];
}

if ($modx->getObject('modResource',array('pagetitle' => $promo,'published' =>1))){
   $res = $modx->getObject('modResource',array('pagetitle' => $promo,'published' =>1));
    $price = str_replace(' ', '', $price);
    $startPrices = $price;
  if($res->getTVValue(27)){
      $d = $res->getTVValue(27);
      $price = $price - ($price * $d /100);
  }
  if($res->getTVValue(26)){
       $d = $res->getTVValue(26);
      $price = $price - $d;
  }
 $_SESSION['discount'] = $startPrices - $price; 
  return $price;
}else{
    return $price;
}

How to put an else if condition so that promotional codes do not work for discounted products? In discounted products, there is an additional field old_price. I tried to do this, if old_price is greater than 0, then return $price, but apparently I'm doing something wrong. Suggest a solution.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Egor Nikitin, 2019-02-01
@Habr_NED

Hello.
Grouping data (GROUP BY ) is not suitable?

P
Philip Gavrilov, 2017-08-27
@Filgavrilov

Use this plugin
https://modstore.pro/packages/discounts/mspromocode
There is an option "Apply only to products without old price"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question