/** * Check if an item matches the criteria set by the product row * * @param Order\Entity\Item\Item $item * @param ProductRow $row * * @return bool */ public function itemIsApplicable(Order\Entity\Item\Item $item, ProductRow $row) { if (in_array($item->id, $this->_alreadyInBundle)) { return false; } if ((int) $item->getProduct()->id !== $row->getProductID()) { return false; } if (count($row->getOptions()) <= 0) { return true; } $unit = $item->getUnit(); foreach ($row->getOptions() as $name => $value) { if (!($unit->hasOption($name) && $unit->getOption($name) === $value)) { return false; } } return true; }
/** * Add a row of product information to the bundle, determining a requirement for the bundle to be deemed as valid * * @param ProductRow $row */ public function addProductRow(ProductRow $row) { $key = md5(serialize([$row->getProductID(), $row->getOptions()])); if (array_key_exists($key, $this->_productRows)) { $this->_productRows[$key]->increaseQuantity($row->getQuantity()); } else { $this->_productRows[$key] = $row; } }