Skip to content

Commit

Permalink
Merge pull request #18 from dealer4dealer/resolve-issue-16
Browse files Browse the repository at this point in the history
Resolve issue 16
  • Loading branch information
AlaaSemsemea authored Jan 5, 2021
2 parents c483878 + 47ebd14 commit 1d88ab9
Show file tree
Hide file tree
Showing 6 changed files with 235 additions and 16 deletions.
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;
}

}
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]);
}

}
40 changes: 26 additions & 14 deletions ExactConnectorHelper/ExactConnectorHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ public function install(InstallContext $context)
'displayInBackend' => false,
'custom' => false,
],
null, true
null,
true
);

$this->setDateOnInstall();
$this->generateEntity();
$context->scheduleClearCache(InstallContext::CACHE_LIST_ALL);
$this->setDateOnInstall();
}

public function uninstall(UninstallContext $context)
Expand All @@ -38,17 +38,29 @@ public function uninstall(UninstallContext $context)
}

$attributeService = $this->container->get('shopware_attribute.crud_service');
$attributeExists = $attributeService->get('s_articles_attributes', 'xcore_date');

if ($attributeExists) {
if ($attributeExists = $attributeService->get('s_articles_attributes', 'xcore_date')) {
$attributeService->delete(
's_articles_attributes',
'xcore_date'
);
}

if ($translationExists = $attributeService->get('s_articles_translations', 'xcore_date')) {
$attributeService->delete(
's_articles_translations',
'xcore_date'
);
}

if ($configuratorExists = $attributeService->get('s_article_configurator_templates_attributes', 'xcore_date')) {
$attributeService->delete(
's_article_configurator_templates_attributes',
'xcore_date'
);
}

$this->generateEntity();
$context->scheduleClearCache(InstallContext::CACHE_LIST_ALL);
}

public static function getSubscribedEvents()
Expand Down Expand Up @@ -87,9 +99,8 @@ private function setDateOnInstall()

foreach ($ids as $id) {
//for each product's id get both last changed date, and the Product's details.
explode(", ", $id);
$repostory = Shopware()->Models()->getRepository(Article::class);
$product = $repostory->find($id);
$repository = Shopware()->Models()->getRepository(Article::class);
$product = $repository->find($id);
$details = $product->getDetails();
$changeDate = $product->getChanged()->getTimestamp();
//convert the date.
Expand All @@ -115,20 +126,21 @@ private function generateEntity()

private function setDateOnProduct(Enlight_Controller_ActionEventArgs $args)
{
$argsId = $args->getRequest()->getParam('id');
$argsId = $args->getRequest()->getParam('id');
$now = date('Y-m-d H:i:s');
$requestBody = json_decode($args->getRequest()->getRawBody());


// //situation when updating product that have no variant.
$mainDetailId = $requestBody->mainDetailId ?? $requestBody->id;
//situation when updating product that have no variant.
$mainDetailId = $requestBody->mainDetailId ?: $requestBody->id;
if (($mainDetailId === $argsId)) {
$sqlQuery =
"UPDATE `s_articles_attributes`
SET `xcore_date` = " . "'" . $now . "'" .
"WHERE `articledetailsID` = " . $mainDetailId;
Shopware()->Db()->executeQuery($sqlQuery);
Shopware()->Container()->get('pluginlogger')->info(sprintf('the xcore_date for product with detail id: %s has been set to %s', $mainDetailId, $now));
Shopware()->Container()->get('pluginlogger')->info(
sprintf('the xcore_date for product with detail id: %s has been set to %s', $mainDetailId, $now)
);
} else {
//situation when updating variant from articles overview.
$repository = Shopware()->Models()->getRepository(Article::class);
Expand Down
1 change: 1 addition & 0 deletions ExactConnectorHelper/Resources/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<services>
<service id="shopware.api.connectorshippingmethods" class="ExactConnectorHelper\Components\Api\Resource\ConnectorShippingMethods"/>
<service id="shopware.api.connectororderstatuses" class="ExactConnectorHelper\Components\Api\Resource\ConnectorOrderStatuses"/>
<service id="shopware.api.connectororderstatuseshistory" class="ExactConnectorHelper\Components\Api\Resource\ConnectorOrderStatusesHistory"/>
<service id="shopware.api.connectorproductattributes" class="ExactConnectorHelper\Components\Api\Resource\ConnectorProductAttributes"/>
<service id="shopware.api.connectorproductattributesoptions" class="ExactConnectorHelper\Components\Api\Resource\ConnectorProductAttributesOptions"/>
<service id="shopware.api.connectorvatcodes" class="ExactConnectorHelper\Components\Api\Resource\ConnectorVatCode"/>
Expand Down
11 changes: 11 additions & 0 deletions ExactConnectorHelper/Subscriber/ControllerRegistration/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public static function getSubscribedEvents()
=> 'onGetConnectorShippingMethodsApiController',
'Enlight_Controller_Dispatcher_ControllerPath_Api_ConnectorOrderStatuses'
=> 'onGetConnectorOrderStatusesApiController',
'Enlight_Controller_Dispatcher_ControllerPath_Api_ConnectorOrderStatusesHistory'
=> 'onGetConnectorOrderStatusesHistoryApiController',
'Enlight_Controller_Dispatcher_ControllerPath_Api_ConnectorProductAttributes'
=> 'onGetConnectorProductAttributesApiController',
'Enlight_Controller_Dispatcher_ControllerPath_Api_ConnectorProductAttributesOptions'
Expand Down Expand Up @@ -72,6 +74,15 @@ public function onGetConnectorOrderStatusesApiController()
return $this->pluginDirectory . '/Controllers/Api/ConnectorOrderStatuses.php';
}

/**
* @return string
*/
public function onGetConnectorOrderStatusesHistoryApiController()
{
return $this->pluginDirectory . '/Controllers/Api/ConnectorOrderStatusesHistory.php';
}


/**
* @return string
*/
Expand Down
70 changes: 68 additions & 2 deletions ExactConnectorHelper/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,76 @@
<label lang="en">Exact Connector Helper</label>
<label lang="de">Exact Connector Helper</label>
<label lang="nl">Exact Connector Helper</label>
<version>2.2.0</version>
<version>2.2.1</version>
<copyright>(c) by dealer4dealer</copyright>
<license>(c)</license>
<license>proprietary</license>
<author>dealer4dealer</author>
<link>https://www.dealer4dealer.nl</link>
<compatibility minVersion="5.5.0"/>
<changelog version="2.2.1">
<changes>
<![CDATA[
<p>
<ul>
<li>Changed Events to update xcore_date field from different product variants frontend windows. </li>
<li>Completely remove the xcore_date when uninstalling the plugin</li>
<li>Changed the cache clearing functionality</li>
<li>Added a new Api endpoint OrderStatusHistory; which retrieve data from order_history table</li>
</ul>
</p>
]]>
</changes>
<changes lang="de">
<![CDATA[
<p>
<ul>
<li>Completely remove the xcore_date when uninstalling the plugin</li>
<li>Changed the cache clearing functionality</li>
<li>Added a new Api endpoint OrderStatusHistory; which retrieve data from order_history table</li>
</ul>
</p>
]]>
</changes>

</changelog>
<description>
<![CDATA[
<b>Exact Connector Helper</b>
<p>
The <i>Exact Connector Helper</i> is a special Shopware 5 plugin for the users of the <i>xCore</i>.<br>
The <i>Exact Connector Helper</i> extends Shopware 5 API by adding a set of new calls that are needed by <i>xCore</i>.
Below, the list of API endpoints made available by the Exact Connector Helper:
<ul>
<li>Shop currencies; </li>
<li>Order status; </li>
<li>Order status history; </li>
<li>Shipping methods; </li>
<li>Vat codes; </li>
<li>Product's extra attributes; </li>
<li>Product's extra attributes options; </li>
</ul><br>
In addition, the plugin add a new column to the product's attributes table <i>xcore_date</i>. This field allows the <i>xCore</i> to collect the last updated product's variants in order to synchronize the changed product's variant to Exact Online.<br>
For more information check the plugin manual: <a href="https://store.shopware.com/search?sSearch=teama_ExactConnectorHelper" rel="noopener">Plugin Manual</a></p>
]]>
</description>
<description lang="de">
<![CDATA[
<b>Exact Connector Helper</b>
<p>
The <i>Exact Connector Helper</i> is a special Shopware 5 plugin for the users of the <i>xCore</i>.<br>
The <i>Exact Connector Helper</i> extends Shopware 5 API by adding a set of new calls that are needed by <i>xCore</i>.
Below, the list of API endpoints made available by the Exact Connector Helper:
<ul>
<li>Shop currencies; </li>
<li>Order status; </li>
<li>Order status history; </li>
<li>Shipping methods; </li>
<li>Vat codes; </li>
<li>Product's extra attributes; </li>
<li>Product's extra attributes options; </li>
</ul><br>
In addition, the plugin add a new column to the product's attributes table <i>xcore_date</i>. This field allows the <i>xCore</i> to collect the last updated product's variants in order to synchronize the changed product's variant to Exact Online.<br>
For more information check the plugin manual: <a href="https://store.shopware.com/search?sSearch=teama_ExactConnectorHelper" rel="noopener">Plugin Manual</a></p>
]]>
</description>
</plugin>

0 comments on commit 1d88ab9

Please sign in to comment.