/** * Validate order item * * @param \XLite\Model\AEntity $entity Entity * @param boolean $isUpdate True if entity is updated; false if created * * @return boolean */ protected function validateOrderItem(\XLite\Model\AEntity $entity, $isUpdate = false) { $result = true; if ($isUpdate && !$this->getChangedFields($entity->getItemId())) { // Ignore order item validation if item was updated but was not changed } elseif (!$entity->isActualAttributes()) { $data = $this->getRequestData(); if (isset($data['order_items'][$entity->getItemId()]['attribute_values'])) { $message = static::t('Order item attributes are out-of-date and cannot be edited'); } } elseif (!$this->isValidEntity($entity)) { $result = false; $message = static::t('Product with selected properties cannot be purchased'); } elseif (!$isUpdate && $entity->hasWrongAmount()) { $result = false; $message = static::t('The specified amount of product exceeds maximum amount of product in stock', array('value' => $entity->getAmount(), 'max' => $entity->getProductAvailableAmount())); } elseif ($isUpdate && $entity->isItemHasWrongAmount($entity)) { $result = false; $message = static::t('The specified amount of product exceeds maximum amount of product in stock', array('value' => $entity->getAmount(), 'max' => $entity->getProductAvailableAmount() + $this->orderItemsData[$entity->getItemId()]['amount'])); } if (!$result) { $this->errorMessages[] = sprintf('[%s] %s: %s', static::t('Error'), $message, $this->formatItem($entity)); } elseif (!empty($message)) { $this->warningMessages[] = sprintf('[%s] %s: %s', static::t('Warning'), $message, $this->formatItem($entity)); } return $result; }