本文整理汇总了PHP中CartRule::checkValidity方法的典型用法代码示例。如果您正苦于以下问题:PHP CartRule::checkValidity方法的具体用法?PHP CartRule::checkValidity怎么用?PHP CartRule::checkValidity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CartRule
的用法示例。
在下文中一共展示了CartRule::checkValidity方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: checkDiscountValidity
/**
* @deprecated 1.5.0
* @param CartRule $obj
* @return bool|string
*/
public function checkDiscountValidity($obj, $discounts, $order_total, $products, $check_cart_discount = false)
{
Tools::displayAsDeprecated();
$context = Context::getContext()->cloneContext();
$context->cart = $this;
return $obj->checkValidity($context);
}
示例2: ajaxProcessAddVoucher
public function ajaxProcessAddVoucher()
{
if ($this->tabAccess['edit'] === '1') {
$errors = array();
if (!($id_cart_rule = Tools::getValue('id_cart_rule')) || !($cart_rule = new CartRule((int) $id_cart_rule))) {
$errors[] = Tools::displayError('Invalid voucher.');
} elseif ($err = $cart_rule->checkValidity($this->context)) {
$errors[] = $err;
}
if (!count($errors)) {
if (!$this->context->cart->addCartRule((int) $cart_rule->id)) {
$errors[] = Tools::displayError('Can\'t add the voucher.');
}
}
echo Tools::jsonEncode(array_merge($this->ajaxReturnVars(), array('errors' => $errors)));
}
}
示例3: addProductsToCart
/**
* Add Products to cart
* @param Cart $cart Cart object
*/
private function addProductsToCart($cart, $codeCountry)
{
$products = $this->datas->orderLineItems;
$country = $this->getCountry($codeCountry);
$address = Address::initialize();
$address->id_country = $country->id;
if ($products && count($products)) {
foreach ($products as $p) {
if (PowaTagAPI::apiLog()) {
PowaTagLogs::initAPILog('Add product to cart', PowaTagLogs::IN_PROGRESS, 'Product : ' . $p->product->code);
}
$product = PowaTagProductHelper::getProductByCode($p->product->code, $this->context->language->id);
if (!Validate::isLoadedObject($product)) {
$this->addError(sprintf($this->module->l('This product does not exists : %s'), $p->product->code), PowaTagErrorType::$SKU_NOT_FOUND);
if (PowaTagAPI::apiLog()) {
PowaTagLogs::initAPILog('Add product to cart', PowaTagLogs::ERROR, 'Product : ' . $this->error['message']);
}
return false;
}
$variants = $p->product->productVariants;
$product_rate = 1 + $product->getTaxesRate($address) / 100;
foreach ($variants as $variant) {
$variantCurrency = $this->getCurrencyByIsoCode($variant->finalPrice->currency);
if (!PowaTagValidate::currencyEnable($variantCurrency)) {
$this->addError(sprintf($this->module->l('Currency not found : %s'), $variant->code), PowaTagErrorType::$CURRENCY_NOT_SUPPORTED);
if (PowaTagAPI::apiLog()) {
PowaTagLogs::initAPILog('Add product to cart', PowaTagLogs::ERROR, 'Product : ' . $this->error['message']);
}
return false;
}
$variantAmount = $variant->finalPrice->amount;
$id_product_attribute = false;
$combination = false;
if ($id_product_attribute = PowaTagProductAttributeHelper::getCombinationByCode($product->id, $variant->code)) {
$combination = new Combination($id_product_attribute);
$priceAttribute = $product->getPrice($this->display_taxes, $id_product_attribute);
$qtyInStock = PowaTagProductQuantityHelper::getProductQuantity($product, $id_product_attribute);
} else {
if ($product) {
$priceAttribute = $product->getPrice($this->display_taxes);
$qtyInStock = PowaTagProductQuantityHelper::getProductQuantity($product);
} else {
$this->addError(sprintf($this->module->l('This variant does not exist : %s'), $variant->code), PowaTagErrorType::$SKU_NOT_FOUND);
if (PowaTagAPI::apiLog()) {
PowaTagLogs::initAPILog('Add product to cart', PowaTagLogs::ERROR, 'Product : ' . $this->error['message']);
}
return false;
}
}
if ($qtyInStock == 0) {
$this->addError(sprintf($this->module->l('No Stock Available')), PowaTagErrorType::$SKU_OUT_OF_STOCK);
if (PowaTagAPI::apiLog()) {
PowaTagLogs::initAPILog('Add product to cart', PowaTagLogs::ERROR, 'Product : ' . $this->error['message']);
}
return false;
}
if ($qtyInStock < $p->quantity) {
$this->addError(sprintf($this->module->l('Quantity > Stock Count')), PowaTagErrorType::$INSUFFICIENT_STOCK);
if (PowaTagAPI::apiLog()) {
PowaTagLogs::initAPILog('Add product to cart', PowaTagLogs::ERROR, 'Product : ' . $this->error['message']);
}
return false;
}
if ($p->quantity < $product->minimal_quantity || $combination && $combination->minimal_quantity > $p->quantity) {
$this->addError(sprintf($this->module->l('Quantity < minimal quantity for product')), PowaTagErrorType::$OTHER_STOCK_ERROR);
if (PowaTagAPI::apiLog()) {
PowaTagLogs::initAPILog('Add product to cart', PowaTagLogs::ERROR, 'Product : ' . $this->error['message']);
}
return false;
}
$cart->updateQty($p->quantity, $product->id, $id_product_attribute);
if (PowaTagAPI::apiLog()) {
PowaTagLogs::initAPILog('Add product to cart', PowaTagLogs::SUCCESS, 'Cart ID : ' . $cart->id . ' - Product ID : ' . $product->id);
}
break;
}
}
} else {
$this->addError($this->module->l('No product found in request'), PowaTagErrorType::$SKU_NOT_FOUND);
return false;
}
// add vouchers
if (isset($this->datas->vouchers)) {
$this->context->cart = $cart;
$vouchers = $this->datas->vouchers;
if ($vouchers && count($vouchers)) {
foreach ($vouchers as $voucher) {
$ci = CartRule::getIdByCode($voucher);
if (!$ci) {
continue;
}
$cr = new CartRule($ci);
if (!$cr) {
continue;
}
if ($error = $cr->checkValidity($this->context, false, true)) {
//.........这里部分代码省略.........