Thanks to visit codestin.com
Credit goes to github.com

Skip to content

SW-1 Initial commit #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 10, 2025
Merged
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
Binary file added .DS_Store
Binary file not shown.
32 changes: 32 additions & 0 deletions .github/workflows/code-style-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Code Style & Tests

on:
push:
branches:
- '**'

jobs:
code-style:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
tools: composer

- name: Install dependencies
run: composer install --no-interaction --no-progress

- name: Run PHPUnit tests
run: vendor/bin/phpunit --configuration phpunit.xml.dist

- name: Run Code Style Checks
run: |
vendor/bin/php-cs-fixer fix --allow-risky yes --dry-run --diff
vendor/bin/phpcs
vendor/bin/phpstan
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/vendor/
/composer.lock
/.phpcs-cache
/.phpcs.cache
/.phpunit.result.cache
/node_modules/
31 changes: 31 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

$finder = (new PhpCsFixer\Finder())
->in(__DIR__ . '/src')
->exclude('var');

$header = <<<EOF
@copyright © SWCOMMERCE

Contact SWCommerce:
E-mail: [email protected]
https://swcommerce.com/
EOF;

return (new PhpCsFixer\Config())
->setRules([
'@Symfony' => true,
'@Symfony:risky' => true,
'@PHP82Migration' => true,
'array_syntax' => ['syntax' => 'short'],
'blank_line_before_statement' => true,
'concat_space' => ['spacing' => 'one'],
'header_comment' => [
'header' => $header,
'comment_type' => 'PHPDoc',
'location' => 'after_open',
'separate' => 'both',
],
])
->setFinder($finder);

4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
cs:
vendor/bin/php-cs-fixer fix --allow-risky yes
vendor/bin/phpcs
vendor/bin/phpstan
24 changes: 24 additions & 0 deletions README.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# JavaScript and CSS Injector for Shopware 6

This plugin for [Shopware 6](https://www.shopware.com) allows you to manage custom JavaScript and CSS/SCSS snippets via a backend interface. It's designed to make it easy to inject code into your storefront without modifying the theme files directly.

## Features

- Create unlimited containers for JavaScript and/or CSS code
- Assign code snippets to specific sales channels
- Define which pages should include each snippet
- Set a date and time range for when each snippet is active
- Available in English and German

## Requirements

- Shopware version >= 6.6

## Installation

1. Clone this repository into a folder named **SwCommerceJavascriptCSSInjector** inside the **custom/plugins** directory of your Shopware installation.
2. Install and activate the plugin using the Plugin Manager in the Shopware administration panel.


## Usage
Go to Content -> Additional js/css code snippets tab and start creating new code snippets
60 changes: 60 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"name": "swcommerce/javascript-css-injector",
"description": "SwCommerce JavaScript/CSS Injector",
"version": "1.0.0",
"type": "shopware-platform-plugin",
"license": "proprietary",
"require": {
"shopware/core": "~v6.6",
"shopware/administration": "*",
"shopware/storefront": "*"
},
"authors": [
{
"name": "swcommerce.com",
"homepage": "https://swcommerce.com",
"role": "Manufacturer"
}
],
"extra": {
"shopware-plugin-class": "SwCommerce\\JavascriptCSSInjector\\SwCommerceJavascriptCSSInjector",
"copyright": "(c) by swcommerce.com",
"label": {
"de-DE": "SwCommerce JS/CSS Injector",
"en-GB": "SwCommerce JS/CSS Injector"
},
"description": {
"de-DE": "Container Manager zum einfachen Hinzufügen von benutzerdefiniertem JavaScript und/oder SCSS zur Theme-Kompilierung.",
"en-GB": "Container manager to easily add custom JavaScript and/or SCSS to the theme compilation."
},
"manufacturerLink": {
"de-DE": "https://swcommerce.com",
"en-GB": "https://swcommerce.com"
},
"supportLink": {
"de-DE": "https://swcommerce.com/support",
"en-GB": "https://swcommerce.com/support"
}
},
"autoload": {
"psr-4": {
"SwCommerce\\JavascriptCSSInjector\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"SwCommerce\\JavascriptCSSInjector\\Test\\": "tests/"
}
},
"require-dev": {
"squizlabs/php_codesniffer": "^3.12",
"phpstan/phpstan": "^2.1",
"friendsofphp/php-cs-fixer": "^3.75",
"phpunit/phpunit": "^12.1"
},
"config": {
"allow-plugins": {
"symfony/runtime": false
}
}
}
15 changes: 15 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>

<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd">

<arg name="basepath" value="."/>
<arg name="cache" value=".phpcs-cache"/>
<arg name="colors"/>
<arg name="extensions" value="php"/>

<rule ref="PSR12"/>

<file>src/</file>

</ruleset>
4 changes: 4 additions & 0 deletions phpstan.dist.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
parameters:
level: 8
paths:
- src/
11 changes: 11 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/12.1/phpunit.xsd"
bootstrap="vendor/autoload.php"
>
<testsuites>
<testsuite name="Application Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
</phpunit>
Binary file added src/.DS_Store
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

/**
* @copyright © SWCOMMERCE
*
* Contact SWCommerce:
* E-mail: [email protected]
* https://swcommerce.com/
*/

declare(strict_types=1);

namespace SwCommerce\JavascriptCSSInjector\Core\Content\CodeSnippet\Aggregate;

use Shopware\Core\Framework\DataAbstractionLayer\Field\FkField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\PrimaryKey;
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\Required;
use Shopware\Core\Framework\DataAbstractionLayer\Field\ManyToOneAssociationField;
use Shopware\Core\Framework\DataAbstractionLayer\FieldCollection;
use Shopware\Core\Framework\DataAbstractionLayer\MappingEntityDefinition;
use Shopware\Core\System\SalesChannel\SalesChannelDefinition;
use SwCommerce\JavascriptCSSInjector\Core\Content\CodeSnippet\CodeSnippetDefinition;

class CodeSnippetSalesChannelDefinition extends MappingEntityDefinition
{
public const ENTITY_NAME = 'sw_commerce_code_snippet_sales_channel';

public function getEntityName(): string
{
return self::ENTITY_NAME;
}

protected function defineFields(): FieldCollection
{
return new FieldCollection([
(new FkField(
'sw_commerce_code_snippet_id',
'swCommerceJavascriptCssInjectorId',
CodeSnippetDefinition::class
))->addFlags(
new PrimaryKey(),
new Required()
),

(new FkField(
'sales_channel_id',
'salesChannelId',
SalesChannelDefinition::class
))->addFlags(
new PrimaryKey(),
new Required()
),

new ManyToOneAssociationField(
'swCommerceJavascriptCssInjector',
'sw_commerce_code_snippet_id',
CodeSnippetDefinition::class
),

new ManyToOneAssociationField(
'salesChannel',
'sales_channel_id',
SalesChannelDefinition::class
),
]);
}
}
26 changes: 26 additions & 0 deletions src/Core/Content/CodeSnippet/CodeSnippetCollection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

/**
* @copyright © SWCOMMERCE
*
* Contact SWCommerce:
* E-mail: [email protected]
* https://swcommerce.com/
*/

declare(strict_types=1);

namespace SwCommerce\JavascriptCSSInjector\Core\Content\CodeSnippet;

use Shopware\Core\Framework\DataAbstractionLayer\EntityCollection;

/**
* @extends EntityCollection<CodeSnippetEntity>
*/
class CodeSnippetCollection extends EntityCollection
{
protected function getExpectedClass(): string
{
return CodeSnippetEntity::class;
}
}
Loading