Skip to content

Commit

Permalink
Add extra safety in templates
Browse files Browse the repository at this point in the history
  • Loading branch information
piusj committed Jun 3, 2024
1 parent 35dc493 commit 3721c25
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 17 deletions.
11 changes: 7 additions & 4 deletions Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,13 @@ public function getProductCategories(ProductInterface $product): array
}
}

/**
* Since we're not sure how the attribute is stored, we need to check a few places.
*/
public function getProductAttributeByCode(ProductInterface $product, string $attributeCode): string|null
/**
* Since we're not sure how the attribute is stored, we need to check a few places.
* @param ProductInterface $product
* @param string|null $attributeCode
* @return string|null
*/
public function getProductAttributeByCode(ProductInterface $product, string $attributeCode = null): string|null
{
try {
if (!$attributeCode)
Expand Down
9 changes: 7 additions & 2 deletions view/frontend/templates/layout/script.phtml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
<?php
use AirRobe\TheCircularWardrobe\Block\Layout\Script;

/** @var Script $block */
try {
/** @var Script $block */
$scriptUrl = $block->getScriptUrl();
} catch (\Throwable $e) {
$scriptUrl = '';
}
?>
<script src="<?php echo $block->getScriptUrl(); ?>" type="text/javascript" src_type="url"></script>
<script src="<?= $scriptUrl ?>" type="text/javascript" src_type="url"></script>
17 changes: 13 additions & 4 deletions view/frontend/templates/order/success.phtml
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
<?php
use AirRobe\TheCircularWardrobe\Block\Order\Success;

/** @var Success $block */
try {
/** @var Success $block */
$appId = $block->getAppId();
$orderId = $block->getOrderId();
$email = $block->getEmail();
} catch (\Throwable $e) {
$appId = '';
$orderId = '';
$email = '';
}
?>
<airrobe-confirmation
app-id="<?php echo $block->getAppId(); ?>"
order-id="<?php echo $block->getOrderId(); ?>"
email="<?php echo $block->getEmail(); ?>">
app-id="<?= $appId ?>"
order-id="<?= $orderId ?>"
email="<?= $email ?>">
</airrobe-confirmation>
29 changes: 22 additions & 7 deletions view/frontend/templates/product/view/markup.phtml
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
<?php
use AirRobe\TheCircularWardrobe\Block\Product\View\Markup;

/** @var Markup $block */
try {
/** @var Markup $block */
$appId = $block->getAppId();
$category = $block->getFirstProductCategory();
$priceCents = $block->getProductPriceCents();
$originalFullPriceCents = $block->getProductOriginalFullPriceCents();
$brand = $block->getProductBrand();
$material = $block->getProductMaterial();
} catch (\Throwable $e) {
$appId = '';
$category = '';
$priceCents = '';
$originalFullPriceCents = '';
$brand = '';
$material = '';
}
?>
<airrobe-opt-in
app-id="<?php echo $block->getAppId(); ?>"
category="<?php echo $block->getFirstProductCategory(); ?>"
price-cents="<?php echo $block->getProductPriceCents(); ?>"
original-full-price-cents="<?php echo $block->getProductOriginalFullPriceCents(); ?>"
brand="<?php echo $block->getProductBrand(); ?>"
material="<?php echo $block->getProductMaterial(); ?>">
app-id="<?= $appId ?>"
category="<?= $category ?>"
price-cents="<?= $priceCents ?>"
original-full-price-cents="<?= $originalFullPriceCents ?>"
brand="<?= $brand ?>"
material="<?= $material ?>">
</airrobe-opt-in>

0 comments on commit 3721c25

Please sign in to comment.