Skip to content
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

Feature/upgrade to OroCommerce 6 #13

Merged
merged 7 commits into from
Jul 23, 2024
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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ This plugin allows you to save products as favorite in OroCommerce
## Requirements

| | Version |
| :--- | :--- |
| PHP | 8.2 |
| OroCommerce | 5.1.* |
| :--- |:--------|
| PHP | 8.3 |
| OroCommerce | 6.0.* |

## Installation

Expand Down
22 changes: 16 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
"exclude-from-classmap": ["/Tests/"]
},
"require": {
"php": "~8.2.0",
"oro/commerce": "5.1.*"
"php": "~8.3.0",
"oro/commerce": "6.0.1"
},
"repositories": {
"oro": {
Expand All @@ -31,11 +31,21 @@
"minimum-stability": "dev",
"prefer-stable": true,
"require-dev": {
"enlightn/security-checker": "^1.9",
"friendsofphp/php-cs-fixer": "^3.13",
"php-parallel-lint/php-parallel-lint": "^1.3",
"phpmd/phpmd": "^2.13",
"phpro/grumphp": "^1.15",
"phpspec/phpspec": "^6.1",
"phpstan/phpstan-symfony": "^1.2",
"php-parallel-lint/php-parallel-lint": "^1.3",
"friendsofphp/php-cs-fixer": "^3.4"
"phpspec/phpspec": "^7.2",
"phpstan/phpstan": "^1.5"
},
"config": {
"sort-packages": true,
"allow-plugins": {
"phpro/grumphp": true,
"php-http/discovery": true,
"symfony/flex": true,
"symfony/runtime": true
}
}
}
2 changes: 1 addition & 1 deletion grumphp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ grumphp:
securitychecker_enlightn: ~
phpcsfixer2:
allow_risky: true
config: 'ruleset/.php_cs'
config: 'ruleset/.php-cs-fixer.php'
22 changes: 22 additions & 0 deletions ruleset/.php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

$finder = PhpCsFixer\Finder::create()
->in([__DIR__.'/../src'])
->files()
->name('*.php');

$config = new PhpCsFixer\Config();
$config
->setRiskyAllowed(true)
->setRules([
'@PSR1' => true,
'@PSR2' => true,
'psr_autoloading' => true, // Updated from psr0 and psr4
'ordered_imports' => true,
'no_extra_blank_lines' => ['tokens' => ['use']], // Updated from no_extra_consecutive_blank_lines
'php_unit_namespaced' => ['target' => '6.0'],
'php_unit_expectation' => true,
])
->setFinder($finder);

return $config;

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

namespace Synolia\Bundle\FavoriteBundle\Controller\Frontend;

use Oro\Bundle\CustomerBundle\Entity\CustomerUser;
use Oro\Bundle\ProductBundle\Entity\Product;
use Oro\Bundle\SecurityBundle\Authentication\TokenAccessorInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Routing\Annotation\Route;
use Synolia\Bundle\FavoriteBundle\Handler\FavoriteButtonAjaxHandler;

#[Route('/ajax', options: ["expose"=>true])]

class FavoriteButtonAjaxController extends AbstractController
{
#[Route('/update/{id}', requirements: ['id' => '\d+'], name: 'synolia_favorite_button_ajax_update', methods: ['POST'])]
public function updateAction(
Product $product,
TokenAccessorInterface $tokenAccessor,
FavoriteButtonAjaxHandler $ajaxHandler
): JsonResponse {
/** @var CustomerUser $user */
$user = $tokenAccessor->getUser();

return new JsonResponse($ajaxHandler->update($product, $user));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,27 @@

namespace Synolia\Bundle\FavoriteBundle\Controller\Frontend;

use Oro\Bundle\LayoutBundle\Annotation\Layout;
use Oro\Bundle\LayoutBundle\Attribute\Layout;
use Oro\Bundle\SecurityBundle\Attribute\Acl;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
use Synolia\Bundle\FavoriteBundle\Entity\Favorite;

class FavoriteController extends AbstractController
{
/**
* @Route("/", name="synolia_favorite_view")
* @Layout(vars={"entity_class"})
*/
#[Route('/', name: 'synolia_favorite_index')]
#[Layout(vars: ['entity_class'])]
#[Acl(
id: 'synolia_favorite_frontend_view',
type: 'entity',
class: 'SynoliaFavoriteBundle\Entity\Favorite',
permission: 'VIEW',
group_name: 'commerce'
)]
public function indexAction(): array
{
$entityClass = Favorite::class;
return [
'entity_class' => $entityClass
];

return ['entity_class' => $entityClass];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class Configuration implements ConfigurationInterface
{
const ROOT_NODE = 'synolia_favorite';
const string ROOT_NODE = 'synolia_favorite';

public function getConfigTreeBuilder(): TreeBuilder
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ public function load(array $configs, ContainerBuilder $container): void

$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yml');
$loader->load('controller.yml');
$loader->load('controllers.yml');
$loader->load('event_listeners.yml');
$loader->load('block_types.yml');

$container->prependExtensionConfig($this->getAlias(), array_intersect_key($config, array_flip(['settings'])));
}
Expand Down
81 changes: 26 additions & 55 deletions src/Synolia/Bundle/FavoriteBundle/Entity/Favorite.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,87 +6,58 @@

use Doctrine\ORM\Mapping as ORM;
use Oro\Bundle\CustomerBundle\Entity\Ownership\FrontendCustomerUserAwareTrait;
use Oro\Bundle\EntityBundle\EntityProperty\CreatedAtAwareTrait;
use Oro\Bundle\EntityBundle\EntityProperty\DatesAwareInterface;
use Oro\Bundle\EntityBundle\EntityProperty\DatesAwareTrait;
use Oro\Bundle\EntityConfigBundle\Metadata\Annotation\Config;
use Oro\Bundle\EntityConfigBundle\Metadata\Attribute\Config;
use Oro\Bundle\EntityExtendBundle\Entity\ExtendEntityInterface;
use Oro\Bundle\EntityExtendBundle\Entity\ExtendEntityTrait;
use Oro\Bundle\OrganizationBundle\Entity\OrganizationAwareInterface;
use Oro\Bundle\OrganizationBundle\Entity\Ownership\OrganizationAwareTrait;
use Oro\Bundle\ProductBundle\Entity\Product;
use Synolia\Bundle\FavoriteBundle\Model\ExtendFavorite;

/**
* @ORM\Entity(repositoryClass="Synolia\Bundle\FavoriteBundle\Entity\Repository\FavoriteRepository")
* @ORM\Table(name="sy_favorite")

* @Config(
* defaultValues={
* "ownership"={
* "organization_field_name"="organization",
* "organization_column_name"="organization_id",
* "frontend_owner_type"="FRONTEND_CUSTOMER",
* "frontend_owner_field_name"="customerUser",
* "frontend_owner_column_name"="customer_user_id",
* },
* "security"={
* "type"="ACL",
* "group_name"="commerce"
* },
* }
* )
* @ORM\HasLifecycleCallbacks
*/
#[ORM\Entity(repositoryClass: 'Synolia\Bundle\FavoriteBundle\Entity\Repository\FavoriteRepository')]
#[ORM\Table(name: 'synolia_favorite')]
DiegoJaureRomero marked this conversation as resolved.
Show resolved Hide resolved
#[Config(defaultValues: [
'ownership' => [
'organization_field_name' => 'organization',
'organization_column_name' => 'organization_id',
'frontend_owner_type' => 'FRONTEND_USER',
'frontend_owner_field_name' => 'customerUser',
'frontend_owner_column_name' => 'customer_user_id', ],
'security' => [
'type' => 'ACL',
'group_name' => 'commerce'],
])]
class Favorite implements ExtendEntityInterface, OrganizationAwareInterface, DatesAwareInterface
{
use CreatedAtAwareTrait;
use ExtendEntityTrait;
use OrganizationAwareTrait;
use DatesAwareTrait;
use ExtendEntityTrait;
use FrontendCustomerUserAwareTrait;
use OrganizationAwareTrait;

/**
* @var integer
*
* @ORM\Id
* @ORM\Column(name="id", type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;

/**
* @var Product
*
* @ORM\ManyToOne(targetEntity="Oro\Bundle\ProductBundle\Entity\Product")
* @ORM\JoinColumn(name="product_id", referencedColumnName="id", onDelete="CASCADE")
*/
protected $product;
#[ORM\Column(name: 'id', type: 'integer')]
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'AUTO')]
protected ?int $id;

#[ORM\ManyToOne(targetEntity: Product::class)]
#[ORM\JoinColumn(name: 'product_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
protected Product $product;

/**
* @return integer
*/
public function getId(): int
public function getId(): ?int
{
return $this->id;
}

/**
* @return Product
*/
public function getProduct(): Product
public function getProduct(): ?Product
{
return $this->product;
}

/**
* @param Product $product
* @return Favorite
*/
public function setProduct(Product $product): self
{
$this->product = $product;

return $this;
}
}
Loading
Loading