0

I am fairly new to OXID.

I am trying to perform an SQL query by using OXID functions only.

The point is to check if $discount exists in oxVoucherSerie's table oxdiscount, and if it exists get the oxid from oxVoucherSerie that corresponds to that discount.

Sadly I cannot use plain MySQL and I am only allowed to use oxid functions. I have no idea how to do it.

    public function save_voucher($discount){
$o_voucherid         = oxNew("oxVoucherSerie");
$aWhere_discount['oxdiscount']    = $discount;
$sSql                       = $o_voucherid->buildSelectString($aWhere_discount);
$b_exists                   = $o_voucher->assignRecord($sSql);
}

This tells me if the discount exists. However, I have no idea to retrieve oxid from said discount.

prgrm
  • 3,734
  • 14
  • 40
  • 80

1 Answers1

2

we might need to clarify some wording and variables first, because i'm not really sure what you are trying to achieve.

voucher - (also called "coupon") shop visitor can enter voucher/coupon code in basket to achieve a price reduction or a free product.
Vouchers are generated in Shop Settings -> coupon series

discount - general price reduction for some categories or articles, e.g. 10% for pet accessories.
Discounts can be configured in Shop Settings -> Discounts


okay, i updated my post.

your code works well, i just changed it a little bit. First the code and then the explanation:

$o_voucher = oxNew("oxVoucherSerie");
$aWhere_discount['oxdiscount'] = 25;
$sSql = $o_voucher->buildSelectString($aWhere_discount);
$o_voucher->assignRecord($sSql);
var_dump($o_voucher);

I replaced $o_voucherid with $o_voucher (without id)
$o_voucher = oxNew("oxVoucherSerie"); gives you an oxVoucherSeries Object
$o_voucher->assignRecord($sSql); does not only tell you if voucher series with such discount exists, it also will load this voucher serie into $o_voucher , so you can access all the (not protedted) parameters of this voucher serie by using $o_voucher, e.g.:
$o_voucher->getId() or $o_voucher->oxvoucherseries__oxid->value() for getting its oxID or just var_dump($o_voucher); to see all the objects properties

By the way, if you are developing with OXID 4.9 you could use this module: https://marat.ws/direct-access-to-oxid-framework-functions/ for quick evaluating and debugging you code. just copy-paste the code from above into the textarea and hit the button

Marat
  • 617
  • 5
  • 12
  • Yes. It is a module that combines both. $discount is the amount to be discounted. A function adds the discount to the oxvoucherseries if this discount doesnt previously exist. Then a new function should check if a given voucher apply a discount. In order to see if this discount exists I need to retrieve the oxid of the oxvoucherseries and in order to get the correct oxid I have to compare it to the $discount. – prgrm May 27 '16 at 10:51