php XLite-Model-AEntity类(方法)实例源码

下面列出了php XLite-Model-AEntity 类(方法)源码代码实例,从而了解它的用法。

作者:kirkbauer    项目:kirkx   
/**
  * Find one by record
  *
  * @param array                $data   Record
  * @param \XLite\Model\AEntity $parent Parent model OPTIONAL
  *
  * @return \XLite\Model\AEntity|void
  */
 public function findOneByRecord(array $data, \XLite\Model\AEntity $parent = null)
 {
     if (empty($data['code'])) {
         $data['code'] = \XLite\Model\Base\Translation::DEFAULT_LANGUAGE;
     }
     return isset($parent) ? $parent->getTranslation($data['code']) : parent::findOneByRecord($data, $parent);
 }

作者:kings    项目:cor   
/**
  * Modify money 
  * 
  * @param float                $value     Value
  * @param \XLite\Model\AEntity $model     Model
  * @param string               $property  Model's property
  * @param array                $behaviors Behaviors
  * @param string               $purpose   Purpose
  *  
  * @return void
  */
 public static function modifyMoney($value, \XLite\Model\AEntity $model, $property, array $behaviors, $purpose)
 {
     foreach ($model->getOptions() as $option) {
         if ($option->getOption() && $option->getOption()->hasActiveSurcharge('price')) {
             $value += $option->getOption()->getSurcharge('price')->getAbsoluteValue();
         }
     }
     return $value;
 }

作者:kirkbauer    项目:kirkx   
/**
  * Get column value
  *
  * @param array                $column Column
  * @param \XLite\Model\AEntity $entity Model
  *
  * @return mixed
  */
 protected function getColumnValue(array $column, \XLite\Model\AEntity $entity)
 {
     if (isset($column[static::COLUMN_PRODUCT_ATTRIBUTE])) {
         $result = $entity->getAttributeValue($column[static::COLUMN_PRODUCT_ATTRIBUTE]);
         $result = $result ? $result->asString() : '';
     } else {
         $result = parent::getColumnValue($column, $entity);
     }
     return $result;
 }

作者:kewaunite    项目:xcar   
/**
  * Update entity
  *
  * @param \XLite\Model\AEntity $entity Entity to update
  * @param array                $data   New values for entity properties
  * @param boolean              $flush  Flag OPTIONAL
  *
  * @return void
  */
 public function update(\XLite\Model\AEntity $entity, array $data = array(), $flush = self::FLUSH_BY_DEFAULT)
 {
     $name = null;
     foreach ($entity->getTranslations() as $translation) {
         if ($translation->getName()) {
             $name = $translation->getName();
             break;
         }
     }
     if ($name) {
         foreach ($entity->getTranslations() as $translation) {
             if (!$translation->getName()) {
                 $translation->setName($name);
             }
         }
     }
     parent::update($entity, $data, $flush);
 }

作者:kirkbauer    项目:kirkx   
/**
  * Clone
  *
  * @return \XLite\Model\AEntity
  */
 public function cloneEntity()
 {
     $entity = parent::cloneEntity();
     foreach ($entity->getSoftTranslation()->getRepository()->findBy(array('owner' => $entity)) as $translation) {
         $newTranslation = $translation->cloneEntity();
         $newTranslation->setOwner($entity);
         $entity->addTranslations($newTranslation);
         \XLite\Core\Database::getEM()->persist($newTranslation);
     }
     return $entity;
 }

作者:kirkbauer    项目:kirkx   
/**
  * Return attribute values
  *
  * @param \XLite\Model\AEntity $model Model
  *
  * @return array
  */
 protected static function getAttributeValues(\XLite\Model\AEntity $model)
 {
     return $model instanceof \XLite\Module\XC\ProductVariants\Model\ProductVariant ? $model->getProduct()->getAttrValues() : parent::getAttributeValues($model);
 }

作者:kewaunite    项目:xcar   
/**
  * Check - remove entity or not
  *
  * @param \XLite\Model\AEntity $entity Entity
  *
  * @return boolean
  */
 protected function isAllowEntityRemove(\XLite\Model\AEntity $entity)
 {
     return $entity->isPersistent();
 }

作者:kirkbauer    项目:kirkx   
/**
  * Get specific language help message
  *
  * @param \XLite\Model\AEntity $entity Language object
  *
  * @return string
  */
 protected function getLanguageHelpMessage(\XLite\Model\AEntity $entity)
 {
     $message = null;
     if ($entity->getValidModule()) {
         $moduleClass = \Includes\Utils\ModulesManager::getClassNameByModuleName($entity->getModule());
         $moduleName = sprintf('%s (%s)', $moduleClass::getModuleName(), $moduleClass::getAuthorName());
         $message = static::t('This language is added by module and cannot be removed.', array('module' => $moduleName));
     } elseif ('en' == $entity->getCode()) {
         $message = 'English language cannot be removed as it is primary language for all texts.';
     }
     return $message;
 }

作者:kewaunite    项目:xcar   
/**
  * Build metod name
  *
  * @param \XLite\Model\AEntity $entity  Entity
  * @param string               $pattern Pattern
  *
  * @return string
  */
 protected function buildMetodName(\XLite\Model\AEntity $entity, $pattern)
 {
     return static::TYPE_COUPONS == $entity->getId() ? sprintf($pattern, 'Coupons') : parent::buildMetodName($entity, $pattern);
 }

作者:kirkbauer    项目:kirkx   
/**
  * Link loaded entity to parent object
  *
  * @param \XLite\Model\AEntity $entity      Loaded entity
  * @param \XLite\Model\AEntity $parent      Entity parent callback
  * @param array                $parentAssoc Entity mapped propery method
  *
  * @return void
  */
 protected function linkLoadedEntity(\XLite\Model\AEntity $entity, \XLite\Model\AEntity $parent, array $parentAssoc)
 {
     if (!$parentAssoc['many'] || !$entity->getUniqueIdentifier() || !$parent->{$parentAssoc}['getter']()->contains($entity)) {
         // Add entity to parent
         $parent->{$parentAssoc}['setter']($entity);
         // Add parent to entity
         if ($parentAssoc['mappedSetter']) {
             $entity->{$parentAssoc}['mappedSetter']($parent);
         }
     }
 }

作者:kewaunite    项目:xcar   
/**
  * Delete single entity
  *
  * @param \XLite\Model\AEntity $entity Entity to detach
  *
  * @return void
  */
 protected function performDelete(\XLite\Model\AEntity $entity)
 {
     $entity->setOldPaymentStatus(null);
     $entity->setOldShippingStatus(null);
     parent::performDelete($entity);
 }

作者:kirkbauer    项目:kirkx   
/**
  * Disable removing special methods
  *
  * @param \XLite\Model\AEntity $entity Shipping method object
  *
  * @return boolean
  */
 protected function isAllowEntityRemove(\XLite\Model\AEntity $entity)
 {
     /** @var \XLite\Model\Shipping\Method $entity */
     return !$entity->getFree() && !$this->isFixedFeeMethod($entity);
 }

作者:kewaunite    项目:xcar   
/**
  * Get column value
  *
  * @param array                $column Column
  * @param \XLite\Model\AEntity $entity Model
  *
  * @return mixed
  */
 protected function getFraudInfoXpcTitle(\XLite\Model\AEntity $entity)
 {
     return $entity->getFraudStatusXpc();
 }

作者:kirkbauer    项目:kirkx   
/**
  * 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;
 }

作者:kewaunite    项目:xcar   
/**
  * Build metod name
  *
  * @param \XLite\Model\AEntity $entity  Entity
  * @param string               $pattern Pattern
  *
  * @return string
  */
 protected function buildMetodName(\XLite\Model\AEntity $entity, $pattern)
 {
     return static::TYPE_DISCOUNTS == $entity->getId() ? sprintf($pattern, 'Discounts') : parent::buildMetodName($entity, $pattern);
 }

作者:kings    项目:cor   
/**
  * Modify money 
  * 
  * @param float                $value     Value
  * @param \XLite\Model\AEntity $model     Model
  * @param string               $property  Model's property
  * @param array                $behaviors Behaviors
  * @param string               $purpose   Purpose
  *  
  * @return void
  */
 public static function modifyMoney($value, \XLite\Model\AEntity $model, $property, array $behaviors, $purpose)
 {
     $obj = $model instanceof \XLite\Model\Product ? $model : $model->getProduct();
     return \XLite\Module\CDev\VAT\Logic\Product\Tax::getInstance()->deductTaxFromPrice($obj, $value);
 }

作者:kirkbauer    项目:kirkx   
/**
  * Return attribute values
  *
  * @param \XLite\Model\AEntity $model Model
  *
  * @return array
  */
 protected static function getAttributeValues(\XLite\Model\AEntity $model)
 {
     return $model instanceof \XLite\Model\Product ? $model->getAttrValues() : $model->getAttributeValues();
 }

作者:kirkbauer    项目:kirkx   
/**
  * Build entity page URL
  *
  * @param \XLite\Model\AEntity $entity Entity
  * @param array                $column Column data
  *
  * @return string
  */
 protected function buildEntityURL(\XLite\Model\AEntity $entity, array $column)
 {
     return \XLite\Core\Converter::buildURL($column[static::COLUMN_LINK], '', array('order_number' => $entity->getOrderNumber()));
 }

作者:kirkbauer    项目:kirkx   
/**
  * Clone
  *
  * @return \XLite\Model\AEntity
  */
 public function cloneEntity()
 {
     $newEntity = parent::cloneEntity();
     if ($this->getSku()) {
         $newEntity->setSku(\XLite\Core\Database::getRepo('XLite\\Module\\XC\\ProductVariants\\Model\\ProductVariant')->assembleUniqueSKU($this->getSku()));
     }
     return $newEntity;
 }

作者:kirkbauer    项目:kirkx   
/**
  * Check cache after enity persist or remove
  *
  * @return void
  */
 public function checkCache()
 {
     parent::checkCache();
     // Check translation owner cache
     if ($this->getOwner()) {
         $this->getOwner()->checkCache();
     }
 }


问题


面经


文章

微信
公众号

扫码关注公众号