0

我对OXID相当陌生。

我正在尝试仅使用 OXID 函数来执行 SQL 查询。

关键是检查 oxVoucherSerie 的表 oxdiscount 中是否存在 $discount,如果存在,则从 oxVoucherSerie 中获取与该折扣相对应的氧化物。

可悲的是,我不能使用普通的 MySQL,我只能使用 oxid 函数。我不知道该怎么做。

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

这告诉我折扣是否存在。但是,我不知道从所说的折扣中恢复氧化物。

4

1 回答 1

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

于 2016-05-27T10:00:38.040 回答