当前位置: 首页>>代码示例>>PHP>>正文


PHP Discount::getCategories方法代码示例

本文整理汇总了PHP中Discount::getCategories方法的典型用法代码示例。如果您正苦于以下问题:PHP Discount::getCategories方法的具体用法?PHP Discount::getCategories怎么用?PHP Discount::getCategories使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Discount的用法示例。


在下文中一共展示了Discount::getCategories方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getValue

 /**
  * Return discount value
  *
  * @param integer $nb_discounts Number of discount currently in cart
  * @param boolean $order_total_products Total cart products amount
  * @return mixed Return a float value or '!' if reduction is 'Shipping free'
  */
 public function getValue($nb_discounts = 0, $order_total_products = 0, $shipping_fees = 0, $idCart = false, $useTax = true)
 {
     $totalAmount = 0;
     $cart = new Cart((int) $idCart);
     if (!Validate::isLoadedObject($cart)) {
         return 0;
     }
     if (!$this->cumulable and (int) $nb_discounts > 1 or !$this->active or !$this->quantity and !$cart->OrderExists()) {
         return 0;
     }
     if ($this->usedByCustomer((int) $cart->id_customer) >= $this->quantity_per_user and !$cart->OrderExists()) {
         return 0;
     }
     $date_start = strtotime($this->date_from);
     $date_end = strtotime($this->date_to);
     if ((time() < $date_start or time() > $date_end) and !$cart->OrderExists()) {
         return 0;
     }
     $products = $cart->getProducts();
     $categories = Discount::getCategories((int) $this->id);
     foreach ($products as $product) {
         if (count($categories) and Product::idIsOnCategoryId($product['id_product'], $categories)) {
             $totalAmount += $this->include_tax ? $product['total_wt'] : $product['total'];
         }
     }
     if ($this->minimal > 0 and $totalAmount < $this->minimal) {
         return 0;
     }
     switch ($this->id_discount_type) {
         /* Relative value (% of the order total) */
         case 1:
             $amount = 0;
             $percentage = $this->value / 100;
             foreach ($products as $product) {
                 if (Product::idIsOnCategoryId($product['id_product'], $categories)) {
                     if ($this->cumulable_reduction or !$product['reduction_applies'] and !$product['on_sale']) {
                         $amount += ($useTax ? $product['total_wt'] : $product['total']) * $percentage;
                     }
                 }
             }
             return $amount;
             /* Absolute value */
         /* Absolute value */
         case 2:
             // An "absolute" voucher is available in one currency only
             $currency = (int) $cart->id_currency ? Currency::getCurrencyInstance($cart->id_currency) : Currency::getCurrent();
             if ($this->id_currency != $currency->id) {
                 return 0;
             }
             $taxDiscount = Cart::getTaxesAverageUsed((int) $cart->id);
             if (!$useTax and isset($taxDiscount) and $taxDiscount != 1) {
                 $this->value = abs($this->value / (1 + $taxDiscount * 0.01));
             }
             // Main return
             $value = 0;
             foreach ($products as $product) {
                 if (Product::idIsOnCategoryId($product['id_product'], $categories)) {
                     $value = $this->value;
                 }
             }
             // Return 0 if there are no applicable categories
             return $value;
             /* Free shipping (does not return a value but a special code) */
         /* Free shipping (does not return a value but a special code) */
         case 3:
             return '!';
     }
     return 0;
 }
开发者ID:greench,项目名称:prestashop,代码行数:76,代码来源:Discount.php

示例2: hasProductInCategory

 /**
  * @param Discount $discountObj
  * @return bool
  * @deprecated
  */
 public function hasProductInCategory($discountObj)
 {
     Tools::displayAsDeprecated();
     $products = $this->getProducts();
     $categories = Discount::getCategories($discountObj->id);
     foreach ($products as $product) {
         if (Product::idIsOnCategoryId($product['id_product'], $categories)) {
             return true;
         }
     }
     return false;
 }
开发者ID:srikanthash09,项目名称:codetestdatld,代码行数:17,代码来源:Cart.php

示例3: displayForm

    public function displayForm()
    {
        global $currentIndex, $cookie;
        $obj = $this->loadObject(true);
        $defaultLanguage = intval(Configuration::get('PS_LANG_DEFAULT'));
        $languages = Language::getLanguages();
        echo '
		<script type="text/javascript">
			id_language = Number(' . $defaultLanguage . ');
		</script>
		<form action="' . $currentIndex . '&submitAdd' . $this->table . '=1&token=' . $this->token . '" id="discount" name="discount" method="post" enctype="multipart/form-data">
		' . ($obj->id ? '<input type="hidden" name="id_' . $this->table . '" value="' . $obj->id . '" />' : '') . '
			<fieldset class="width3"><legend><img src="../img/admin/coupon.gif" />' . $this->l('Vouchers') . '</legend>
				<label>' . $this->l('Code:') . ' </label>
				<div class="margin-form">
					<input type="text" size="30" maxlength="32" name="name" value="' . htmlentities($this->getFieldValue($obj, 'name'), ENT_COMPAT, 'UTF-8') . '" style="text-transform: uppercase;" id="code" />
					<sup>*</sup>
					<img src="../img/admin/news-new.gif" onclick="gencode(8);" style="cursor: pointer" />
					<span class="hint" name="help_box">' . $this->l('Invalid characters: numbers and') . ' !<>,;?=+()@#"�{}_$%:<span class="hint-pointer">&nbsp;</span></span>
					<p style="clear: both;">' . $this->l('The voucher\'s code, at least 3 characters long, which the customer types in during check-out') . '</p>
				</div>
				<label>' . $this->l('Type:') . ' </label>
				<div class="margin-form">
					<select name="id_discount_type" id="id_discount_type" onchange="free_shipping()">';
        $discountTypes = Discount::getDiscountTypes(intval($cookie->id_lang));
        foreach ($discountTypes as $discountType) {
            echo '<option value="' . intval($discountType['id_discount_type']) . '"' . ($this->getFieldValue($obj, 'id_discount_type') == $discountType['id_discount_type'] ? ' selected="selected"' : '') . '>' . $discountType['name'] . '</option>';
        }
        echo '
					</select>
				</div>
				<label>' . $this->l('Categories:') . ' </label>
					<div class="margin-form">
							<table cellspacing="0" cellpadding="0" class="table" style="width: 29.5em;">
									<tr>
										<th><input type="checkbox" name="checkme" class="noborder" onclick="checkDelBoxes(this.form, \'categoryBox[]\', this.checked)" /></th>
										<th>' . $this->l('ID') . '</th>
										<th>' . $this->l('Name') . '</th>
									</tr>';
        $done = array();
        $index = array();
        $indexedCategories = isset($_POST['categoryBox']) ? $_POST['categoryBox'] : ($obj->id ? Discount::getCategories($obj->id) : array());
        $categories = Category::getCategories(intval($cookie->id_lang), false);
        foreach ($indexedCategories as $k => $row) {
            $index[] = $row['id_category'];
        }
        $this->recurseCategoryForInclude($index, $categories, $categories[0][1], 1, $obj->id);
        echo '
							</table>
							<p style="padding:0px; margin:0px 0px 10px 0px;">' . $this->l('Mark all checkbox(es) of categories to which the discount is to be applicated') . '<sup> *</sup></p>
						</div>
				<div class="clear" / >
				<label>' . $this->l('Description:') . ' </label>
				<div class="margin-form">';
        foreach ($languages as $language) {
            echo '
					<div id="description_' . $language['id_lang'] . '" style="display: ' . ($language['id_lang'] == $defaultLanguage ? 'block' : 'none') . '; float: left;">
						<input size="33" type="text" name="description_' . $language['id_lang'] . '" value="' . htmlentities($this->getFieldValue($obj, 'description', intval($language['id_lang'])), ENT_COMPAT, 'UTF-8') . '" /><sup> *</sup>
						<span class="hint" name="help_box">' . $this->l('Invalid characters:') . ' <>;=#{}<span class="hint-pointer">&nbsp;</span></span>
						<p style="clear: both;">' . $this->l('Will appear in cart next to voucher code') . '</p>
					</div>';
        }
        $this->displayFlags($languages, $defaultLanguage, 'description', 'description');
        echo '
				</div><br /><br /><br />
				<div class="clear" / >
				<label>' . $this->l('Value:') . ' </label>
				<div class="margin-form">
					<input type="text" size="15" name="value" id="discount_value" value="' . floatval($this->getFieldValue($obj, 'value')) . '" onKeyUp="javascript:this.value = this.value.replace(/,/g, \'.\'); " /> <sup>*</sup>
					<p style="clear: both;">' . $this->l('Either the monetary amount or the %, depending on Type selected above') . '</p>
				</div>
				<label>' . $this->l('Total quantity:') . ' </label>
				<div class="margin-form">
					<input type="text" size="15" name="quantity" value="' . intval($this->getFieldValue($obj, 'quantity')) . '" /> <sup>*</sup>
					<p style="clear: both;">' . $this->l('Total quantity available (mainly for vouchers open to everyone)') . '</p>
				</div>
				<label>' . $this->l('Qty per each user:') . ' </label>
				<div class="margin-form">
					<input type="text" size="15" name="quantity_per_user" value="' . intval($this->getFieldValue($obj, 'quantity_per_user')) . '" /> <sup>*</sup>
					<p style="clear: both;">' . $this->l('Number of times a single customer can use this voucher') . '</p>
				</div>
				<label>' . $this->l('Minimum amount') . '</label>
				<div class="margin-form">
					<input type="text" size="15" name="minimal" value="' . ($this->getFieldValue($obj, 'minimal') ? floatval($this->getFieldValue($obj, 'minimal')) : '0') . '" onkeyup="javascript:this.value = this.value.replace(/,/g, \'.\'); " /> <sup>*</sup>
					<p style="clear: both;">' . $this->l('Leave blank or 0 if not applicable') . '</p>
				</div>
				<div class="margin-form">
					<p>
						<input type="checkbox" name="cumulable"' . ($this->getFieldValue($obj, 'cumulable') == 1 ? ' checked="checked"' : '') . ' id="cumulable_on" value="1" />
						<label class="t" for="cumulable_on"> ' . $this->l('Cumulative with other vouchers') . '</label>
					</p>
				</div>
				<div class="margin-form">
					<p>
						<input type="checkbox" name="cumulable_reduction"' . ($this->getFieldValue($obj, 'cumulable_reduction') == 1 ? ' checked="checked"' : '') . ' id="cumulable_reduction_on" value="1" />
						<label class="t" for="cumulable_reduction_on"> ' . $this->l('Cumulative with price reductions') . '</label>
					</p>
				</div>
				<label>' . $this->l('To be used by:') . ' </label>
								<div class="margin-form">				
//.........这里部分代码省略.........
开发者ID:Bruno-2M,项目名称:prestashop,代码行数:101,代码来源:AdminDiscounts.php

示例4: displayForm


//.........这里部分代码省略.........
				<div id="behavior_not_exhausted" style="display:none;">
					<label>' . $this->l('Behavior:') . '</label>
					<div class="margin-form">
						<select name="behavior_not_exhausted">
							<option value="1" ' . ($obj->behavior_not_exhausted === 1 ? 'selected="selected"' : '') . '>' . $this->l('Reduces the voucher value to correspond to the order amount') . '</option>
							<option value="2" ' . ($obj->behavior_not_exhausted == 2 ? 'selected="selected"' : '') . '>' . $this->l('Create a new voucher with the remaining amount') . '</option>
							<option value="3" ' . ($obj->behavior_not_exhausted == 3 ? 'selected="selected"' : '') . '>' . $this->l('Create negative invoice') . '</option>
						</select>
					</div>
				</div>
				</div>
				<label>' . $this->l('Description:') . ' </label>
				<div class="margin-form">';
        foreach ($this->_languages as $language) {
            echo '	<div id="description_' . $language['id_lang'] . '" style="display: ' . ($language['id_lang'] == $this->_defaultFormLanguage ? 'block' : 'none') . '; float: left;">
						<input size="33" type="text" name="description_' . $language['id_lang'] . '" value="' . htmlentities($this->getFieldValue($obj, 'description', (int) $language['id_lang']), ENT_COMPAT, 'UTF-8') . '" /><sup> *</sup>
						<span class="hint" name="help_box">' . $this->l('Invalid characters:') . ' <>;=#{}<span class="hint-pointer">&nbsp;</span></span>
						<p class="clear">' . $this->l('Will appear in cart next to voucher code') . '</p>
					</div>';
        }
        $this->displayFlags($this->_languages, $this->_defaultFormLanguage, 'description', 'description');
        echo '	</div>
				<div class="clear" / >
				<label>' . $this->l('Categories:') . ' </label>
					<div class="margin-form">
							<table cellspacing="0" cellpadding="0" class="table" style="width: 600px;">
									<tr>
										<th><input type="checkbox" name="checkme" class="noborder" onclick="checkDelBoxes(this.form, \'categoryBox[]\', this.checked)" /></th>
										<th>' . $this->l('ID') . '</th>
										<th>' . $this->l('Name') . '</th>
									</tr>';
        $done = array();
        $index = array();
        $indexedCategories = isset($_POST['categoryBox']) ? $_POST['categoryBox'] : ($obj->id ? Discount::getCategories($obj->id) : array());
        $categories = Category::getCategories((int) $cookie->id_lang, false);
        foreach ($indexedCategories as $k => $row) {
            $index[] = isset($row['id_category']) ? (int) $row['id_category'] : (int) $row;
        }
        $this->recurseCategoryForInclude((int) Tools::getValue($this->identifier), $index, $categories, $categories[0][1], 1, $obj->id);
        echo '
							</table>
							<p style="padding:0px; margin:0px 0px 10px 0px;">' . $this->l('Check all box(es) of categories to which the discount is to be applied') . '<sup> *</sup></p>
						</div>
				<div class="clear" / >
				<label>' . $this->l('Total quantity:') . ' </label>
				<div class="margin-form">
					<input type="text" size="15" name="quantity" value="' . (int) $this->getFieldValue($obj, 'quantity') . '" /> <sup>*</sup>
					<p class="clear">' . $this->l('Total quantity available (mainly for vouchers open to everyone)') . '</p>
				</div>
				<label>' . $this->l('Qty per each user:') . ' </label>
				<div class="margin-form">
					<input type="text" size="15" name="quantity_per_user" value="' . (int) $this->getFieldValue($obj, 'quantity_per_user') . '" /> <sup>*</sup>
					<p class="clear">' . $this->l('Number of times a single customer can use this voucher') . '</p>
				</div>
				<label>' . $this->l('Minimum purchase') . '</label>
				<div class="margin-form">
					<input type="text" size="15" name="minimal" value="' . ($this->getFieldValue($obj, 'minimal') ? (double) $this->getFieldValue($obj, 'minimal') : '0') . '" onkeyup="javascript:this.value = this.value.replace(/,/g, \'.\'); " /> <sup>*</sup>&nbsp;
					<select name="include_tax" id="include_tax" style="vertical-align: middle;">
						<option value="0" ' . ($obj->include_tax == 0 ? 'selected="selected"' : '') . '>' . $this->l('tax excl.') . '</option>
						<option value="1" ' . ($obj->include_tax == 1 ? 'selected="selected"' : '') . '>' . $this->l('tax incl.') . '</option>
					</select>
					<p class="clear">' . $this->l('0 if not applicable') . '</p>
				</div>
				<div class="margin-form">
					<p>
						<input type="checkbox" name="cumulable"' . ($this->getFieldValue($obj, 'cumulable') == 1 ? ' checked="checked"' : '') . ' id="cumulable_on" value="1" />
开发者ID:Evil1991,项目名称:PrestaShop-1.4,代码行数:67,代码来源:AdminDiscounts.php

示例5: getValue

 /**
  * Return discount value
  *
  * @param integer $nb_discounts Number of discount currently in cart
  * @param boolean $order_total_products Total cart products amount
  * @return mixed Return a float value or '!' if reduction is 'Shipping free'
  */
 function getValue($nb_discounts = 0, $order_total_products = 0, $shipping_fees = 0, $idCart = false, $useTax = true)
 {
     $totalAmount = 0;
     if (!$this->cumulable and intval($nb_discounts) > 1) {
         return 0;
     }
     if (!$this->active) {
         return 0;
     }
     if (!$this->quantity) {
         return 0;
     }
     $date_start = strtotime($this->date_from);
     $date_end = strtotime($this->date_to);
     if (time() < $date_start or time() > $date_end) {
         return 0;
     }
     $cart = new Cart(intval($idCart));
     $products = $cart->getProducts();
     $categories = Discount::getCategories(intval($this->id));
     $in_category = false;
     foreach ($products as $product) {
         if (count($categories)) {
             if (Product::idIsOnCategoryId($product['id_product'], $categories)) {
                 $totalAmount += $useTax ? $product['total_wt'] : $product['total'];
             }
         }
     }
     $totalAmount += floatval($shipping_fees);
     if ($this->minimal > 0 and $totalAmount < $this->minimal) {
         return 0;
     }
     switch ($this->id_discount_type) {
         case 1:
             // % on order
             $amount = 0;
             $percentage = $this->value / 100;
             foreach ($products as $product) {
                 if (Product::idIsOnCategoryId($product['id_product'], $categories)) {
                     $amount += ($useTax ? $product['total_wt'] : $product['total']) * $percentage;
                 }
             }
             return $amount;
         case 2:
             // amount
             foreach ($products as $product) {
                 if (Product::idIsOnCategoryId($product['id_product'], $categories)) {
                     $in_category = true;
                     break;
                 }
             }
             return $in_category ? $this->value : 0;
         case 3:
             // Shipping is free
             return '!';
     }
     return 0;
 }
开发者ID:sealence,项目名称:local,代码行数:65,代码来源:Discount.php


注:本文中的Discount::getCategories方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。