3namespace Bitrix\Catalog\Document\Action\Store;
5use Bitrix\Catalog\Document\Action;
6use Bitrix\Catalog\Document\Action\ProductAndStoreInfo;
7use Bitrix\Catalog\EO_StoreBatch;
8use Bitrix\Catalog\Product\Store\CostPriceCalculator;
9use Bitrix\Catalog\StoreBatchDocumentElementTable;
10use Bitrix\Catalog\StoreBatchTable;
11use Bitrix\Main\Config\Option;
13use Bitrix\Main\Loader;
14use Bitrix\Main\Localization\Loc;
15use Bitrix\Main\Result;
39 $this->storeId = $storeId;
60 if (CostPriceCalculator::getMethod() === CostPriceCalculator::METHOD_AVERAGE)
62 $batch = $this->
loadBatch($this->storeId);
69 (
float)$this->purchasingPrice,
70 $this->purchasingCurrency,
72 $resultUpdate = $batch->save();
73 if (!$resultUpdate->isSuccess())
76 new Error(Loc::getMessage(
'CATALOG_STORE_DOCS_ERR_CANT_UPDATE_STORE_PRODUCT'))
86 $batch = $this->createBatch(
89 $this->purchasingPrice,
90 $this->purchasingCurrency,
97 new Error(Loc::getMessage(
'CATALOG_STORE_DOCS_ERR_CANT_UPDATE_STORE_PRODUCT'))
106 $this->purchasingPrice,
107 $this->purchasingCurrency,
122 'STORE_ID' => $storeId,
131 protected function createBatch(
141 'AVAILABLE_AMOUNT' => $amount,
146 if (!$resultAdd->isSuccess())
151 $batch = $resultAdd->getObject();
166 'PRODUCT_BATCH_ID' => $batch->getId(),
184 $precision = (int)Option::get(
'sale',
'value_precision', 2);
185 $newAvailableAmount = $batch->getAvailableAmount() +
$amount;
186 $newPurchasingPrice = ($batch->getPurchasingPrice() * $batch->getAvailableAmount() +
$purchasingPrice *
$amount) / $newAvailableAmount;
187 $newPurchasingPrice = round($newPurchasingPrice,
$precision);
189 $batch->setAvailableAmount($newAvailableAmount);
190 $batch->setPurchasingPrice($newPurchasingPrice);
193 private function convertPrice(
199 if (!Loader::includeModule(
'currency'))
204 return \CCurrencyRates::convertCurrency(
recalculateBatch(EO_StoreBatch $batch, float $amount, float $purchasingPrice, string $purchasingCurrency=null,)
string $purchasingCurrency
__construct(int $storeId, int $productId, float $amount, int $documentElementId=null, float $purchasingPrice=null, string $purchasingCurrency=null)
addDocumentElementBatchBinding(EO_StoreBatch $batch, float $amount, float $purchasingPrice=null, string $purchasingCurrency=null,)
static getList(array $parameters=array())
trait ProductAndStoreInfo