-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from dealer4dealer/resolve-issue-16
Resolve issue 16
- Loading branch information
Showing
6 changed files
with
235 additions
and
16 deletions.
There are no files selected for viewing
83 changes: 83 additions & 0 deletions
83
ExactConnectorHelper/Components/Api/Resource/ConnectorOrderStatusesHistory.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<?php | ||
|
||
namespace ExactConnectorHelper\Components\Api\Resource; | ||
|
||
use Shopware\Components\Api\Resource\Resource; | ||
use Shopware\Models\Order\History; | ||
use Shopware\Models\Order\Status; | ||
use Shopware\Components\Api\Exception as ApiException; | ||
|
||
class ConnectorOrderStatusesHistory extends Resource | ||
{ | ||
|
||
/** | ||
* @return \Doctrine\Common\Persistence\ObjectRepository|\Doctrine\ORM\EntityRepository|\Shopware\Models\Dispatch\Repository | ||
*/ | ||
public function getRepository() | ||
{ | ||
return $this->getManager()->getRepository(History::class); | ||
} | ||
|
||
/** | ||
* Get order History Data | ||
* @param array $criteria | ||
* @param array $orderBy | ||
* @return array | ||
*/ | ||
public function getList(array $criteria = [], array $orderBy = []) | ||
{ | ||
$builder = $this->getRepository()->createQueryBuilder('history'); | ||
|
||
// Create builder on requested filter and sort | ||
$builder->addFilter($criteria) | ||
->addOrderBy($orderBy); | ||
|
||
$query = $builder->getQuery(); | ||
$query->setHydrationMode($this->resultMode); | ||
|
||
$paginator = $this->getManager()->createPaginator($query); | ||
|
||
//returns the total count of the query | ||
$totalResult = $paginator->count(); | ||
|
||
//returns the order history data | ||
$orderStatuses = $paginator->getIterator()->getArrayCopy(); | ||
|
||
return ['data' => $orderStatuses, 'total' => $totalResult]; | ||
} | ||
|
||
|
||
/** | ||
* Get one order status | ||
* | ||
* @param $id | ||
* @return mixed | ||
* @throws ApiException\NotFoundException | ||
* @throws ApiException\ParameterMissingException | ||
* @throws ApiException\PrivilegeException | ||
* @throws \Doctrine\ORM\NonUniqueResultException | ||
*/ | ||
public function getOne($id) | ||
{ | ||
$this->checkPrivilege('read'); | ||
|
||
if (empty($id)) { | ||
throw new ApiException\ParameterMissingException(); | ||
} | ||
|
||
$builder = $this->getRepository() | ||
->createQueryBuilder('orderStatus') | ||
->select('orderStatus') | ||
->where('orderStatus.id =?1') | ||
->setParameter(1, $id); | ||
|
||
$orderStatus = $builder->getQuery()->getOneOrNullResult($this->getResultMode()); | ||
|
||
if (!$orderStatus) { | ||
throw new ApiException\NotFoundException("Order status by id $id not found"); | ||
} | ||
|
||
return $orderStatus; | ||
} | ||
|
||
} |
46 changes: 46 additions & 0 deletions
46
ExactConnectorHelper/Controllers/Api/ConnectorOrderStatusesHistory.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
/** | ||
* Class Shopware_Controllers_Api_ConnectorOrderStatuses | ||
*/ | ||
class Shopware_Controllers_Api_ConnectorOrderStatusesHistory extends Shopware_Controllers_Api_Rest | ||
{ | ||
/** | ||
* @var Shopware\Components\Api\Resource\ConnectorOrderStatusesHistory | ||
*/ | ||
protected $resource; | ||
|
||
public function init() | ||
{ | ||
$this->resource = \Shopware\Components\Api\Manager::getResource('ConnectorOrderStatusesHistory'); | ||
} | ||
|
||
/** | ||
* GET Request on /api/ConnectorOrderStatuses | ||
*/ | ||
public function indexAction() | ||
{ | ||
$filter = $this->Request()->getParam('filter', []); | ||
$sort = $this->Request()->getParam('sort', []); | ||
|
||
$result = $this->resource->getList($filter, $sort); | ||
|
||
$this->View()->assign($result); | ||
$this->View()->assign('success', true); | ||
} | ||
|
||
/** | ||
* Get one order status | ||
* | ||
* GET /api/ConnectorOrderStatuses/{id} | ||
*/ | ||
public function getAction() | ||
{ | ||
$id = $this->Request()->getParam('id'); | ||
|
||
$orderStatus = $this->resource->getOne($id); | ||
|
||
$this->View()->assign(['data' => $orderStatus, 'success' => true]); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters