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

Inativar/Ativar item na assinatura #142

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
3d356da
Merge pull request #1 from vindi/master
cedran Oct 1, 2024
c9d712a
feat: removed deprecated magento 2 classes
contardi Oct 9, 2024
3dd0462
feat: removed deprecated magento 2 classes
contardi Oct 9, 2024
096d220
fix: remove unused patch
contardi Oct 9, 2024
079f52c
fix: call non existing class
contardi Oct 10, 2024
f726265
fix: return composer version
Oct 14, 2024
e8f58b3
Merge pull request #2 from vindi/development
cedran Oct 21, 2024
bb738ac
Merge pull request #3 from vindi/development
cedran Oct 25, 2024
e90f745
Versionamento da 2.1.0
thais-kusuki-vindi Oct 30, 2024
32b637a
Merge pull request #135 from vindi/versionamento/2.1.0
thais-kusuki-vindi Oct 30, 2024
da3a058
Merge pull request #4 from vindi/development
cedran Nov 1, 2024
bda41e8
feat: adding and deleting items in the subscription
devbizcommerce Nov 8, 2024
6b91aa7
feat: exclude and include subscription items
devbizcommerce Nov 13, 2024
dd35154
fix: adding validation so you can't exclude shipping or leave a subsc…
devbizcommerce Nov 13, 2024
a94c4c7
feat: add duration in subscription item
devbizcommerce Nov 13, 2024
bc18767
fix: add permanent option in item cycles
devbizcommerce Nov 13, 2024
b5321d0
refactor: restoring OrderCreator helper
devbizcommerce Nov 18, 2024
4e9a55f
fix: adjust creation of new orders
devbizcommerce Nov 18, 2024
d6d736c
refactor: create observer to update subscription data
devbizcommerce Nov 18, 2024
2188f25
feat: add quantity in subscription item
devbizcommerce Nov 29, 2024
a5d0d5b
fix: error updating subscription items in the observer
devbizcommerce Dec 2, 2024
a6423a3
fix: add validate quantity greater than zero
devbizcommerce Dec 3, 2024
81337ad
fix: add validate quantity greater than zero
devbizcommerce Dec 3, 2024
5cd96c9
fix: add validate quantity greater than zero
devbizcommerce Dec 3, 2024
2deb066
fix: customer id error when create register
devbizcommerce Dec 3, 2024
c0f2de2
fix: customer id error when create register
devbizcommerce Dec 3, 2024
06b9e79
fix: fixing zero price validations
devbizcommerce Dec 4, 2024
fd24535
fix: finalizing orders with zero prices
devbizcommerce Dec 4, 2024
479c8ee
feat: adding option to change subscription item status
devbizcommerce Dec 5, 2024
62ff5d9
Merge pull request #5 from vindi/development
cedran Dec 5, 2024
c7d9b84
merge
devbizcommerce Dec 5, 2024
5c1e21c
merge
devbizcommerce Dec 5, 2024
20bf8c0
Merge branch 'master' of github.com:bizcommerce/vindi-magento2
Dec 13, 2024
2d111c3
feat: merge remote
Dec 13, 2024
e874370
Merge branch 'vindi-master'
Dec 13, 2024
bb686e5
Merge remote-tracking branch 'origin/master' into development
Dec 13, 2024
597f80c
feat: new card layout
contardi Dec 14, 2024
f979e70
fix: same input id for different fields
contardi Dec 17, 2024
924a82b
Merge branch 'development' into feature/exclude-include-subscription-…
devbizcommerce Dec 18, 2024
334392b
Merge branch 'feature/exclude-include-subscription-items' into featur…
devbizcommerce Dec 18, 2024
bcd91fd
fix: cacheable false for product view
contardi Dec 19, 2024
97bf315
fix: add cache key info product block
contardi Dec 19, 2024
3abb854
fix: add discount in subscriptions
devbizcommerce Dec 19, 2024
956f099
Merge branch 'feature/exclude-include-subscription-items' into featur…
devbizcommerce Dec 19, 2024
a812adf
Merge pull request #7 from bizcommerce/feat/new-card-layout
contardi Dec 29, 2024
84cd88e
Merge branch 'development' into feature/exclude-include-subscription-…
devbizcommerce Jan 6, 2025
d8684c5
Merge branch 'feature/exclude-include-subscription-items' into featur…
devbizcommerce Jan 6, 2025
3371f62
fix: correcting quantity validation in shipping
devbizcommerce Jan 6, 2025
7d3c80c
feat: added all available brands
contardi Jan 6, 2025
75875a2
Merge remote-tracking branch 'origin/development' into feature/exclud…
contardi Jan 7, 2025
d97cdd0
Merge branch 'feature/exclude-include-subscription-items' of https://…
devbizcommerce Jan 8, 2025
30957ef
merge
devbizcommerce Jan 8, 2025
054216e
fix: removed status on item creation
devbizcommerce Jan 14, 2025
3bf42fc
Merge branch 'feature/exclude-include-subscription-items' into featur…
devbizcommerce Jan 14, 2025
c44273a
Merge pull request #9 from vindi/development
cedran Jan 15, 2025
2197abf
Merge branch 'development' into feature/exclude-include-subscription-…
devbizcommerce Jan 15, 2025
9caf345
Merge branch 'feature/exclude-include-subscription-items' into featur…
devbizcommerce Jan 15, 2025
a3747f3
fix: correcting duplication of items on the invoice
devbizcommerce Jan 15, 2025
ce0e160
Merge branch 'feature/exclude-include-subscription-items' into featur…
devbizcommerce Jan 15, 2025
a9c83e8
fix: adjusting the addition of temporary items
devbizcommerce Jan 16, 2025
9ed0c24
Merge branch 'feature/exclude-include-subscription-items' into featur…
devbizcommerce Jan 16, 2025
29a40ae
fix: removing the item when creating the invoice
devbizcommerce Jan 16, 2025
82e6c2b
Merge branch 'feature/exclude-include-subscription-items' into featur…
devbizcommerce Jan 16, 2025
93b931a
fix: removing the item when creating the invoice
devbizcommerce Jan 16, 2025
474fd6c
Merge branch 'feature/exclude-include-subscription-items' into featur…
devbizcommerce Jan 16, 2025
2ebe788
fix: removing the item when creating the invoice
devbizcommerce Jan 17, 2025
e8ad5f5
Merge branch 'feature/exclude-include-subscription-items' into featur…
devbizcommerce Jan 17, 2025
9798060
fix: removing the item when creating the invoice
devbizcommerce Jan 17, 2025
e63ff62
Merge branch 'feature/exclude-include-subscription-items' into featur…
devbizcommerce Jan 17, 2025
2f18d63
fix: removing the item when creating the invoice
devbizcommerce Jan 17, 2025
4dcb140
fix: removing the item when creating the invoice
devbizcommerce Jan 17, 2025
6bae698
fix: removing the item when creating the invoice
devbizcommerce Jan 17, 2025
05d6c36
Merge branch 'feature/exclude-include-subscription-items' into featur…
devbizcommerce Jan 17, 2025
8fea1da
fix: removing duplication in translation
devbizcommerce Jan 29, 2025
63d1026
Merge branch 'feature/exclude-include-subscription-items' into featur…
devbizcommerce Jan 29, 2025
551d054
Merge pull request #10 from vindi/development
cedran Feb 3, 2025
e0c0c2f
merge
devbizcommerce Feb 3, 2025
fa88896
fix: remove duplicate itens
devbizcommerce Feb 6, 2025
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
48 changes: 42 additions & 6 deletions Controller/Adminhtml/Subscription/SaveSubscriptionItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,29 @@
*/
class SaveSubscriptionItem extends Action
{
/** @var ProductItems */
/**
* @var ProductItems
*/
protected $productItems;

/** @var VindiSubscriptionItemRepository */
/**
* @var VindiSubscriptionItemRepository
*/
protected $subscriptionItemRepository;

/** @var JsonFactory */
/**
* @var JsonFactory
*/
protected $resultJsonFactory;

/** @var VindiSubscriptionItemCollectionFactory */
/**
* @var VindiSubscriptionItemCollectionFactory
*/
protected $vindiSubscriptionItemCollectionFactory;

/**
* SaveSubscriptionItem constructor.
*
* @param Context $context
* @param ProductItems $productItems
* @param VindiSubscriptionItemRepository $subscriptionItemRepository
Expand Down Expand Up @@ -72,18 +81,40 @@ public function execute()
$entityId = $postData['entity_id'] ?? null;
$price = $postData['settings']['price'] ?? null;
$quantity = $postData['settings']['quantity'] ?? null;
$status = $postData['settings']['status'] ?? null;

if (!$entityId || ($price === null && $quantity === null)) {
throw new LocalizedException(__('You must provide at least one of the fields: price or quantity.'));
}

$subscriptionItem = $this->subscriptionItemRepository->getById($entityId);
$productCode = $subscriptionItem->getProductCode();
$subscriptionId = $subscriptionItem->getSubscriptionId();

if ($productCode === 'frete' && $quantity !== null) {
throw new LocalizedException(__('The quantity of the shipping item cannot be changed. Only the price can be updated.'));
}

if ($status !== null) {
if ($productCode === 'frete' && $status !== 'active') {
throw new LocalizedException(__('Shipping items must remain active.'));
}

if ($status === 'inactive') {
$itemsCollection = $this->vindiSubscriptionItemCollectionFactory->create();
$itemsCollection->addFieldToFilter('subscription_id', $subscriptionId)
->addFieldToFilter('product_code', ['neq' => 'frete'])
->addFieldToFilter('entity_id', ['neq' => $entityId])
->addFieldToFilter('status', 'active');

$activeItems = $itemsCollection->getSize();

if ($activeItems == 0) {
throw new LocalizedException(__('A subscription must have at least one non-shipping active item.'));
}
}
}

$data = [];
if ($price !== null) {
$price = number_format((float)$price, 2, '.', '');
Expand All @@ -92,13 +123,14 @@ public function execute()

if ($quantity !== null) {
$data['quantity'] = (int)$quantity;

if ($quantity > 1) {
$data['pricing_schema']['schema_type'] = 'per_unit';
}
}

$subscriptionId = $subscriptionItem->getSubscriptionId();
if ($status !== null) {
$data['status'] = $status;
}

if ((float)$price === 0.00 && $productCode !== 'frete') {
$itemsCollection = $this->vindiSubscriptionItemCollectionFactory->create();
Expand Down Expand Up @@ -129,6 +161,10 @@ public function execute()
$subscriptionItem->setQuantity($quantity);
}

if ($status !== null) {
$subscriptionItem->setStatus($status);
}

$this->subscriptionItemRepository->save($subscriptionItem);

$this->_eventManager->dispatch(
Expand Down
37 changes: 3 additions & 34 deletions Model/VindiSubscriptionItem/DataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,11 @@

class DataProvider extends \Magento\Ui\DataProvider\ModifierPoolDataProvider
{
/**
* @var \Vindi\Payment\Model\ResourceModel\VindiSubscriptionItem\Collection
*/
protected $collection;

/**
* @var DataPersistorInterface
*/
protected $dataPersistor;

/**
* @var array
*/
protected $loadedData;

/**
* @var Data
*/
protected $helper;

/**
* DataProvider constructor.
* @param string $name
* @param string $primaryFieldName
* @param string $requestFieldName
* @param CollectionFactory $subscriptionItemCollectionFactory
* @param DataPersistorInterface $dataPersistor
* @param Data $helper
* @param array $meta
* @param array $data
* @param PoolInterface|null $pool
*/
public function __construct(
string $name,
string $primaryFieldName,
Expand All @@ -58,9 +31,6 @@ public function __construct(
parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data, $pool);
}

/**
* @return array
*/
public function getData()
{
if (isset($this->loadedData)) {
Expand All @@ -69,12 +39,11 @@ public function getData()

$items = $this->collection->getItems();

/** @var \Vindi\Payment\Model\VindiSubscriptionItem $subscriptionItem */
foreach ($items as $subscriptionItem) {
$result['settings'] = $subscriptionItem->getData();
$price = number_format((float) $result['settings']['price'], 2, '.', '');
$result['settings']['price'] = $price;
$result['entity_id'] = $subscriptionItem->getEntityId();
$result['entity_id'] = $subscriptionItem->getId();

$result['settings']['price'] = number_format((float) $subscriptionItem->getPrice(), 2, '.', '');

$this->loadedData[$subscriptionItem->getEntityId()] = $result;
}
Expand Down
6 changes: 6 additions & 0 deletions i18n/pt_BR.csv
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,12 @@
"This subscription item no longer exists.","Este item de assinatura não existe mais."
"Failed to delete the item from the subscription.","Falha ao excluir o item da assinatura."
"This subscription no longer exists.","Esta assinatura não existe mais."
"Shipping items must remain active.","Itens de frete devem permanecer ativos."
"A subscription must have at least one non-shipping active item.","Uma assinatura deve ter pelo menos um item ativo (sem contar o frete)."
"inactive","Inativo"
"active","Ativo"
"Inactive","Inativo"
"Active","Ativo"
"This payment link has expired.","Este link de pagamento expirou."
"The payment success page has already been accessed.","A página de sucesso do pagamento já foi acessada."
"Card Information","Dados do Cartão"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,29 @@
<dataScope>quantity</dataScope>
</settings>
</field>
<field name="status" sortOrder="30" formElement="checkbox">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="source" xsi:type="string">menu</item>
<item name="default" xsi:type="string">active</item>
</item>
</argument>
<settings>
<dataType>boolean</dataType>
<label translate="true">Status</label>
<dataScope>status</dataScope>
</settings>
<formElements>
<checkbox>
<settings>
<valueMap>
<map name="false" xsi:type="string">inactive</map>
<map name="true" xsi:type="string">active</map>
</valueMap>
<prefer>toggle</prefer>
</settings>
</checkbox>
</formElements>
</field>
</fieldset>
</form>