Ejemplo n.º 1
0
 public static function Update($ID, $arFields)
 {
     if (!CModule::IncludeModule('catalog')) {
         return false;
     }
     global $DB;
     if (!self::CheckFields('UPDATE', $arFields, $ID)) {
         return false;
     }
     if (isset($arFields['NAME']) || isset($arFields['SECTION_ID']) || isset($arFields['SORT']) || isset($arFields['ACTIVE']) || isset($arFields['DETAIL_PICTURE']) || isset($arFields['DESCRIPTION']) || isset($arFields['DESCRIPTION_TYPE']) || isset($arFields['PREVIEW_PICTURE']) || isset($arFields['PREVIEW_TEXT']) || isset($arFields['PREVIEW_TEXT_TYPE']) || isset($arFields['ORIGINATOR_ID']) || isset($arFields['ORIGIN_ID']) || isset($arFields['XML_ID']) || isset($arFields['PROPERTY_VALUES'])) {
         $element = new CIBlockElement();
         $obResult = $element->GetById($ID);
         if ($arElement = $obResult->Fetch()) {
             // files
             $arElement['PREVIEW_PICTURE'] = CFile::MakeFileArray($arElement['PREVIEW_PICTURE']);
             $arElement['DETAIL_PICTURE'] = CFile::MakeFileArray($arElement['DETAIL_PICTURE']);
             if (isset($arFields['NAME'])) {
                 $arElement['NAME'] = $arFields['NAME'];
             }
             if (isset($arFields['SECTION_ID'])) {
                 $arElement['IBLOCK_SECTION_ID'] = $arFields['SECTION_ID'];
             }
             if (isset($arFields['SORT'])) {
                 $arElement['SORT'] = $arFields['SORT'];
             }
             if (isset($arFields['ACTIVE'])) {
                 $arElement['ACTIVE'] = $arFields['ACTIVE'];
             }
             if (isset($arFields['DETAIL_PICTURE'])) {
                 $arElement['DETAIL_PICTURE'] = $arFields['DETAIL_PICTURE'];
             }
             if (isset($arFields['DESCRIPTION'])) {
                 $arElement['DETAIL_TEXT'] = $arFields['DESCRIPTION'];
             }
             if (isset($arFields['DESCRIPTION_TYPE'])) {
                 $arElement['DETAIL_TEXT_TYPE'] = $arFields['DESCRIPTION_TYPE'];
             }
             if (isset($arFields['PREVIEW_PICTURE'])) {
                 $arElement['PREVIEW_PICTURE'] = $arFields['PREVIEW_PICTURE'];
             }
             if (isset($arFields['PREVIEW_TEXT'])) {
                 $arElement['PREVIEW_TEXT'] = $arFields['PREVIEW_TEXT'];
                 $arElement['PREVIEW_TEXT_TYPE'] = 'text';
             }
             if (isset($arFields['PREVIEW_TEXT_TYPE'])) {
                 $arElement['PREVIEW_TEXT_TYPE'] = $arFields['PREVIEW_TEXT_TYPE'];
             }
             if (isset($arFields['XML_ID'])) {
                 $arElement['XML_ID'] = $arElement['EXTERNAL_ID'] = $arFields['XML_ID'];
             } else {
                 if (isset($arFields['ORIGINATOR_ID']) || isset($arFields['ORIGIN_ID'])) {
                     if (strlen($arFields['ORIGINATOR_ID']) > 0 && strlen($arFields['ORIGIN_ID']) > 0) {
                         $arElement['XML_ID'] = $arFields['ORIGINATOR_ID'] . '#' . $arFields['ORIGIN_ID'];
                     } else {
                         $delimiterPos = strpos($arElement['XML_ID'], '#');
                         if (strlen($arFields['ORIGINATOR_ID']) > 0) {
                             if ($delimiterPos !== false) {
                                 $arElement['XML_ID'] = $arFields['ORIGINATOR_ID'] . substr($arElement['XML_ID'], $delimiterPos);
                             } else {
                                 $arElement['XML_ID'] = $arFields['ORIGINATOR_ID'];
                             }
                         } else {
                             if ($delimiterPos !== false) {
                                 $arElement['XML_ID'] = substr($arElement['XML_ID'], 0, $delimiterPos) . $arFields['ORIGIN_ID'];
                             } else {
                                 $arElement['XML_ID'] = '#' . $arFields['ORIGINATOR_ID'];
                             }
                         }
                     }
                 }
             }
             if (isset($arFields['PROPERTY_VALUES'])) {
                 $arElement['PROPERTY_VALUES'] = $arFields['PROPERTY_VALUES'];
             }
             if (!$element->Update($ID, $arElement)) {
                 self::$LAST_ERROR = $element->LAST_ERROR;
                 return false;
             }
         }
     }
     // update VAT
     $CCatalogProduct = new CCatalogProduct();
     $arCatalogProductFields = array();
     if (isset($arFields['VAT_INCLUDED'])) {
         $arCatalogProductFields['VAT_INCLUDED'] = $arFields['VAT_INCLUDED'];
     }
     if (isset($arFields['VAT_ID']) && !empty($arFields['VAT_ID'])) {
         $arCatalogProductFields['VAT_ID'] = $arFields['VAT_ID'];
     }
     if (isset($arFields['MEASURE']) && !empty($arFields['MEASURE'])) {
         $arCatalogProductFields['MEASURE'] = $arFields['MEASURE'];
     }
     if (count($arCatalogProductFields) > 0) {
         $CCatalogProduct->Update($ID, $arCatalogProductFields);
     }
     if (isset($arFields['PRICE']) && isset($arFields['CURRENCY_ID'])) {
         self::setPrice($ID, $arFields['PRICE'], $arFields['CURRENCY_ID']);
     } else {
         if (isset($arFields['PRICE']) || isset($arFields['CURRENCY_ID'])) {
             $CPrice = new CPrice();
             $price = $currency = false;
             if (!isset($arFields['PRICE'])) {
                 $basePriceInfo = self::getPrice($ID);
                 if ($basePriceInfo !== false && is_array($basePriceInfo) && isset($basePriceInfo['PRICE'])) {
                     $price = $basePriceInfo['PRICE'];
                     $currency = $arFields['CURRENCY_ID'];
                 }
             } elseif (!isset($arFields['CURRENCY_ID'])) {
                 $basePriceInfo = self::getPrice($ID);
                 if ($basePriceInfo !== false && is_array($basePriceInfo) && isset($basePriceInfo['PRICE'])) {
                     $price = $arFields['PRICE'];
                     $currency = $basePriceInfo['CURRENCY'];
                 }
             } else {
                 $price = $arFields['PRICE'];
                 $currency = $arFields['CURRENCY_ID'];
             }
             if ($price !== false && $currency !== false) {
                 CCrmProduct::setPrice($ID, $price, $currency);
             }
         }
     }
     //		$sUpdate = trim($DB->PrepareUpdate(CCrmProduct::TABLE_NAME, $arFields));
     //		if (!empty($sUpdate))
     //		{
     //			$sQuery = 'UPDATE '.CCrmProduct::TABLE_NAME.' SET '.$sUpdate.' WHERE ID = '.$ID;
     //			$DB->Query($sQuery, false, 'File: '.__FILE__.'<br/>Line: '.__LINE__);
     //
     //			CCrmEntityHelper::RemoveCached(self::CACHE_NAME, $ID);
     //		}
     CCrmEntityHelper::RemoveCached(self::CACHE_NAME, $ID);
     return true;
 }
Ejemplo n.º 2
0
    return;
}
if (!\Bitrix\Main\Loader::includeModule("sale")) {
    ShowError('Module sale is not loaded');
    return;
}
// check fields
if (!empty($_REQUEST['productid'])) {
    $productid = (int) $_REQUEST['productid'];
}
if (empty($productid)) {
    ShowError('$_REQUEST["productid"] is empty');
    return;
}
// get product name
$arProduct = CIBlockElement::GetById($productid)->Fetch();
if (!$arProduct) {
    ShowError('$arProduct is empty');
    true;
}
// get product price
$arPrice = CCatalogProduct::GetOptimalPrice($arProduct['ID'], 1, $USER->GetUserGroupArray());
if (empty($arPrice['PRICE']['PRICE'])) {
    ShowError('$arPrice["PRICE"]["PRICE"] is empty');
}
// add product to basket
$arBasket = array('PRODUCT_ID' => $arProduct['ID'], 'PRODUCT_PRICE_ID' => $arPrice['PRICE']['ID'], 'PRICE' => $arPrice['PRICE']['PRICE'], 'CURRENCY' => $arPrice['PRICE']['CURRENCY'], 'LID' => $arProduct['LID'], 'DELAY' => 'Y', 'NAME' => $arProduct['NAME']);
$result = CSaleBasket::Add($arBasket);
// answer to ajax
echo (int) $result;
require $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/epilog_after.php";
Ejemplo n.º 3
0
?>
 <br /> -->
									<?endif?>

									<!-- <strong><?php 
echo GetMessage('SPOL_BASKET');
?>
:</strong> -->
									<table style="width: 100%">
										<?foreach ($order["BASKET_ITEMS"] as $item): ?>
										<?
										$product = CCatalogSku::GetProductInfo($item['PRODUCT_ID']);
										if (false === $product) {
											$element = CIBlockElement::GetById($item['PRODUCT_ID'])->Fetch();
										} else {
											$element = CIBlockElement::GetById($product['ID'])->Fetch();
										}
										$item['DETAIL_PAGE_URL'] = '/butik/' . $element['CODE'] .'/';
										$item['PREVIEW_PICTURE'] = CFile::ResizeImageGet($element['PREVIEW_PICTURE'], array('width' => 100, 'height' => 100));
										?>
											<tr>
												<td style="width: 30%">
													<a href="<?php 
echo $item["DETAIL_PAGE_URL"];
?>
" target="_blank">
													<img src="<?php 
echo $item['PREVIEW_PICTURE']['src'];
?>
">
													</a>
Ejemplo n.º 4
0
 /**
  * Возвращает путь до картинки
  */
 function getImage($arProperty)
 {
     $current = self::getCurrent($arProperty);
     $image = null;
     $p = strtoupper($arProperty['USER_TYPE_SETTINGS']['PROPERTY_NAME']);
     $link = strtoupper($arProperty['USER_TYPE_SETTINGS']['PROPERTY_LINK']);
     if ($link && !empty($current[$link])) {
         //узнаем инфоблок привязанного свойства
         if ($link === 'IBLOCK_SECTION_ID') {
             $res = \CIBlockSection::GetById($current[$link]);
             if ($ob = $res->Fetch()) {
                 $image = isset($ob[$p]) ? $ob[$p] : null;
             }
         } else {
             $res = \CIBlockElement::GetById($current[$link]);
             if ($ob = $res->Fetch()) {
                 if (strpos($p, 'PROPERTY_') === 0) {
                     $pres = \CIBlockElement::GetProperty($ob['IBLOCK_ID'], $ob['ID'], [], ['CODE' => substr($p, 9)]);
                     if ($pob = $pres->Fetch()) {
                         $image = $pob['VALUE'];
                     }
                 } else {
                     $image = isset($ob[$p]) ? $ob[$p] : null;
                 }
             }
         }
     } elseif (!empty($current[$p])) {
         $image = $current[$p];
     }
     if ($image && is_numeric($image)) {
         $image = \CFile::GetPath($image);
     }
     return $image;
 }
Ejemplo n.º 5
0
<?php

require $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_before.php";
$req = $_REQUEST;
CModule::IncludeModule("sale");
CModule::IncludeModule("iblock");
//_show_array($req);
if (!empty($req['id']) && !empty($req['width']) && !empty($req['height']) && !empty($req['quantity']) && !empty($req['price'])) {
    $rsProd = CIBlockElement::GetById($req['id']);
    if ($arProd = $rsProd->Fetch()) {
        $arFields = array("PRODUCT_ID" => $arProd['ID'], "PRICE" => $req['price'], "CURRENCY" => "RUB", "WEIGHT" => !empty($req['weight']) && $req['weight'] != '' ? $req['weight'] : 'Нет', "QUANTITY" => $req['quantity'], "LID" => LANG, "DELAY" => "N", "CAN_BUY" => "Y", "NAME" => $arProd['NAME']);
        $arProps = array();
        $arProps[] = array("NAME" => "Объем", "CODE" => "VOLUME", "VALUE" => !empty($req['volume']) && $req['volume'] != '' ? $req['volume'] : 'Нет');
        $arProps[] = array("NAME" => "Цвет", "CODE" => "COLOR", "VALUE" => !empty($req['color']) && $req['color'] != '' ? $req['color'] : 'Нет');
        $arProps[] = array("NAME" => "Ширина", "CODE" => "WIDTH", "VALUE" => $req['width'] . ' мм');
        $arProps[] = array("NAME" => "Высота", "CODE" => "HEIGHT", "VALUE" => $req['height'] . ' мм');
        $arFields["PROPS"] = $arProps;
        //        _show_array($arFields);
        $basketId = CSaleBasket::Add($arFields);
    }
}
//!empty($basketId) ? _show_array(CSaleBasket::GetById($basketId)) : _show_array('А вот хрен тебе! :Р');