Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions Config/config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8" ?>

<config xmlns="http://thelia.net/schema/dic/config"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://thelia.net/schema/dic/config http://thelia.net/schema/dic/config/thelia-1.0.xsd">

<forms>
<form name="replaced_order_module_form" class="ReplacedOrderModule\Form\ReplacedOrderModuleForm" />
</forms>

<services>
<service id="action.replace.order.module.service" class="ReplacedOrderModule\Service\ReplacedOrderModuleService">
<argument type="service" id="event_dispatcher"/>
</service>
</services>

<hooks>
<hook id="replace.module.configuration.hook" class="ReplacedOrderModule\Hook\ConfigurationHook">
<tag name="hook.event_listener" event="module.configuration" type="back" method="onModuleConfiguration" />
</hook>
</hooks>
</config>
28 changes: 28 additions & 0 deletions Config/module.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="http://thelia.net/schema/dic/module"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://thelia.net/schema/dic/module http://thelia.net/schema/dic/module/module-2_2.xsd">
<fullnamespace>ReplacedOrderModule\ReplacedOrderModule</fullnamespace>
<descriptive locale="en_US">
<title>Replaced Payment and Delivery Module in Order </title>
</descriptive>
<descriptive locale="fr_FR">
<title>Remplacement des Modules de Livraison et de Payments des Commandes </title>
</descriptive>
<languages>
<language>en_US</language>
<language>fr_FR</language>
</languages>
<version>1.0.0</version>
<authors>
<author>
<name>thomas da silva mendonca</name>
<email>tdasilva@openstudio</email>
</author>
</authors>
<type>classic</type>
<thelia>2.4.4</thelia>
<stability>other</stability>
<mandatory>0</mandatory>
<hidden>0</hidden>
</module>
10 changes: 10 additions & 0 deletions Config/routing.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8" ?>

<routes xmlns="http://symfony.com/schema/routing"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">

<route id="replaced_order_module" path="/admin/module/ReplacedOrderModule/replacedordermodule">
<default key="_controller">ReplacedOrderModule\Controller\ReplacedOrderModule::replaceOrderModule</default>
</route>
</routes>
12 changes: 12 additions & 0 deletions Config/schema.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<database defaultIdMethod="native" name="thelia"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../vendor/thelia/propel/resources/xsd/database.xsd" >

<table name="replaced_module" namespace="ReplacedOrderModule\Model">
<column autoIncrement="true" name="id" primaryKey="true" required="true" type="INTEGER" />
<column name="code" size="255" type="VARCHAR" />
<column name="title" size="255" type="VARCHAR" />
<column name="created_at" type="TIMESTAMP"/>
</table>
</database>
2 changes: 2 additions & 0 deletions Config/sqldb.map
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Sqlfile -> Database map
thelia.sql=thelia
22 changes: 22 additions & 0 deletions Config/thelia.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

# This is a fix for InnoDB in MySQL >= 4.1.x
# It "suspends judgement" for fkey relationships until are tables are set.
SET FOREIGN_KEY_CHECKS = 0;

-- ---------------------------------------------------------------------
-- replaced_module
-- ---------------------------------------------------------------------

DROP TABLE IF EXISTS `replaced_module`;

CREATE TABLE `replaced_module`
(
`id` INTEGER NOT NULL AUTO_INCREMENT,
`code` VARCHAR(255),
`title` VARCHAR(255),
`created_at` DATETIME,
PRIMARY KEY (`id`)
) ENGINE=InnoDB;

# This restores the fkey checks, after having unset them earlier
SET FOREIGN_KEY_CHECKS = 1;
44 changes: 44 additions & 0 deletions Controller/ReplacedOrderModule.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace ReplacedOrderModule\Controller;

use ReplacedOrderModule\Service\ReplacedOrderModuleService;
use Thelia\Controller\Admin\BaseAdminController;
use Thelia\Core\Security\AccessManager;
use Thelia\Core\Security\Resource\AdminResources;

class ReplacedOrderModule extends BaseAdminController
{
public function replaceOrderModule()
{
if (null !== $response = $this->checkAuth([AdminResources::MODULE], ["CustomerTools"], AccessManager::UPDATE)) {
return $response;
}

$form = $this->createForm('replaced_order_module_form');

try {
$data = $this->validateForm($form)->getData();

/** @var ReplacedOrderModuleService $replacedOrderModuleService */
$replacedOrderModuleService = $this->getContainer()->get('action.replace.order.module.service');

$module = $replacedOrderModuleService->getModule($data["modules"]);

$replacedOrderModuleService->saveModule($module);
$replacedOrderModuleService->updateOrder($module);

return $this->generateSuccessRedirect($form);
} catch (\Exception $e) {
$error_message = $e->getMessage();
}

$form->setErrorMessage($error_message);

$this->getParserContext()
->addForm($form)
->setGeneralError($error_message);

return $this->generateErrorRedirect($form);
}
}
52 changes: 52 additions & 0 deletions Form/ReplacedOrderModuleForm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

namespace ReplacedOrderModule\Form;

use Propel\Runtime\Exception\PropelException;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Thelia\Core\Translation\Translator;
use Thelia\Log\Tlog;
use Thelia\Model\Lang;
use Thelia\Model\ModuleQuery;
use TheliaEmailManager\Form\BaseForm;

class ReplacedOrderModuleForm extends BaseForm
{

protected function buildForm()
{
$this->initModulesList();
$this->formBuilder
->add('modules',
ChoiceType::class,
[
'required' => true,
'choices' => $this->initModulesList(),
'label' => Translator::getInstance()->trans('Replaced Module'),
]);
}

public function getName(){
return 'replaced_order_form';
}

private function initModulesList(){
$choices = [];

$modules = ModuleQuery::create()
->filterByType(2)
->_or()
->filterByType(3)
->find();

foreach ($modules as $module) {
try {
$choices[$module->getId()] = $module->getCode();
} catch (PropelException $e) {
Tlog::getInstance()->error($e->getMessage());
}
}
return $choices;
}
}
14 changes: 14 additions & 0 deletions Hook/ConfigurationHook.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace ReplacedOrderModule\Hook;

use Thelia\Core\Event\Hook\HookRenderEvent;
use Thelia\Core\Hook\BaseHook;

class ConfigurationHook extends BaseHook
{
public function onModuleConfiguration(HookRenderEvent $event)
{
$event->add(($this->render("module_configuration.html")));
}
}
6 changes: 6 additions & 0 deletions I18n/backOffice/default/fr_FR.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php

return array(
'Replace Module' => 'Remplacer le Module',
'replacedordermodule.title' => 'Replaced Order Module',
);
4 changes: 4 additions & 0 deletions I18n/en_US.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?php
return array(
// 'an english string' => 'The displayed english string',
);
5 changes: 5 additions & 0 deletions I18n/fr_FR.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

return array(
'Replaced Module' => 'Module à Remplacer',
);
20 changes: 20 additions & 0 deletions Model/ReplacedModule.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace ReplacedOrderModule\Model;

use ReplacedOrderModule\Model\Base\ReplacedModule as BaseReplacedModule;

/**
* Skeleton subclass for representing a row from the 'replaced_module' table.
*
*
*
* You should add additional methods to this class to meet the
* application requirements. This class will only be generated as
* long as it does not already exist in the output directory.
*
*/
class ReplacedModule extends BaseReplacedModule
{

}
20 changes: 20 additions & 0 deletions Model/ReplacedModuleQuery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace ReplacedOrderModule\Model;

use ReplacedOrderModule\Model\Base\ReplacedModuleQuery as BaseReplacedModuleQuery;

/**
* Skeleton subclass for performing query and update operations on the 'replaced_module' table.
*
*
*
* You should add additional methods to this class to meet the
* application requirements. This class will only be generated as
* long as it does not already exist in the output directory.
*
*/
class ReplacedModuleQuery extends BaseReplacedModuleQuery
{

}
25 changes: 24 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,24 @@
# ReplacedOrderModule
# Replaced Order Module

This module allows to replace payment module id or delivery module id from order.

So you can delete the module after.

## Installation

### Manually

* Copy the module into ```<thelia_root>/local/modules/``` directory and be sure that the name of the module is ReplacedOrderModule.
* Activate it in your thelia administration panel

### Composer

Add it in your main thelia composer.json file

```
composer require thelia/replaced-order-module-module:~1.0
```

## Usage

This module add a selector in the config where you can choose the delivery or payment module you want to replace
28 changes: 28 additions & 0 deletions ReplacedOrderModule.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/

namespace ReplacedOrderModule;

use Thelia\Module\BaseModule;

class ReplacedOrderModule extends BaseModule
{
/** @var string */
const DOMAIN_NAME = 'replacedordermodule';

/*
* You may now override BaseModuleInterface methods, such as:
* install, destroy, preActivation, postActivation, preDeactivation, postDeactivation
*
* Have fun !
*/
}
Loading