PHP code example of shopsys / plugin-interface
1. Go to this page and download the library: Download shopsys/plugin-interface library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
shopsys / plugin-interface example snippets
// vendor/your-bundle-name-bundle/src/YourBundleNameBundle.php
// ...
/**
* @inheritdoc
*/
public function build(ContainerBuilder $container) {
parent::build($container);
$container->addCompilerPass(
DoctrineOrmMappingsPass::createAnnotationMappingDriver(
[$this->getNamespace() . '\Entity'],
[$this->getPath() . '/Entity']
)
);
}
// ...
// ...
class AcmeProductCrudExtension implements PluginCrudExtensionInterface
{
private $acmeProductFacade;
public function __construct(AcmeProductFacade $acmeProductFacade) {
$this->acmeProductFacade = $acmeProductFacade;
}
public function getFormTypeClass()
{
return AcmeProductFormType::class;
}
public function getFormLabel()
{
return 'ACME data';
}
public function getData($productId)
{
$acmeProduct = $this->acmeProductFacade->findByProductId($productId);
$pluginData = [
'attribute' => $acmeProduct->getAttribute(),
];
return $pluginData;
}
public function saveData($productId, $data)
{
$acmeProductData = new AcmeProductData();
$acmeProductData->attribute = $data['attribute'];
$this->acmeProductFacade->save($productId, $acmeProductData);
}
public function removeData($productId)
{
$this->acmeProductFacade->remove($productId);
}
}
class AcmeDataFixture implements PluginDataFixtureInterface
{
private $acmeProductFacade;
public function __construct(AcmeProductFacade $acmeProductFacade) {
$this->acmeProductFacade = $acmeProductFacade;
}
public function load() {
$firstAcmeProductData = new AcmeProductData();
$firstAcmeProductData->enableWeightCalculation = true;
$firstAcmeProductData->weight = 42;
$firstAcmeProductData->domainId = 1;
$this->acmeProductFacade->save($firstAcmeProductData);
$secondAcmeProductData = new AcmeProductData();
$secondAcmeProductData->enableWeightCalculation = false;
$secondAcmeProductData->weight = null;
$secondAcmeProductData->domainId = 2;
$this->acmeProductFacade->save($secondAcmeProductData);
}
}
// ...
class AcmeDataDownloadCronModule implements SimpleCronModuleInterface
{
/**
* @var \Symfony\Bridge\Monolog\Logger
*/
private $logger;
public function setLogger(Logger $logger)
{
$this->logger = $logger;
}
public function run()
{
$data = $this->downloadData();
$this->saveData($data);
$this->logger->info(sprintf('Downloaded %d new records.', count($data)));
}
// ...
}