Initial commit

This commit is contained in:
2020-01-27 08:56:08 +01:00
commit b7525048d6
27129 changed files with 3409855 additions and 0 deletions

View File

@@ -0,0 +1,209 @@
<?php
namespace WithdrawalInStore\Controller\Admin;
use WithdrawalInStore\Form\ExportOrder;
use WithdrawalInStore\Format\CSV;
use WithdrawalInStore\Format\CSVLine;
use WithdrawalInStore\WithdrawalInStore;
use Propel\Runtime\ActiveQuery\Criteria;
use Symfony\Component\Config\Definition\Exception\Exception;
use Thelia\Controller\Admin\BaseAdminController;
use Thelia\Core\Event\Order\OrderEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Core\HttpFoundation\Response;
use Thelia\Core\Security\AccessManager;
use Thelia\Core\Security\Resource\AdminResources;
use Thelia\Model\ConfigQuery;
use Thelia\Model\CountryQuery;
use Thelia\Model\CustomerTitleI18nQuery;
use Thelia\Model\OrderAddressQuery;
use Thelia\Model\OrderQuery;
use Thelia\Model\OrderStatus;
use Thelia\Model\OrderStatusQuery;
class Export extends BaseAdminController
{
const CSV_SEPARATOR = ";";
const DEFAULT_PHONE = "0100000000";
const DEFAULT_CELLPHONE = "0600000000";
public function export()
{
if (null !== $response = $this->checkAuth(array(AdminResources::MODULE), array('WithdrawalInStore'), AccessManager::UPDATE)) {
return $response;
}
$csv = new CSV(self::CSV_SEPARATOR);
try {
$form = new ExportOrder($this->getRequest());
$vform = $this->validateForm($form);
// Check status_id
$status_id = $vform->get("new_status_id")->getData();
if (!preg_match("#^nochange|processing|sent$#", $status_id)) {
throw new Exception("Bad value for new_status_id field");
}
$status = OrderStatusQuery::create()
->filterByCode(
array(
OrderStatus::CODE_PAID,
OrderStatus::CODE_PROCESSING,
OrderStatus::CODE_SENT
),
Criteria::IN
)
->find()
->toArray("code")
;
$query = OrderQuery::create()
->filterByDeliveryModuleId(WithdrawalInStore::getModuleId())
->filterByStatusId(
array(
$status[OrderStatus::CODE_PAID]['Id'],
$status[OrderStatus::CODE_PROCESSING]['Id']),
Criteria::IN
)
->find();
// check form && exec csv
/** @var \Thelia\Model\Order $order */
foreach ($query as $order) {
$value = $vform->get('order_'.$order->getId())->getData();
// If checkbox is checked
if ($value) {
/**
* Retrieve user with the order
*/
$customer = $order->getCustomer();
/**
* Retrieve address with the order
*/
$address = OrderAddressQuery::create()
->findPk($order->getDeliveryOrderAddressId());
if ($address === null) {
throw new Exception("Could not find the order's invoice address");
}
/**
* Retrieve country with the address
*/
$country = CountryQuery::create()
->findPk($address->getCountryId());
if ($country === null) {
throw new Exception("Could not find the order's country");
}
/**
* Retrieve Title
*/
$title = CustomerTitleI18nQuery::create()
->filterById($customer->getTitleId())
->findOneByLocale(
$this->getSession()
->getAdminEditionLang()
->getLocale()
);
/**
* Get user's phone & cellphone
* First get invoice address phone,
* If empty, try to get default address' phone.
* If still empty, set default value
*/
$phone = $address->getPhone();
if (empty($phone)) {
$phone = $customer->getDefaultAddress()->getPhone();
if (empty($phone)) {
$phone = self::DEFAULT_PHONE;
}
}
/**
* Cellp
*/
$cellphone = $customer->getDefaultAddress()->getCellphone();
if (empty($cellphone)) {
$cellphone = self::DEFAULT_CELLPHONE;
}
/**
* Compute package weight
*/
$weight = 0;
/** @var \Thelia\Model\OrderProduct $product */
foreach ($order->getOrderProducts() as $product) {
$weight+=(double) $product->getWeight();
}
/**
* Get store's name
*/
$store_name = ConfigQuery::read("store_name");
/**
* Write CSV line
*/
$csv->addLine(
CSVLine::create(
array(
$address->getFirstname(),
$address->getLastname(),
$address->getCompany(),
$address->getAddress1(),
$address->getAddress2(),
$address->getAddress3(),
$address->getZipcode(),
$address->getCity(),
$country->getIsoalpha2(),
$phone,
$cellphone,
$order->getRef(),
$title->getShort(),
$customer->getEmail(),
$weight,
$store_name,
)
)
);
/**
* Then update order's status if necessary
*/
if ($status_id == "processing") {
$event = new OrderEvent($order);
$event->setStatus($status[OrderStatus::CODE_PROCESSING]['Id']);
$this->dispatch(TheliaEvents::ORDER_UPDATE_STATUS, $event);
} elseif ($status_id == "sent") {
$event = new OrderEvent($order);
$event->setStatus($status[OrderStatus::CODE_SENT]['Id']);
$this->dispatch(TheliaEvents::ORDER_UPDATE_STATUS, $event);
}
}
}
} catch (\Exception $e) {
return Response::create($e->getMessage(), 500);
}
return Response::create(
utf8_decode($csv->parse()),
200,
array(
"Content-Encoding"=>"ISO-8889-1",
"Content-Type"=>"application/csv-tab-delimited-table",
"Content-disposition"=>"filename=export.csv"
)
);
}
}

View File

@@ -0,0 +1,305 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace WithdrawalInStore\Controller\Admin;
use WithdrawalInStore\Event\WithdrawalInStoreDeleteEvent;
use WithdrawalInStore\Event\WithdrawalInStoreEvents;
use WithdrawalInStore\Event\WithdrawalInStoreUpdateEvent;
use WithdrawalInStore\Form\WithdrawalInStoreRuleCreationForm;
use WithdrawalInStore\Form\WithdrawalInStoreRuleModificationForm;
use WithdrawalInStore\Model\WithdrawalInStoreQuery;
use Propel\Runtime\Exception\PropelException;
use Thelia\Controller\Admin\AbstractCrudController;
use Thelia\Controller\Admin\unknown;
use Thelia\Core\Security\AccessManager;
use Thelia\Core\Security\Resource\AdminResources;
use Thelia\Form\Exception\FormValidationException;
/**
* Class WithdrawalInStoreController
* @package WithdrawalInStore\Controller\Admin
* @author Michaël Espeche <mespeche@openstudio.fr>
*/
class WithdrawalInStoreController extends AbstractCrudController
{
public $areaId;
public function __construct()
{
parent::__construct(
'WithdrawalInStore',
'manual',
'WithdrawalInStore_order',
AdminResources::MODULE,
WithdrawalInStoreEvents::WITHDRAWAL_IN_STORE_RULE_CREATE,
WithdrawalInStoreUpdateEvent::WITHDRAWAL_IN_STORE_RULE_UPDATE,
WithdrawalInStoreDeleteEvent::WITHDRAWAL_IN_STORE_RULE_DELETE,
null,
null,
'WithdrawalInStore'
);
}
public function createRuleAction()
{
if (null !== $response = $this->checkAuth(array(), array('WithdrawalInStore'), AccessManager::CREATE)) {
return $response;
}
$ruleCreationForm = new WithdrawalInStoreRuleCreationForm($this->getRequest());
$message = false;
try {
$form = $this->validateForm($ruleCreationForm);
$event = $this->createEventInstance($form->getData());
$this->areaId = $form->get('area')->getData();
if(null === $this->getExistingObject()){
$this->dispatch(WithdrawalInStoreEvents::WITHDRAWAL_IN_STORE_RULE_CREATE, $event);
return $this->generateSuccessRedirect($ruleCreationForm);
}
else{
throw new \Exception("A rule with this area already exist");
}
} catch (FormValidationException $e) {
$message = sprintf("Please check your input: %s", $e->getMessage());
} catch (PropelException $e) {
$message = $e->getMessage();
} catch (\Exception $e) {
$message = sprintf("Sorry, an error occured: %s", $e->getMessage()." ".$e->getFile());
}
if ($message !== false) {
\Thelia\Log\Tlog::getInstance()->error(
sprintf("Error during free shipping rule creation process : %s.", $message)
);
$ruleCreationForm->setErrorMessage($message);
$this->getParserContext()
->addForm($ruleCreationForm)
->setGeneralError($message)
;
}
// Redirect
return $this->generateRedirectFromRoute(
'admin.module.configure', array(), array('module_code' => 'WithdrawalInStore')
);
}
/**
* @param $data
* @return \WithdrawalInStore\Event\WithdrawalInStoreEvents
*/
private function createEventInstance($data)
{
$WithdrawalInStoreEvent = new WithdrawalInStoreEvents(
$data['amount'],
$data['area']
);
return $WithdrawalInStoreEvent;
}
/**
* Return the creation form for this object
*/
protected function getCreationForm()
{
return new WithdrawalInStoreRuleCreationForm($this->getRequest());
}
/**
* Return the update form for this object
*/
protected function getUpdateForm()
{
return new WithdrawalInStoreRuleModificationForm($this->getRequest());
}
/**
* Hydrate the update form for this object, before passing it to the update template
*
* @param unknown $object
*/
protected function hydrateObjectForm($object)
{
// Prepare the data that will hydrate the form
$data = array(
'id' => $object->getId(),
'area' => $object->getAreaId(),
'amount' => $object->getAmount()
);
// Setup the object form
return new WithdrawalInStoreRuleModificationForm($this->getRequest(), "form", $data);
}
/**
* Creates the creation event with the provided form data
*
* @param unknown $formData
*/
protected function getCreationEvent($formData)
{
return new WithdrawalInStoreEvents($formData['amount'], $formData['area']);
}
/**
* Creates the update event with the provided form data
*
* @param unknown $formData
*/
protected function getUpdateEvent($formData)
{
$WithdrawalInStoreUpdateEvent = new WithdrawalInStoreUpdateEvent($formData['id']);
$WithdrawalInStoreUpdateEvent
->setArea($formData['area'])
->setAmount($formData['amount']);
return $WithdrawalInStoreUpdateEvent;
}
/**
* Creates the delete event with the provided form data
*/
protected function getDeleteEvent()
{
return new WithdrawalInStoreDeleteEvent($this->getRequest()->get('rule_id'));
}
/**
* Return true if the event contains the object, e.g. the action has updated the object in the event.
*
* @param unknown $event
*/
protected function eventContainsObject($event)
{
return $event->hasRule();
}
/**
* Get the created object from an event.
*
* @param unknown $event
*/
protected function getObjectFromEvent($event)
{
return $event->getRule();
}
/**
* Load an existing object from the database
*/
protected function getExistingObject()
{
if(null !== $this->areaId){
return WithdrawalInStoreQuery::create()
->findOneByAreaId($this->areaId);
} else {
return WithdrawalInStoreQuery::create()
->findOneById($this->getRequest()->get('ruleId', 0));
}
}
/**
* Returns the object label form the object event (name, title, etc.)
*
* @param unknown $object
*/
protected function getObjectLabel($object)
{
// TODO: Implement getObjectLabel() method.
}
/**
* Returns the object ID from the object
*
* @param unknown $object
*/
protected function getObjectId($object)
{
// TODO: Implement getObjectId() method.
}
/**
* Render the main list template
*
* @param unknown $currentOrder , if any, null otherwise.
*/
protected function renderListTemplate($currentOrder)
{
// TODO: Implement renderListTemplate() method.
}
protected function getEditionArguments()
{
return array(
'ruleId' => $this->getRequest()->get('ruleId', 0)
);
}
/**
* Render the edition template
*/
protected function renderEditionTemplate()
{
// return $this->render('rule-edit', $this->getEditionArguments());
}
/**
* Redirect to the edition template
*/
protected function redirectToEditionTemplate()
{
$args = $this->getEditionArguments();
return $this->generateRedirectFromRoute("admin.WithdrawalInStore.rule.edit", [], ["ruleId" => $args['ruleId']]);
}
/**
* Redirect to the list template
*/
protected function redirectToListTemplate()
{
return $this->generateRedirectFromRoute("admin.module.configure", [], ["module_code" => "WithdrawalInStore"]);
}
protected function performAdditionalUpdateAction($updateEvent)
{
return $this->redirectToListTemplate();
}
}

View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8" ?>
<dwsync>
<file name="Export.php" server="51.254.220.106//web/" local="131379660587187500" remote="131383879200000000" />
<file name="WithdrawalInStoreController.php" server="51.254.220.106//web/" local="131379692017968750" remote="131383879200000000" />
<file name="Export.php" server="37.187.178.154//web/" local="131351946000000000" remote="131378968800000000" />
<file name="WithdrawalInStoreController.php" server="37.187.178.154//web/" local="131351946000000000" remote="131378968800000000" />
</dwsync>