-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added functionality to mark payment methods as harmless
- Loading branch information
Showing
8 changed files
with
363 additions
and
55 deletions.
There are no files selected for viewing
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,113 @@ | ||
<?php | ||
|
||
namespace LxRmp\Attribute; | ||
|
||
use LxRmp\Util\AbstractHandler; | ||
use Doctrine\ORM\NoResultException; | ||
use Shopware\Bundle\AttributeBundle\Service\CrudService; | ||
|
||
abstract class AbstractAttribute extends AbstractHandler | ||
{ | ||
/** | ||
* CrudService | ||
* | ||
* @var CrudService | ||
*/ | ||
private $crudService; | ||
|
||
/** | ||
* Name of the database table | ||
* | ||
* @return string | ||
*/ | ||
abstract protected function getTableName(); | ||
|
||
/** | ||
* List of fields | ||
* | ||
* @return array | ||
*/ | ||
abstract protected function getFields(); | ||
|
||
/** | ||
* Perform update for this plugin | ||
* | ||
* @param string $oldVersion Old Version | ||
*/ | ||
abstract protected function doUpdate($oldVersion); | ||
|
||
/** | ||
* @param \Enlight_Event_EventArgs $args | ||
* @return mixed|void | ||
*/ | ||
public function onPluginUpdate(\Enlight_Event_EventArgs $args) | ||
{ | ||
$oldVersion = $args->get('oldVersion'); | ||
$this->doUpdate($oldVersion); | ||
} | ||
|
||
/** | ||
* @param \Enlight_Event_EventArgs $args | ||
* @return mixed|void | ||
*/ | ||
public function onPluginUninstall(\Enlight_Event_EventArgs $args){} | ||
|
||
/** | ||
* @param $name | ||
* @throws \Exception | ||
*/ | ||
protected function addField($name):void | ||
{ | ||
$this->updateField($name); | ||
} | ||
|
||
/** | ||
* @param $name | ||
* @throws \Exception | ||
*/ | ||
protected function updateField($name):void | ||
{ | ||
$def = $this->getDefinition($name); | ||
$service = $this->getCrudService(); | ||
$def[2]['displayInBackend'] = true; | ||
$service->update($this->getTableName(), $def[0], $def[1], $def[2]); | ||
} | ||
|
||
/** | ||
* @param $name | ||
* @throws \Exception | ||
*/ | ||
protected function deleteField($name):void | ||
{ | ||
$service = $this->getCrudService(); | ||
if ($service->get($this->getTableName(), $name)) { | ||
$service->delete($this->getTableName(), $name); | ||
} | ||
} | ||
|
||
/** | ||
* @param $name | ||
* @return mixed | ||
* @throws NoResultException | ||
*/ | ||
protected function getDefinition($name) | ||
{ | ||
foreach ($this->getFields() as $def) { | ||
if ($def[0] == $name) { | ||
return $def; | ||
} | ||
} | ||
throw new NoResultException(); | ||
} | ||
|
||
/** | ||
* @return CrudService | ||
*/ | ||
protected function getCrudService():CrudService | ||
{ | ||
if (!$this->crudService instanceof CrudService) { | ||
$this->crudService = Shopware()->Container()->get('shopware_attribute.crud_service'); | ||
} | ||
return $this->crudService; | ||
} | ||
} |
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,50 @@ | ||
<?php | ||
|
||
namespace LxRmp\Attribute; | ||
|
||
use Shopware\Bundle\AttributeBundle\Service\TypeMapping; | ||
|
||
class Payment extends AbstractAttribute | ||
{ | ||
|
||
/** | ||
* Name of the database table | ||
* | ||
* @return string | ||
*/ | ||
protected function getTableName():string | ||
{ | ||
return 's_core_paymentmeans_attributes'; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
protected function getFields():array | ||
{ | ||
$fields = array(); | ||
|
||
$fields[] = [ | ||
'harmless', | ||
TypeMapping::TYPE_BOOLEAN, | ||
[ | ||
'label' => 'Unbedenklich', | ||
'position' => 10 | ||
] | ||
]; | ||
return $fields; | ||
} | ||
|
||
/** | ||
* @param string $oldVersion | ||
*/ | ||
protected function doUpdate($oldVersion):void | ||
{ | ||
if(version_compare('1.0.3', $oldVersion, '>')){ | ||
try{ | ||
$this->addField('harmless'); | ||
}catch (\Exception $exception){ | ||
} | ||
} | ||
} | ||
} |
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
Oops, something went wrong.