Skip to content

Commit

Permalink
Merge pull request #12 from feleCornejo/feature/update-to-oro-6
Browse files Browse the repository at this point in the history
feat:Update to oro 6
  • Loading branch information
mi-lopez authored May 6, 2024
2 parents c09368d + 9996736 commit e0b9dd7
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 92 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php: [8.1]
php: [8.3]

steps:
- uses: actions/checkout@v2
Expand Down
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 the customer to subscribe to a product whose stock level is e
## Requirements

| | Version |
| :--- | :-- |
| PHP | 8.2 |
| OroCommerce | 5.1 |
| :--- |:--------|
| PHP | 8.2 |
| OroCommerce | 5.1 |

## Installation

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
"exclude-from-classmap": ["/Tests/"]
},
"require": {
"php": "~8.2.0",
"oro/commerce": "5.1.*"
"php": "~8.3.0",
"oro/commerce": "6.0.*"
},
"repositories": {
"oro": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
namespace Synolia\Bundle\StockAlertBundle\Controller\Frontend;

use Doctrine\Persistence\ObjectManager;
use Oro\Bundle\LayoutBundle\Annotation\Layout;
use Oro\Bundle\LayoutBundle\Attribute\Layout;
use Oro\Bundle\ProductBundle\Entity\Product;
use Oro\Bundle\SecurityBundle\Annotation\CsrfProtection;
use Oro\Bundle\SecurityBundle\Attribute\CsrfProtection;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
Expand Down Expand Up @@ -40,9 +40,7 @@ public function setHandler(StockAlertHandler $handler): void
$this->handler = $handler;
}

/**
* @Route(path="/form/{productId}", name="synolia_frontend_stock_alert_form", methods={"POST"})
*/
#[Route(path: '/form/{productId}', name: 'synolia_frontend_stock_alert_form', methods: ['POST']) ]
public function form(Request $request, int $productId): Response
{
$product = $this->manager->getRepository(Product::class)->find($productId);
Expand Down Expand Up @@ -81,10 +79,8 @@ public function form(Request $request, int $productId): Response
]);
}

/**
* @Route("/", name="synolia_stock_alert_frontend_index")
* @Layout(vars={"entity_class", "organization_id", "customer_user_id"})
*/
#[Route(path: '/', name: 'synolia_stock_alert_frontend_index')]
#[Layout(vars: ['entity_class','organization_id','customer_user_id'])]
public function indexAction(): array
{
$entityClass = StockAlert::class;
Expand All @@ -98,10 +94,8 @@ public function indexAction(): array
];
}

/**
* @Route("/create/{id}", name="synolia_stock_alert_create", requirements={"id"="\d+"})
* @ParamConverter("product", class="OroProductBundle:Product", options={"id" = "id"})
*/
#[Route(path: '/create/{id}', name: 'synolia_stock_alert_create', requirements: ['id' => '\d+']) ]
#[ParamConverter('product', class: Product::class, options: ['id' => 'id'])]
public function createAction(Product $product): JsonResponse
{
try {
Expand All @@ -122,16 +116,9 @@ public function createAction(Product $product): JsonResponse
]);
}

/**
* @Route(
* "/delete/{id}",
* name="synolia_stock_alert_delete",
* methods={"DELETE"},
* requirements={"id"="\d+"}
* )
* @CsrfProtection()
* @ParamConverter("product", class="OroProductBundle:Product", options={"id" = "id"})
*/
#[Route(path: '/delete/{id}', name: 'synolia_stock_alert_delete', requirements: ['id' => '\d+'], methods: ['DELETE']) ]
#[CsrfProtection()]
#[ParamConverter('product', class: Product::class, options: ['id' => 'id'])]
public function deleteAction(Product $product): JsonResponse
{
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@

class StockAlertController extends AbstractController
{
/**
* @Route("/", name="synolia_stock_alert_index")
* @Template
*/
#[Route(path: '/', name: 'synolia_stock_alert_index')]
#[Template('@SynoliaStockAlert/StockAlert/index.html.twig')]
public function indexAction(): array
{
return [
Expand Down
68 changes: 29 additions & 39 deletions src/Synolia/Bundle/StockAlertBundle/Entity/StockAlert.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,42 @@

namespace Synolia\Bundle\StockAlertBundle\Entity;

use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Oro\Bundle\CustomerBundle\Entity\CustomerOwnerAwareInterface;
use Oro\Bundle\CustomerBundle\Entity\Ownership\FrontendCustomerAwareTrait;
use Oro\Bundle\CustomerBundle\Entity\Ownership\FrontendCustomerUserAwareTrait;
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\ProductBundle\Entity\Product;
use Oro\Bundle\UserBundle\Entity\Ownership\UserAwareTrait;
use Synolia\Bundle\StockAlertBundle\Entity\Repository\StockAlertRepository;
use Synolia\Bundle\StockAlertBundle\Model\ExtendStockAlert;

/**
* @ORM\Table(name="synolia_stock_alert")
* @ORM\Entity(repositoryClass="Synolia\Bundle\StockAlertBundle\Entity\Repository\StockAlertRepository")
* @Config(
* defaultValues={
* "ownership"={
* "owner_type"="USER",
* "owner_field_name"="owner",
* "owner_column_name"="user_owner_id",
* "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",
* "frontend_customer_field_name"="customer",
* "frontend_customer_column_name"="customer_id"
* },
* "dataaudit"={
* "auditable"=true
* },
* "entity"={
* "icon"="fa-shopping-cart"
* }
* }
* )
*/
#[ORM\Entity(repositoryClass: StockAlertRepository::class)]
#[ORM\Table(name: 'synolia_stock_alert')]
#[Config(
defaultValues: [
'entity' => ['icon' => 'fa-shopping-cart'],
'dataaudit' => ['auditable' => true],
'ownership' => [
'owner_type' => 'USER',
'owner_field_name' => 'owner',
'owner_column_name' => 'user_owner_id',
'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',
'frontend_customer_field_name' => 'customer',
'frontend_customer_column_name' => 'customer_id',
],
]
)]
class StockAlert extends ExtendStockAlert implements
ExtendEntityInterface,
OrganizationAwareInterface,
Expand All @@ -56,22 +52,16 @@ class StockAlert extends ExtendStockAlert implements
use FrontendCustomerUserAwareTrait;
use UserAwareTrait;

/**
* @ORM\Id
* @ORM\Column(name="id", type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
#[ORM\Id]
#[ORM\Column(name: 'id', type: Types::INTEGER)]
#[ORM\GeneratedValue(strategy: 'AUTO')]
protected int $id;

/**
* @ORM\ManyToOne(targetEntity="Oro\Bundle\ProductBundle\Entity\Product")
* @ORM\JoinColumn(name="product_id", referencedColumnName="id", nullable=false, onDelete="CASCADE")
*/
#[ORM\ManyToOne(targetEntity: Product::class)]
#[ORM\JoinColumn(name: 'product_id', referencedColumnName: 'id', nullable: false, onDelete: 'CASCADE')]
protected Product $product;

/**
* @ORM\Column(name="expiration_date", type="datetime", nullable=true)
*/
#[ORM\Column(name: 'expiration_date', type: Types::DATETIME_MUTABLE, nullable: true)]
protected ?\DateTime $expirationDate;

public function getId(): int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Doctrine\Persistence\ObjectManager;
use Oro\Bundle\EmailBundle\Migrations\Data\ORM\AbstractEmailFixture;
use Oro\Bundle\EmailBundle\Model\EmailTemplate;
use Oro\Bundle\EmailBundle\Entity\EmailTemplate;
use Oro\Bundle\MigrationBundle\Fixture\VersionedFixtureInterface;

class LoadEmailTemplates extends AbstractEmailFixture implements VersionedFixtureInterface
Expand All @@ -16,7 +16,7 @@ public function getEmailsDir(): string
return $this->container
->get('kernel')
->locateResource('@SynoliaStockAlertBundle/Migrations/Data/ORM/data/emails')
;
;
}

public function getVersion(): string
Expand All @@ -30,7 +30,7 @@ protected function findExistingTemplate(ObjectManager $manager, array $template)
return null;
}

return $manager->getRepository('OroEmailBundle:EmailTemplate')->findOneBy([
return $manager->getRepository(EmailTemplate::class)->findOneBy([
'name' => $template['params']['name'],
]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ const StockAlert = BaseView.extend({
this.options = {...this.options, ...options};

this.productId = this.options.productId;
if(this.productId === undefined){
this.productId = this.options.product.id;
}
this.hasStock = this.options.hasStock;
if (this.hasStock) {
$('.delete-stock-alert', this.options.el).show();
Expand Down Expand Up @@ -63,4 +66,4 @@ const StockAlert = BaseView.extend({
}
});

export default StockAlert
export default StockAlert
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@
</p>
</div>
{% if (quantity <= 0) %}
<div class="col">
<a class="create-stock-alert pull-right"
href=""
title="{{ 'synolia.stockalert.alert.register.title'|trans }}"
style="display: none"
>
<span class="fa-envelope"></span>
</a>
<a class="delete-stock-alert pull-right"
href=""
title="{{ 'synolia.stockalert.alert.unregister.title'|trans }}"
style="display: none"
>
<span class="fa-trash"></span>
</a>
</div>
<div class="col">
<a class="create-stock-alert pull-right"
href=""
title="{{ 'synolia.stockalert.alert.register.title'|trans }}"
style="display: none"
>
<span class="fa-envelope"></span>
</a>
<a class="delete-stock-alert pull-right"
href=""
title="{{ 'synolia.stockalert.alert.unregister.title'|trans }}"
style="display: none"
>
<span class="fa-trash"></span>
</a>
</div>
{% endif %}
</div>
</div>
Expand Down

0 comments on commit e0b9dd7

Please sign in to comment.