* @copyright Since 2007 PrestaShop SA and Contributors * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) */ namespace PrestaShopBundle\Api\Stock; use PrestaShopBundle\Entity\ProductIdentity; class MovementsCollection { private $movements = []; /** * @param array $stockMovementsParams * * @return $this */ public function fromArray(array $stockMovementsParams) { $movements = []; array_walk($stockMovementsParams, function ($item) use (&$movements) { $combinationId = 0; if ($item['delta'] != 0) { if (array_key_exists('combination_id', $item)) { $combinationId = $item['combination_id']; } $productIdentity = ProductIdentity::fromArray([ 'product_id' => $item['product_id'], 'combination_id' => $combinationId, ]); $movements[] = new Movement($productIdentity, $item['delta']); } }); $this->movements = $movements; return $this; } /** * @param callable $callback * * @return array */ public function map(callable $callback) { return array_map($callback, $this->movements); } }