/** * Returns a list of all the warehouses with a value in use for the stock * GridField instance. Will create records for products that don't have * them. * * @return DataList */ public function getStockForEachWarehouse() { $warehouses = ProductWarehouse::get(); $output = new ArrayList(); $defaults = ProductWarehouseStock::config()->get('defaults'); foreach ($warehouses as $warehouse) { $stock = $this->getStockForWarehouse($warehouse); $output->push($stock); } return $output; }
/** * Returns a list of all the warehouses with a value in use for the stock * GridField instance. Will create records for products that don't have * them. * * @return DataList */ public function getStockForEachWarehouse() { $warehouses = ProductWarehouse::get(); $output = new ArrayList(); $defaults = ProductWarehouseStock::config()->get('defaults'); foreach ($warehouses as $warehouse) { $base = $this->getStockBaseIdentifier(); $record = $this->getWarehouseStock()->first(); if (!$record) { $record = Injector::inst()->create('ProductWarehouseStock'); $record->WarehouseID = $warehouse->ID; $record->ProductID = $this->owner->ID; $record->ProductClass = $base; $record->Quantity = $defaults['Quantity']; $record->write(); } $output->push($record); } return $output; }