Skip to content

Commit

Permalink
NTR: PISHPS-273: fix subscription button in diffferent languages (#742)
Browse files Browse the repository at this point in the history
fix #719

Co-authored-by: Vitalij Mik <[email protected]>
  • Loading branch information
BlackScorp and Vitalij Mik authored May 8, 2024
1 parent 8ca3c81 commit b62ad4c
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

{% block buy_widget_buy_button %}

{% if mollie_subscriptions_enabled and product.customFields.mollie_payments_product_subscription_enabled %}
{% if mollie_subscriptions_enabled and product.translated.customFields.mollie_payments_product_subscription_enabled %}
<div class="d-grid">
<button class="btn btn-primary btn-block btn-buy" title="{{ "molliePayments.subscriptions.product.addToCartText"|trans|sw_sanitize }}" aria-label="{{ "molliePayments.subscriptions.product.addToCartText"|trans|sw_sanitize }}">
{{ "molliePayments.subscriptions.product.addToCartText"|trans|sw_sanitize }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@

{% block page_product_detail_product_buy_button %}

{% if mollie_subscriptions_enabled and product.customFields.mollie_payments_product_subscription_enabled %}

{% if mollie_subscriptions_enabled and product.translated.customFields.mollie_payments_product_subscription_enabled %}
<div class="d-grid">
<button class="btn btn-block btn-buy" title="{{ "molliePayments.subscriptions.product.addToCartText"|trans|sw_sanitize }}">
{{ "molliePayments.subscriptions.product.addToCartText"|trans|sw_sanitize }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

{% set isMollieSubscription = false %}
{% for element in page.cart.data.elements %}
{% if(element._entityName == "product" and element.customFields.mollie_payments_product_subscription_enabled) %}
{% if(element._entityName == "product" and element.translated.customFields.mollie_payments_product_subscription_enabled) %}
{% set isMollieSubscription = true %}
{% endif %}
{% endfor %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

{% block page_product_detail_buy_button %}

{% if mollie_subscriptions_enabled and page.product.customFields.mollie_payments_product_subscription_enabled %}
{% if mollie_subscriptions_enabled and page.product.translated.customFields.mollie_payments_product_subscription_enabled %}
<button class="btn btn-primary btn-block btn-buy" title="{{ "molliePayments.subscriptions.product.addToCartText"|trans|sw_sanitize }}" aria-label="{{ "molliePayments.subscriptions.product.addToCartText"|trans|sw_sanitize }}">
{{ "molliePayments.subscriptions.product.addToCartText"|trans|sw_sanitize }}
</button>
Expand Down
2 changes: 1 addition & 1 deletion src/Struct/Product/ProductAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ private function getCustomFieldValue(ProductEntity $product, string $keyName)
$foundValue = '';


$customFields = $product->getCustomFields();
$customFields = $product->getTranslated()['customFields'];

# ---------------------------------------------------------------------------
# search in new structure
Expand Down
6 changes: 5 additions & 1 deletion tests/PHPUnit/Service/Cart/Voucher/VoucherServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function testProductHasMealVoucher()
$foundProduct->setCustomFields([
'mollie_payments_product_voucher_type' => VoucherType::TYPE_MEAL,
]);

$foundProduct->setTranslated(['customFields'=>$foundProduct->getCustomFields()]);
# build a repo that would return nothing...just in case ;)
$fakeRepoProducts = new FakeProductRepository(null, $foundProduct);

Expand All @@ -99,8 +99,10 @@ public function testUnknownParentThrowsException()
$this->expectException(ProductNotFoundException::class);

$foundProduct = new ProductEntity();

$foundProduct->setId('ID-123');
$foundProduct->setParentId('PARENT-123');
$foundProduct->setTranslated(['customFields'=>$foundProduct->getCustomFields()]);

$fakeRepoProducts = new FakeProductRepository(null, $foundProduct);

Expand All @@ -121,12 +123,14 @@ public function testVoucherOfParent()
$foundProduct = new ProductEntity();
$foundProduct->setId('ID-123');
$foundProduct->setParentId('PARENT-123');
$foundProduct->setTranslated(['customFields'=>$foundProduct->getCustomFields()]);

$foundParentProduct = new ProductEntity();
$foundParentProduct->setId('ID-456');
$foundParentProduct->setCustomFields([
'mollie_payments_product_voucher_type' => VoucherType::TYPE_GIFT,
]);
$foundParentProduct->setTranslated(['customFields'=>$foundParentProduct->getCustomFields()]);


$fakeRepoProducts = new FakeProductRepository($foundParentProduct, $foundProduct);
Expand Down
28 changes: 19 additions & 9 deletions tests/PHPUnit/Struct/Product/ProductAttributesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@ class ProductAttributesTest extends TestCase
*/
public function testEmptyCustomFields()
{
$method = new ProductEntity();
$method->setCustomFields([]);
$product = new ProductEntity();
$product->setCustomFields([]);
$product->setTranslated([
'customFields' => $product->getCustomFields()
]);


$attributes = new ProductAttributes($method);
$attributes = new ProductAttributes($product);

$this->assertEquals('', $attributes->getVoucherType());
}
Expand All @@ -30,15 +34,18 @@ public function testEmptyCustomFields()
*/
public function testVoucherType()
{
$method = new ProductEntity();
$method->setCustomFields([
$product = new ProductEntity();
$product->setCustomFields([
'mollie_payments_product_voucher_type' => VoucherType::TYPE_ECO,
'mollie_payments' => [
'voucher_type' => VoucherType::TYPE_MEAL
]
]);
$product->setTranslated([
'customFields' => $product->getCustomFields()
]);

$attributes = new ProductAttributes($method);
$attributes = new ProductAttributes($product);

$this->assertEquals(VoucherType::TYPE_ECO, $attributes->getVoucherType());
}
Expand All @@ -49,12 +56,15 @@ public function testVoucherType()
*/
public function testUnknownVoucherType()
{
$method = new ProductEntity();
$method->setCustomFields([
$product = new ProductEntity();
$product->setCustomFields([
'mollie_payments_product_voucher_type' => '5',
]);
$product->setTranslated([
'customFields' => $product->getCustomFields()
]);

$attributes = new ProductAttributes($method);
$attributes = new ProductAttributes($product);

$this->assertEquals(VoucherType::TYPE_NOTSET, $attributes->getVoucherType());
}
Expand Down

0 comments on commit b62ad4c

Please sign in to comment.