StockLevelProcessor.php in Commerce Stock 8
File
modules/field/src/StockLevelProcessor.php
View source
<?php
namespace Drupal\commerce_stock_field;
use Drupal\Core\TypedData\TypedData;
class StockLevelProcessor extends TypedData {
protected $valueComputed = FALSE;
protected $processedLevel = NULL;
public function getValue() {
$this
->ensureComputedValue();
return $this->processedLevel;
}
public function setValue($value, $notify = TRUE) {
if (is_null($value)) {
return;
}
$this->processedLevel = $value;
$this->valueComputed = TRUE;
}
protected function computeValue() {
$entity = $this
->getParent()
->getEntity();
$stockServiceManager = \Drupal::service('commerce_stock.service_manager');
$level = $stockServiceManager
->getStockLevel($entity);
$this->processedLevel = $level;
}
protected function ensureComputedValue() {
if ($this->valueComputed === FALSE) {
$this
->computeValue();
$this->valueComputed = TRUE;
}
}
}