/** * Verify fields for "Add to cart" form. * * @param CatalogProductView $catalogProductView * @param GiftCardProduct $product * @param array $fixtureAmounts * @return array * * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ protected function verifyFields(CatalogProductView $catalogProductView, GiftCardProduct $product, array $fixtureAmounts) { $giftCard = $catalogProductView->getGiftCardBlock(); $isAmountSelectVisible = $giftCard->isAmountSelectVisible(); $isAmountInputVisible = $giftCard->isAmountInputVisible(); $isAllowOpenAmount = $product->hasData('allow_open_amount') && 'Yes' === $product->getAllowOpenAmount(); $isShowSelectAmount = $product->hasData('giftcard_amounts') && ($isAllowOpenAmount || 1 < count($product->getGiftcardAmounts())); return array_filter(array_merge($this->getSelectAmountVisibleErrors($isAmountSelectVisible, $isShowSelectAmount), $this->getInputAmountVisibleErrors($fixtureAmounts, $isAllowOpenAmount, $isAmountInputVisible), $this->getSenderAndRecipientFieldsVisibleErrors($product, $catalogProductView))); }
/** * Get checkout gift card options. * * @param GiftCardProduct $product * @return array */ protected function getCheckoutGiftCardOptions(GiftCardProduct $product) { $checkoutGiftCardOptions = []; $giftcardAmounts = $product->getGiftcardAmounts(); $checkoutData = $product->getCheckoutData(); if (isset($checkoutData['options']['giftcard_options'])) { $checkoutGiftCardOptions = $checkoutData['options']['giftcard_options']; // Replace option key to value $amountOptionKey = str_replace('option_key_', '', $checkoutGiftCardOptions['giftcard_amount']); $checkoutGiftCardOptions['giftcard_amount'] = $giftcardAmounts[$amountOptionKey]['price']; } return $checkoutGiftCardOptions; }