diff --git a/Components/Api/Resource/Quote.php b/Components/Api/Resource/Quote.php new file mode 100644 index 0000000..58caa61 --- /dev/null +++ b/Components/Api/Resource/Quote.php @@ -0,0 +1,153 @@ +getManager()->getRepository(QuoteModel::class); + } + + /** + * @param int $offset + * @param int $limit + * @param array $criteria + * @param array $orderBy + * @return array + */ + public function getList($offset = 0, $limit = 25, array $criteria = [], array $orderBy = []) + { + //$builder = Shopware()->Models()->createQueryBuilder(); + //$builder->select(['quote'])->from(\MailCampaignsConnector\Models\Quote\Quote::class, 'quote'); + + $builder = $this->getRepository()->createQueryBuilder('quote'); + + $builder + ->addFilter($criteria) + ->addOrderBy($orderBy) + ->setFirstResult($offset) + ->setMaxResults($limit); + + $query = $builder->getQuery(); + $query->setHydrationMode($this->resultMode); + $sql = $query->getSql(); + + $paginator = $this->getManager()->createPaginator($query); + + //returns the total count of the query + $totalResult = $paginator->count(); + + //returns the Quote data + $quotes = $paginator->getIterator()->getArrayCopy(); + $newquotes = array(); + $quotedates = array(); + $i=0; + foreach($quotes as $quote) + { + $newquotes[$quote["sessionId"]]["customerId"] = $quote["customerId"]; + $newquotes[$quote["sessionId"]]["sessionId"] = $quote["sessionId"]; + $newquotes[$quote["sessionId"]]["dateChanged"] = $quote["date"]; + + /* Creation date */ + if ($newquotes[$quote["sessionId"]]["dateCreated"] == "") + $newquotes[$quote["sessionId"]]["dateCreated"] = $quote["date"]; + + if (strtotime($quote["date"]) < strtotime($newquotes[$quote["sessionId"]]["dateCreated"])) + { + $newquotes[$quote["sessionId"]]["dateCreated"] = $quote["date"]; + } + /* Creation date */ + + $quote["customerId"] = $quote["customerId"]; + $newquotes[$quote["sessionId"]]["details"][] = $quote; + } + + return ['data' => $newquotes, 'total' => $totalResult]; // , 'sql' => $sql, + } + + /** + * Get One Quote Information + * + * @param $id + * @return mixed + * @throws ApiException\NotFoundException + * @throws ApiException\ParameterMissingException + */ + public function getOne($id) + { + $this->checkPrivilege('read'); + + if (empty($id)) { + throw new ApiException\ParameterMissingException(); + } + + $builder = $this->getRepository() + ->createQueryBuilder('Quote') + ->select('Quote') + ->where('Quote.id = ?1') + ->setParameter(1, $id); + + /** @var QuoteModel $quote */ + $quote = $builder->getQuery()->getOneOrNullResult($this->getResultMode()); + + if (!$quote) { + throw new ApiException\NotFoundException("Quote by id $id not found"); + } + + return $quote; + } + + /** + * @param $id + * @param array $params + * @return null|object + * @throws ApiException\ValidationException + * @throws ApiException\NotFoundException + * @throws ApiException\ParameterMissingException + */ + public function update($id, array $params) + { + $this->checkPrivilege('update'); + + if (empty($id)) { + throw new ApiException\ParameterMissingException(); + } + + /** @var $quote QuoteModel */ + $builder = $this->getRepository() + ->createQueryBuilder('Quote') + ->select('Quote') + ->where('Quote.id = ?1') + ->setParameter(1, $id); + + /** @var QuoteModel $quote */ + $quote = $builder->getQuery()->getOneOrNullResult(self::HYDRATE_OBJECT); + + if (!$quote) { + throw new ApiException\NotFoundException("Quote by id $id not found"); + } + + $quote->fromArray($params); + + $violations = $this->getManager()->validate($quote); + if ($violations->count() > 0) { + throw new ApiException\ValidationException($violations); + } + + $this->flush(); + + return $quote; + } +} diff --git a/Components/Api/Resource/Subscriber.php b/Components/Api/Resource/Subscriber.php new file mode 100644 index 0000000..1b88136 --- /dev/null +++ b/Components/Api/Resource/Subscriber.php @@ -0,0 +1,195 @@ +getManager()->getRepository(SubscriberModel::class); + } + + /** + * Create new Subscriber + * + * @param array $params + * @return SubscriberModel + * @throws ApiException\ValidationException + */ + public function create(array $params) + { + /** @var SubscriberModel $subscriber */ + $subscriber = new SubscriberModel(); + + $subscriber->fromArray($params); + + $violations = $this->getManager()->validate($subscriber); + + /** + * Handle Violation Errors + */ + if ($violations->count() > 0) { + throw new ApiException\ValidationException($violations); + } + + $this->getManager()->persist($subscriber); + $this->flush(); + + return $subscriber; + } + + /** + * @param int $offset + * @param int $limit + * @param array $criteria + * @param array $orderBy + * @return array + */ + public function getList($offset = 0, $limit = 25, array $criteria = [], array $orderBy = []) + { + // $builder = Shopware()->Models()->createQueryBuilder(); + // $builder->select(['s.id, s.email, s']) + // ->from(\MailCampaignsConnector\Models\Subscriber\Subscriber::class, 's'); + // $results = $builder->getQuery()->getArrayResult(); + // $getDql = $builder->getDql(); + // $getSql = $builder->getQuery()->getSql(); + // return ['data' => $results, 'getDql' => $getDql, 'getSql' => $getSql]; + + $builder = $this->getRepository()->createQueryBuilder('subscriber'); + $builder->addFilter($criteria) + ->addOrderBy($orderBy) + ->setFirstResult($offset) + ->setMaxResults($limit); + $query = $builder->getQuery(); + $query->setHydrationMode($this->resultMode); + + $paginator = $this->getManager()->createPaginator($query); + + //returns the total count of the query + $totalResult = $paginator->count(); + + //returns the Subscriber data + $subscriber = $paginator->getIterator()->getArrayCopy(); + // ookcool + // $subscriber = $query->getSingleResult(); + // $subscriber = $query->getArrayResult(); + // $subscriber = $query->getScalarResult(); + // $subscriber = $query->getSingleScalarResult(); + + $getDql = $builder->getDql(); + $getSql = $builder->getQuery()->getSql(); + + return ['data' => $subscriber, 'total' => $totalResult]; + } + + /** + * Delete Existing Subscriber + * + * @param $id + * @return null|object + * @throws ApiException\NotFoundException + * @throws ApiException\ParameterMissingException + */ + public function delete($id) + { + $this->checkPrivilege('delete'); + + if (empty($id)) { + throw new ApiException\ParameterMissingException(); + } + + $subscriber = $this->getRepository()->find($id); + + if (!$subscriber) { + throw new ApiException\NotFoundException("Subscriber by id $id not found"); + } + + $this->getManager()->remove($subscriber); + $this->flush(); + } + + /** + * Get One Subscriber Information + * + * @param $id + * @return mixed + * @throws ApiException\NotFoundException + * @throws ApiException\ParameterMissingException + */ + public function getOne($id) + { + $this->checkPrivilege('read'); + + if (empty($id)) { + throw new ApiException\ParameterMissingException(); + } + + $builder = $this->getRepository() + ->createQueryBuilder('Subscriber') + ->select('Subscriber') + ->where('Subscriber.id = ?1') + ->setParameter(1, $id); + + /** @var SubscriberModel $subscriber */ + $subscriber = $builder->getQuery()->getOneOrNullResult($this->getResultMode()); + + if (!$subscriber) { + throw new ApiException\NotFoundException("Subscriber by id $id not found"); + } + + return $subscriber; + } + + /** + * @param $id + * @param array $params + * @return null|object + * @throws ApiException\ValidationException + * @throws ApiException\NotFoundException + * @throws ApiException\ParameterMissingException + */ + public function update($id, array $params) + { + $this->checkPrivilege('update'); + + if (empty($id)) { + throw new ApiException\ParameterMissingException(); + } + + /** @var $subscriber SubscriberModel */ + $builder = $this->getRepository() + ->createQueryBuilder('Subscriber') + ->select('Subscriber') + ->where('Subscriber.id = ?1') + ->setParameter(1, $id); + + /** @var SubscriberModel $subscriber */ + $subscriber = $builder->getQuery()->getOneOrNullResult(self::HYDRATE_OBJECT); + + if (!$subscriber) { + throw new ApiException\NotFoundException("Subscriber by id $id not found"); + } + + $subscriber->fromArray($params); + + $violations = $this->getManager()->validate($subscriber); + if ($violations->count() > 0) { + throw new ApiException\ValidationException($violations); + } + + $this->flush(); + + return $subscriber; + } +} diff --git a/Controllers/Api/Quote.php b/Controllers/Api/Quote.php new file mode 100644 index 0000000..7b1f3b7 --- /dev/null +++ b/Controllers/Api/Quote.php @@ -0,0 +1,100 @@ +resource = \Shopware\Components\Api\Manager::getResource('Quote'); + } + + /** + * GET Request on /api/Quote + */ + public function indexAction() + { + $limit = $this->Request()->getParam('limit', 1000); + $offset = $this->Request()->getParam('start', 0); + $sort = $this->Request()->getParam('sort', []); + $filter = $this->Request()->getParam('filter', []); + + $result = $this->resource->getList($offset, $limit, $filter, $sort); + $this->View()->assign(['success' => true, 'data' => $result]); + } + + /** + * Create new Quote + * + * POST /api/Quote + */ + public function postAction() + { + $banner = $this->resource->create($this->Request()->getPost()); + + $location = $this->apiBaseUrl . 'Quote/' . $banner->getId(); + + $data = [ + 'id' => $banner->getId(), + 'location' => $location, + ]; + $this->View()->assign(['success' => true, 'data' => $data]); + $this->Response()->setHeader('Location', $location); + } + + /** + * Get one Quote + * + * GET /api/Quote/{id} + */ + public function getAction() + { + $id = $this->Request()->getParam('id'); + /** @var \Shopware\Models\Quote\Quote $banner */ + $banner = $this->resource->getOne($id); + + $this->View()->assign(['success' => true, 'data' => $banner]); + } + + /** + * Update One Quote + * + * PUT /api/Quote/{id} + */ + public function putAction() + { + $bannerId = $this->Request()->getParam('id'); + $params = $this->Request()->getPost(); + + /** @var \Shopware\Models\Quote\Quote $banner */ + $banner = $this->resource->update($bannerId, $params); + + $location = $this->apiBaseUrl . 'Quote/' . $bannerId; + $data = [ + 'id' => $banner->getId(), + 'location' => $location + ]; + + $this->View()->assign(['success' => true, 'data' => $data]); + } + + /** + * Delete One Quote + * + * DELETE /api/Quote/{id} + */ + public function deleteAction() + { + $bannerId = $this->Request()->getParam('id'); + + $this->resource->delete($bannerId); + + $this->View()->assign(['success' => true]); + } +} diff --git a/Controllers/Api/Subscriber.php b/Controllers/Api/Subscriber.php new file mode 100644 index 0000000..0572900 --- /dev/null +++ b/Controllers/Api/Subscriber.php @@ -0,0 +1,100 @@ +resource = \Shopware\Components\Api\Manager::getResource('Subscriber'); + } + + /** + * GET Request on /api/Subscriber + */ + public function indexAction() + { + $limit = $this->Request()->getParam('limit', 1000); + $offset = $this->Request()->getParam('start', 0); + $sort = $this->Request()->getParam('sort', []); + $filter = $this->Request()->getParam('filter', []); + + $result = $this->resource->getList($offset, $limit, $filter, $sort); + $this->View()->assign(['success' => true, 'data' => $result]); + } + + /** + * Create new Subscriber + * + * POST /api/Subscriber + */ + public function postAction() + { + $banner = $this->resource->create($this->Request()->getPost()); + + $location = $this->apiBaseUrl . 'Subscriber/' . $banner->getId(); + + $data = [ + 'id' => $banner->getId(), + 'location' => $location, + ]; + $this->View()->assign(['success' => true, 'data' => $data]); + $this->Response()->setHeader('Location', $location); + } + + /** + * Get one Subscriber + * + * GET /api/Subscriber/{id} + */ + public function getAction() + { + $id = $this->Request()->getParam('id'); + /** @var \Shopware\Models\Subscriber\Subscriber $banner */ + $banner = $this->resource->getOne($id); + + $this->View()->assign(['success' => true, 'data' => $banner]); + } + + /** + * Update One Subscriber + * + * PUT /api/Subscriber/{id} + */ + public function putAction() + { + $bannerId = $this->Request()->getParam('id'); + $params = $this->Request()->getPost(); + + /** @var \Shopware\Models\Subscriber\Subscriber $banner */ + $banner = $this->resource->update($bannerId, $params); + + $location = $this->apiBaseUrl . 'Subscriber/' . $bannerId; + $data = [ + 'id' => $banner->getId(), + 'location' => $location + ]; + + $this->View()->assign(['success' => true, 'data' => $data]); + } + + /** + * Delete One Subscriber + * + * DELETE /api/Subscriber/{id} + */ + public function deleteAction() + { + $bannerId = $this->Request()->getParam('id'); + + $this->resource->delete($bannerId); + + $this->View()->assign(['success' => true]); + } +} diff --git a/Core/sOrder.php b/Core/sOrder.php new file mode 100644 index 0000000..15c5adc --- /dev/null +++ b/Core/sOrder.php @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/MailCampaignsConnector.php b/MailCampaignsConnector.php new file mode 100644 index 0000000..3d37d83 --- /dev/null +++ b/MailCampaignsConnector.php @@ -0,0 +1,42 @@ + 'onEnlightControllerFrontStartDispatch' + ]; + } + + /** + * @return string + */ + public function onGetSubscriberApiController() + { + return $this->getPath() . '/Controllers/Api/Subscriber.php'; + } + + /** + * @return string + */ + public function onGetQuoteApiController() + { + return $this->getPath() . '/Controllers/Api/Quote.php'; + } + + /** + * + */ + public function onEnlightControllerFrontStartDispatch() + { + $this->container->get('loader')->registerNamespace('Shopware\Components', $this->getPath() . '/Components/'); + } +} diff --git a/Models/Quote/Quote.php b/Models/Quote/Quote.php new file mode 100644 index 0000000..ac3613c --- /dev/null +++ b/Models/Quote/Quote.php @@ -0,0 +1,472 @@ +attribute; + } + + /** + * @param \Shopware\Models\Attribute\OrderBasket|array|null $attribute + * + * @return \Shopware\Models\Attribute\OrderBasket + */ + public function setAttribute($attribute) + { + return $this->setOneToOne($attribute, '\Shopware\Models\Attribute\OrderBasket', 'attribute', 'orderBasket'); + } + + /** + * @return int + */ + public function getId() + { + return $this->id; + } + + /** + * @param string $articleName + */ + public function setArticleName($articleName) + { + $this->articleName = $articleName; + } + + /** + * @return string + */ + public function getArticleName() + { + return $this->articleName; + } + + /** + * @param string $config + */ + public function setConfig($config) + { + $this->config = $config; + } + + /** + * @return string + */ + public function getConfig() + { + return $this->config; + } + + /** + * @param float $currencyFactor + */ + public function setCurrencyFactor($currencyFactor) + { + $this->currencyFactor = $currencyFactor; + } + + /** + * @return float + */ + public function getCurrencyFactor() + { + return $this->currencyFactor; + } + + /** + * @param int $esdArticle + */ + public function setEsdArticle($esdArticle) + { + $this->esdArticle = $esdArticle; + } + + /** + * @return int + */ + public function getEsdArticle() + { + return $this->esdArticle; + } + + /** + * @param string $lastViewPort + */ + public function setLastViewPort($lastViewPort) + { + $this->lastViewPort = $lastViewPort; + } + + /** + * @return string + */ + public function getLastViewPort() + { + return $this->lastViewPort; + } + + /** + * @param int $mode + */ + public function setMode($mode) + { + $this->mode = $mode; + } + + /** + * @return int + */ + public function getMode() + { + return $this->mode; + } + + /** + * @param string $partnerId + */ + public function setPartnerId($partnerId) + { + $this->partnerId = $partnerId; + } + + /** + * @return string + */ + public function getPartnerId() + { + return $this->partnerId; + } + + /** + * @param float $price + */ + public function setPrice($price) + { + $this->price = $price; + } + + /** + * @return float + */ + public function getPrice() + { + return $this->price; + } + + /** + * @param int $quantity + */ + public function setQuantity($quantity) + { + $this->quantity = $quantity; + } + + /** + * @return int + */ + public function getQuantity() + { + return $this->quantity; + } + + /** + * @param string $sessionId + */ + public function setSessionId($sessionId) + { + $this->sessionId = $sessionId; + } + + /** + * @return string + */ + public function getSessionId() + { + return $this->sessionId; + } + + /** + * @param int $shippingFree + */ + public function setShippingFree($shippingFree) + { + $this->shippingFree = $shippingFree; + } + + /** + * @return int + */ + public function getShippingFree() + { + return $this->shippingFree; + } + + /** + * @param string $userAgent + */ + public function setUserAgent($userAgent) + { + $this->userAgent = $userAgent; + } + + /** + * @return string + */ + public function getUserAgent() + { + return $this->userAgent; + } + + /** + * @return \DateTime + */ + public function getDate() + { + return $this->date; + } + + /** + * @param \DateTime $date + */ + public function setDate($date) + { + $this->date = $date; + } + + /** + * @return float + */ + public function getNetPrice() + { + return $this->netPrice; + } + + /** + * @param float $netPrice + */ + public function setNetPrice($netPrice) + { + $this->netPrice = $netPrice; + } + + /** + * @return string + */ + public function getOrderNumber() + { + return $this->orderNumber; + } + + /** + * @param string $orderNumber + */ + public function setOrderNumber($orderNumber) + { + $this->orderNumber = $orderNumber; + } + + /** + * @param int $articleId + */ + public function setArticleId($articleId) + { + $this->articleId = $articleId; + } + + /** + * @return int + */ + public function getArticleId() + { + return $this->articleId; + } + + /** + * @param int $customerId + */ + public function setCustomerId($customerId) + { + $this->customerId = $customerId; + } + + /** + * @return int + */ + public function getCustomerId() + { + return $this->customerId; + } + + /** + * @return float + */ + public function getTaxRate() + { + return $this->taxRate; + } + + /** + * @param float $taxRate + */ + public function setTaxRate($taxRate) + { + $this->taxRate = $taxRate; + } +} diff --git a/Models/Quote/Repository.php b/Models/Quote/Repository.php new file mode 100644 index 0000000..a34ca3b --- /dev/null +++ b/Models/Quote/Repository.php @@ -0,0 +1,40 @@ + + * The quote model repository is responsible to load all quote data. + */ +class Repository extends ModelRepository +{ + /** + * Loads all quotes. The $filter parameter can + * be used to narrow the selection down to a category id. + * + * @param null $filter + * + * @return \Doctrine\ORM\Query + */ + public function getQuotes($filter = null) + { + $builder = $this->getQuoteMainQuery($filter); + + return $builder->getQuery(); + } + + /** + * @param null $filter + * + * @return \Doctrine\ORM\Query + */ + public function getQuoteMainQuery($filter = null) + { + $builder = $this->createQueryBuilder('quote'); + return $builder; + } +} \ No newline at end of file diff --git a/Models/Subscriber/Repository.php b/Models/Subscriber/Repository.php new file mode 100644 index 0000000..6363313 --- /dev/null +++ b/Models/Subscriber/Repository.php @@ -0,0 +1,40 @@ + + * The subscriber model repository is responsible to load all subscriber data. + */ +class Repository extends ModelRepository +{ + /** + * Loads all subscribers. The $filter parameter can + * be used to narrow the selection down to a category id. + * + * @param null $filter + * + * @return \Doctrine\ORM\Query + */ + public function getSubscribers($filter = null) + { + $builder = $this->getSubscriberMainQuery($filter); + + return $builder->getQuery(); + } + + /** + * @param null $filter + * + * @return \Doctrine\ORM\Query + */ + public function getSubscriberMainQuery($filter = null) + { + $builder = $this->createQueryBuilder('subscriber'); + return $builder; + } +} \ No newline at end of file diff --git a/Models/Subscriber/Subscriber.php b/Models/Subscriber/Subscriber.php new file mode 100644 index 0000000..f296c26 --- /dev/null +++ b/Models/Subscriber/Subscriber.php @@ -0,0 +1,142 @@ +id; + } + + /** + * @return string + */ + public function getEmail() + { + return $this->email; + } + + /** + * @return int + */ + public function getGroupID() + { + return $this->groupID; + } + + /** + * @param $email string + */ + public function setEmail($email) + { + $this->email = $email; + } +} diff --git a/Resources/services.xml b/Resources/services.xml new file mode 100644 index 0000000..eddde08 --- /dev/null +++ b/Resources/services.xml @@ -0,0 +1,10 @@ + + + + + + + + diff --git a/plugin.xml b/plugin.xml new file mode 100644 index 0000000..3e3c5a2 --- /dev/null +++ b/plugin.xml @@ -0,0 +1,8 @@ + + + + 1.0.0 + MailCampaigns + +