示例#1
0
 /**
  * @return \Magento\Framework\DB\QueryInterface
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function create()
 {
     $mapper = $this->criteria->getMapperInterfaceName();
     $mapperInstance = $this->mapperFactory->create($mapper);
     $select = $mapperInstance->map($this->criteria);
     $query = $this->queryFactory->create('Magento\\Framework\\DB\\Query', ['select' => $select, 'criteria' => $this->criteria, 'resource' => $this->resource]);
     return $query;
 }
 /**
  * Map criteria to Select Query Object
  *
  * @param CriteriaInterface $criteria
  * @return Select
  */
 public function map(CriteriaInterface $criteria)
 {
     $criteriaParts = $criteria->toArray();
     foreach ($criteriaParts as $key => $value) {
         $camelCaseKey = \Magento\Framework\Api\SimpleDataObjectConverter::snakeCaseToUpperCamelCase($key);
         $mapperMethod = 'map' . $camelCaseKey;
         if (method_exists($this, $mapperMethod)) {
             if (!is_array($value)) {
                 $value = [$value];
             }
             call_user_func_array([$this, $mapperMethod], $value);
         }
     }
     return $this->select;
 }