本文整理汇总了PHP中CCatalogProduct类的典型用法代码示例。如果您正苦于以下问题:PHP CCatalogProduct类的具体用法?PHP CCatalogProduct怎么用?PHP CCatalogProduct使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CCatalogProduct类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: On1CExchAfterIBlockElementAdd
function On1CExchAfterIBlockElementAdd(&$arFields)
{
// Create catalog records for all iblock elements
$iblockElementId = intval($arFields['RESULT']);
if ($iblockElementId > 0) {
$catalogProduct = new CCatalogProduct();
$catalogProduct->Add(array('ID' => $iblockElementId, 'QUANTITY' => 0));
}
return true;
}
示例2: addCatalogProducts
protected function addCatalogProducts($arParams){
if (!CModule::IncludeModule("iblock") && !CModule::IncludeModule("catalog") && !CModule::IncludeModule("sale")):
return false;
endif;
$arFields = array(
"ID" => $arParams["PRODUCT_ID"],
"QUANTITY" => $arParams["BALANCE"],
"CAN_BUY_ZERO" => "Y",
"NEGATIVE_AMOUNT_TRACE" => "Y",
"QUANTITY_TRACE" => "Y"
);
$db_res = CCatalogProduct::GetList(
array(),
array("ID" => $arParams["PRODUCT_ID"]),
false,
array()
);
if ($ar_res = $db_res->Fetch()):
if (!CCatalogProduct::Update($ar_res["ID"], $arFields)):
return false;
endif;
else:
if(!CCatalogProduct::Add($arFields)):
return false;
endif;
endif;
return true;
}
示例3: AddToBasket
function AddToBasket($pid, $quantity)
{
if (CModule::IncludeModule("sale") && CModule::IncludeModule("catalog")) {
$ar_res = CCatalogProduct::GetByIDEx($pid);
if ($ar_res) {
$result = Add2BasketByProductID($pid, $quantity);
// если ошибки - $ex = $APPLICATION->GetException();
if ($result) {
$arrSendResult['ERROR'] = 'N';
$arrSendResult['TEXT'] = 'OK';
echo json_encode($arrSendResult);
} else {
$arrSendResult['ERROR'] = 'Y';
$arrSendResult['TEXT'] = 'Error';
echo json_encode($arrSendResult);
}
} else {
if (Add2BasketByProductID($pid, $quantity)) {
$arrSendResult['ERROR'] = 'N';
$arrSendResult['TEXT'] = 'OK';
echo json_encode($arrSendResult);
}
}
}
}
示例4: OnProductCatalogHandler
function OnProductCatalogHandler($ID, $arFields)
{
Bitrix\Main\Loader::includeModule('iblock');
Bitrix\Main\Loader::includeModule('catalog');
define('IBLOCK_ID_PRODUCTS', 2);
define('IBLOCK_ID_OFFERS', 3);
$query = new \Bitrix\Main\Entity\Query(Bitrix\Iblock\ElementTable::getEntity());
$query->setSelect(array("ID", "IBLOCK_ID"))->setFilter(array("ID" => $ID))->setOrder(array("ID" => "ASC"));
$resElement = $query->exec()->fetch();
if ($resElement['IBLOCK_ID'] == IBLOCK_ID_PRODUCTS) {
CIBlockElement::SetPropertyValuesEx($ID, $resElement['IBLOCK_ID'], array("AVAILABLE_QUANTITY_CATALOG" => $arFields['QUANTITY']));
} elseif ($resElement['IBLOCK_ID'] == IBLOCK_ID_OFFERS) {
//1
$rsElementOffer = CIBlockElement::GetList(array(), array("ID" => $ID), false, false, array("ID", "IBLOCK_ID", 'NAME', "PROPERTY_CML2_LINK"))->fetch();
$resElemOfferProduct = (int) $rsElementOffer['PROPERTY_CML2_LINK_VALUE'];
//2
$resOffersCML2 = CIBlockElement::GetList(array(), array("PROPERTY_CML2_LINK" => $resElemOfferProduct, 'IBLOCK_ID' => IBLOCK_ID_OFFERS), false, false, array("ID", "IBLOCK_ID", 'NAME'));
//3
$arrOffersIDs = array();
while ($res = $resOffersCML2->fetch()) {
$arrOffersIDs[] = $res['ID'];
}
//4
$availQuant = array();
foreach ($arrOffersIDs as $k => $v) {
$ar_res_cat = CCatalogProduct::GetList(array("ID" => "DESC"), array("ID" => (int) $v), false, false, array("ID", "QUANTITY", 'ELEMENT_IBLOCK_ID', 'ELEMENT_NAME'))->fetch();
$availQuant[] = $ar_res_cat['QUANTITY'];
}
//5
$minAvailQuant = (int) min($availQuant);
//6
$resUpdateSCU = CIBlockElement::SetPropertyValuesEx($resElemOfferProduct, IBLOCK_ID_PRODUCTS, array("AVAILABLE_QUANTITY_CATALOG" => $minAvailQuant));
}
}
示例5: getPriceObj
protected function getPriceObj()
{
if ($this->price === null) {
$this->price = \CCatalogProduct::GetOptimalPrice($this->ID);
// echo '<pre>'.print_r($this->price,true).'</pre>';
}
return $this->price;
}
示例6: getProductMeasures
public static function getProductMeasures($productID)
{
if (!Main\Loader::includeModule('catalog')) {
throw new Main\SystemException("Could not load 'catalog' module.");
}
$productIDs = is_array($productID) ? $productID : array($productID);
$measure2product = array();
if (!empty($productIDs)) {
$productEntity = new \CCatalogProduct();
$dbProductResult = $productEntity->GetList(array(), array('@ID' => $productIDs), false, false, array('ID', 'MEASURE'));
if (is_object($dbProductResult)) {
while ($productFields = $dbProductResult->Fetch()) {
$measureID = isset($productFields['MEASURE']) ? intval($productFields['MEASURE']) : 0;
if ($measureID <= 0) {
continue;
}
if (isset($measure2product[$measureID])) {
$measure2product[$measureID] = array();
}
$measure2product[$measureID][] = intval($productFields['ID']);
}
}
}
$result = array();
if (!empty($measure2product)) {
$dbMeasureResult = \CCatalogMeasure::getList(array(), array('@ID' => array_keys($measure2product)), false, false, array('ID', 'CODE', 'SYMBOL_RUS', 'SYMBOL_INTL', 'IS_DEFAULT'));
if (is_object($dbMeasureResult)) {
while ($measureFields = $dbMeasureResult->Fetch()) {
$measureID = intval($measureFields['ID']);
$measureInfo = array('ID' => $measureID, 'CODE' => intval($measureFields['CODE']), 'IS_DEFAULT' => isset($measureFields['IS_DEFAULT']) && $measureFields['IS_DEFAULT'] === 'Y', 'SYMBOL' => isset($measureFields['SYMBOL_RUS']) ? $measureFields['SYMBOL_RUS'] : $measureFields['SYMBOL_INTL']);
foreach ($measure2product[$measureID] as $productID) {
$result[$productID] = array($measureInfo);
}
}
}
}
return $result;
}
示例7: loadFromDatabase
protected function loadFromDatabase()
{
if (!isset($this->fields)) {
$this->fields = \CCatalogProduct::getByID($this->id);
if (is_array($this->fields)) {
if ($this->fields["MEASURE"] > 0) {
$this->fields["MEASURE"] = new ElementCatalogMeasure($this->fields["MEASURE"]);
}
$this->fields["STORE"] = new ElementCatalogStoreList(0);
} else {
$this->fields["STORE"] = new ElementCatalogStoreList(0);
}
}
return is_array($this->fields);
}
示例8: getProductList
/**
* @param Basket $basketCollection
* @param array $productList
* @return array
*/
public static function getProductList(Basket $basketCollection, array $productList = array())
{
$productBasketIndex = array();
$result = array();
foreach ($basketCollection as $basketKey => $basketItem) {
$productId = intval($basketItem->getProductId());
if (intval($productId < 0) || sizeof($productList) > 0 && in_array($productId, $productList)) {
continue;
}
$productBasketIndex[$basketKey] = $productId;
}
$rsProducts = \CCatalogProduct::GetList(array(), array('ID' => $productBasketIndex), false, false, array('ID', 'CAN_BUY_ZERO', 'NEGATIVE_AMOUNT_TRACE', 'QUANTITY_TRACE', 'QUANTITY', 'QUANTITY_RESERVED'));
while ($arProduct = $rsProducts->Fetch()) {
$result[$arProduct['ID']] = $arProduct;
}
return $result;
}
示例9: add_element
function add_element($iblock_id, $section_id, $NAME, $PRICE_EUR, $P, $DETAIL_PICTURE)
{
$el = new CIBlockElement();
//test_dump($P);
$arFields = array("IBLOCK_ID" => $iblock_id, "NAME" => $NAME, "CODE" => $P["ARTNUMBER"], "ACTIVE" => "Y", "IBLOCK_SECTION_ID" => $section_id, "DETAIL_TEXT" => $P["DESCRIPTION_TEXT"], "DETAIL_TEXT_TYPE" => "html", "PROPERTY_VALUES" => $P, "DETAIL_PICTURE" => $DETAIL_PICTURE);
if ($last_el_id = $el->Add($arFields)) {
echo "New ID: " . $last_el_id . "<br>";
$arFields = array("ID" => $last_el_id, "VAT_INCLUDED" => "Y");
if (CCatalogProduct::Add($arFields)) {
echo "Добавили параметры товара к элементу каталога " . $last_el_id . "<br>";
$arFields = array("PRODUCT_ID" => $last_el_id, "CATALOG_GROUP_ID" => 1, "PRICE" => $PRICE_EUR, "CURRENCY" => "EUR");
CPrice::Add($arFields);
} else {
echo "Ошибка добавления параметров товаров";
}
} else {
echo "Error: " . $el->LAST_ERROR . "<br>";
}
}
示例10: CheckFields
/**
* <p>Метод служит для проверки параметров, переданных в методы <a href="http://dev.1c-bitrix.ru/api_help/catalog/classes/ccatalogproductgroups/ccatalogproductgroups.add.php">CCatalogProductGroups::Add</a> и <a href="http://dev.1c-bitrix.ru/api_help/catalog/classes/ccatalogproductgroups/ccatalogproductgroups.update.php">CCatalogProductGroups::Update</a>.</p>
*
*
*
*
* @param string $ACTION Указывает, для какого метода идет проверка. Возможные значения:
* <br><ul> <li> <b>ADD</b> - для метода <a
* href="http://dev.1c-bitrix.ru/api_help/catalog/classes/ccatalogproductgroups/ccatalogproductgroups.add.php">CCatalogProductGroups::Add</a>;</li>
* <li> <b>UPDATE</b> - для метода <a
* href="http://dev.1c-bitrix.ru/api_help/catalog/classes/ccatalogproductgroups/ccatalogproductgroups.update.php">CCatalogProductGroups::Update</a>.</li>
* </ul>
*
*
*
* @param array &$arFields Ассоциативный массив параметров информации о связи товаров и
* групп пользователей. Допустимые ключи: <ul> <li> <b>PRODUCT_ID</b> - код
* товара;</li> <li> <b>GROUP_ID</b> - код группы пользователей;</li> <li> <b>ACCESS_LENGTH</b>
* - длина периода, на который пользователь привязывается к группе
* пользователей при покупке товара (0 - навсегда);</li> <li>
* <b>ACCESS_LENGTH_TYPE</b> - тип периода, на который пользователь
* привязывается к группе пользователей при покупке товара ("H" - час,
* "D" - сутки, "W" - неделя, "M" - месяц, "Q" - квартал, "S" - полугодие, "Y" -
* год).</li> </ul>
*
*
*
* @param int $ID = 0 Код записи с информацией о связи товаров и групп пользователей, к
* которым пользователь привязывается при покупке товаров.
* Параметр является необязательным и имеет смысл только для $ACTION =
* 'UPDATE'.
*
*
*
* @return bool <p> В случае корректности переданных параметров возвращает true,
* иначе - false. Если функция вернула false, с помощью $APPLICATION->GetException()
* можно получить текст ошибок.</p>
*
*
* <h4>See Also</h4>
* <ul> <li><a href="http://dev.1c-bitrix.ru/api_help/catalog/fields.php">Структура таблицы</a></li> <li><a
* href="http://dev.1c-bitrix.ru/api_help/catalog/classes/ccatalogproductgroups/ccatalogproductgroups.add.php">CCatalogProductGroups::Add</a></li>
* <li><a
* href="http://dev.1c-bitrix.ru/api_help/catalog/classes/ccatalogproductgroups/ccatalogproductgroups.update.php">CCatalogProductGroups::Update</a></li>
* </ul> </ht<br><br>
*
*
* @static
* @link http://dev.1c-bitrix.ru/api_help/catalog/classes/ccatalogproductgroups/checkfields.php
* @author Bitrix
*/
public static function CheckFields($ACTION, &$arFields, $ID = 0)
{
if ((is_set($arFields, "PRODUCT_ID") || $ACTION == "ADD") && intval($arFields["PRODUCT_ID"]) <= 0) {
return false;
}
if ((is_set($arFields, "GROUP_ID") || $ACTION == "ADD") && intval($arFields["GROUP_ID"]) <= 0) {
return false;
}
if (is_set($arFields, "ACCESS_LENGTH") || $ACTION == "ADD") {
$arFields["ACCESS_LENGTH"] = intval($arFields["ACCESS_LENGTH"]);
if ($arFields["ACCESS_LENGTH"] < 0) {
$arFields["ACCESS_LENGTH"] = 0;
}
}
if ((is_set($arFields, "ACCESS_LENGTH_TYPE") || $ACTION == "ADD") && !array_key_exists($arFields["ACCESS_LENGTH_TYPE"], CCatalogProduct::GetTimePeriodTypes(true))) {
$arFields["ACCESS_LENGTH_TYPE"] = CCatalogProduct::TIME_PERIOD_DAY;
}
return true;
}
示例11: editContent
public function editContent(&$content)
{
$replaced_template = "<!--Mneniya.pro-->";
if (strpos($content, $replaced_template) !== false) {
if (CModule::IncludeModule("catalog")) {
$product_id = 0;
if (isset($_SESSION['VIEWED_PRODUCT']) && $_SESSION['VIEWED_PRODUCT']) {
$product_id = $_SESSION['VIEWED_PRODUCT'];
} else {
$product_id = $_SESSION['LAST_VIEW_ID'];
}
$product_info = CCatalogProduct::GetByIDEx($product_id);
$settings = unserialize(COption::GetOptionString("pimentos.mneniyapro", "settings"));
if (isset($settings["code"]) && $settings["code"]) {
$content = str_replace($replaced_template, '<div class="mp-prod_id" style="display:none">' . $product_id . '</div>' . '<div class="mp-prod_name" style="display:none">' . $product_info['NAME'] . '</div>' . $settings["code"], $content);
}
}
}
}
示例12: updateAll
public static function updateAll($page = 0, &$total, $perPage = CAutoPriceUpdater::LIMIT)
{
$list = CCatalogProduct::GetList(array(), array('IBLOCK_ID' => self::enabledCatalogs()), false, array('iNumPage' => $page + 1, 'nPageSize' => $perPage), array('ID'));
$total = $list->NavPageCount;
if ($page + 1 > $list->NavPageCount) {
return false;
}
$priceType = COption::GetOptionInt('autoprice', 'priceTypes', 0);
while ($res = $list->Fetch()) {
$price = CPrice::GetBasePrice($res['ID'], false, false);
$priseRub = floatval($price * self::$usdRate);
if ($priseRub < 1000 && self::$extras[0]) {
self::setExtra($res['ID'], $priceType, self::$extras[0]);
} elseif ($priseRub < 10000 && self::$extras[1]) {
self::setExtra($res['ID'], $priceType, self::$extras[1]);
} elseif ($priseRub < 100000 && self::$extras[2]) {
self::setExtra($res['ID'], $priceType, self::$extras[2]);
}
}
return $page + 1 < $total;
}
示例13: get_ib_items_list
private static function get_ib_items_list($arFilter, $arSelectFields, $with_prices = false)
{
if (!CModule::IncludeModule("iblock")) {
return false;
}
$arItems = array();
$res = CIBlockElement::GetList(array("SORT" => "ASC", "NAME" => "ASC"), $arFilter, false, false, $arSelectFields);
while ($item = $res->GetNext()) {
if ($with_prices) {
$item["PRICE"] = CCatalogProduct::GetOptimalPrice($item["ID"], self::DEFAULT_PRICE_ID, isset($GLOBALS['USER']) && $GLOBALS['USER'] ? $GLOBALS['USER']->GetUserGroupArray() : 0);
if (isset($item["PRICE"]["RESULT_PRICE"]) && $item["PRICE"]["RESULT_PRICE"]) {
$item["PRICE_VALUE"] = $item["PRICE"]["RESULT_PRICE"]["BASE_PRICE"];
$item["PRICE_STR_VALUE"] = CurrencyFormat($item["PRICE"]["RESULT_PRICE"]["BASE_PRICE"], $item["PRICE"]["RESULT_PRICE"]["CURRENCY"]);
} else {
$item["PRICE_VALUE"] = 0;
$item["PRICE_STR_VALUE"] = "";
}
}
$arItems[$item["ID"]] = $item;
}
return $arItems;
}
示例14: addToBascket
function addToBascket($arItems){
$num = 0;
foreach($arItems as $item){
$tovar=CCatalogProduct::GetByIDEx($item["ID"]);
if(intval($item["COUNT"])<=$tovar["PRODUCT"]["QUANTITY"]&&intval($item["COUNT"])>0){
Add2BasketByProductID($item["ID"],intval($item["COUNT"]));
$num++;
}
}
?>
<script>
$(".CartLink span").text('(<?php
echo $num;
?>
)');
$('body,html').animate({scrollTop: 0}, 2);
</script>
<?
}
示例15: getAvailableQuantity
function getAvailableQuantity($arBasketItems)
{
if (empty($arBasketItems) || !is_array($arBasketItems)) {
return array();
}
if ($catalogIncluded === null) {
$catalogIncluded = Loader::includeModule('catalog');
}
if (!$catalogIncluded) {
return false;
}
$arElementId = array();
$productMap = array();
foreach ($arBasketItems as $key => $arItem) {
$arElementId[$arItem['PRODUCT_ID']] = $arItem['PRODUCT_ID'];
if (!isset($productMap[$arItem['PRODUCT_ID']])) {
$productMap[$arItem['PRODUCT_ID']] = array();
}
$productMap[$arItem['PRODUCT_ID']][] = $key;
}
unset($key, $arItem);
if (!empty($arElementId)) {
$productIterator = CCatalogProduct::GetList(array(), array('ID' => $arElementId), false, false, array('ID', 'QUANTITY'));
while ($product = $productIterator->Fetch()) {
if (!isset($productMap[$product['ID']])) {
continue;
}
foreach ($productMap[$product['ID']] as $key) {
$arBasketItems[$key]['AVAILABLE_QUANTITY'] = $product['QUANTITY'];
}
unset($key);
}
unset($product, $productIterator);
}
unset($productMap, $arElementId);
return $arBasketItems;
}