diff --git a/src/.editorconfig b/src/.editorconfig new file mode 100644 index 0000000..5a1a946 --- /dev/null +++ b/src/.editorconfig @@ -0,0 +1,20 @@ +# EditorConfig is awesome: https://EditorConfig.org + +# Top-most EditorConfig file +root = true + +# All files +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true +indent_style = tab + +# Markdown files +[*.md] +trim_trailing_whitespace = false + +[*.{yaml,yml}] +indent_size = 2 +indent_style = space diff --git a/src/services/Checkout.php b/src/services/Checkout.php index c2d97aa..6122168 100644 --- a/src/services/Checkout.php +++ b/src/services/Checkout.php @@ -2,6 +2,7 @@ namespace fostercommerce\craftfostercheckout\services; +use craft\commerce\elements\Product; use craft\commerce\elements\Variant; use craft\commerce\models\LineItem; use craft\commerce\Plugin; @@ -88,7 +89,7 @@ public function note($page): ?string return $note; } - /* + /** * Gets the line items image field based on the products settings */ public function lineItemImageField($productType): ?array @@ -116,28 +117,30 @@ public function lineItemImageField($productType): ?array return $fieldData; } - /* + /** * Gets a line items image asset based on the config settings for the product type + * + * @throws InvalidConfigException */ public function lineItemImage(LineItem $lineItem): ?Asset { $image = null; $sku = $lineItem->getSku(); $variant = Variant::find()->sku($sku)->one(); + /** @var Product $product */ $product = $variant->getOwner(); + $fieldInfo = $this->lineItemImageField($product->type->handle); - if ($fieldInfo['level'] === 'variant') { + if ($fieldInfo !== null) { try { - $image = $variant->getFieldValue($fieldInfo['handle'])->one(); - } catch (InvalidFieldException) { - $image = null; - } - } else { - try { - $image = $product->getFieldValue($fieldInfo['handle'])->one(); + if ($fieldInfo['level'] === 'variant') { + $image = $variant->getFieldValue($fieldInfo['handle'])->one(); + } else { + $image = $product->getFieldValue($fieldInfo['handle'])->one(); + } } catch (InvalidFieldException) { - $image = null; + // Do nothing } }