Adding extra field to order/checkout without editing core fles

Hey,

I’m trying to add and extra comment field to the Checkout. But I can’t get the data to be passed over without editing the Core files. How can I recreate this as an extension or a plugin? Or does anybody have a better or easier solution that I’ve missed?

Thanks in advance,
Chef

----------------------------------------------------------------------
Shopware Core file:
vendor/shopware/shopware/engine/Shopware/Models/Order/Order.php
----------------------------------------------------------------------
363:
    /**
     * @var string
     *
     * @ORM\Column(name="commentTest", type="text", nullable=false)
     */
    private $commentTest;


725:
    /**
     * Set commentTest
     *
     * @param string $commentTest
     *
     * @return Order
     */
    public function setCommentTest($commentTest)
    {
        $this->commentTest = $this->cleanup($commentTest);

        return $this;
    }

    /**
     * Get commentTest
     *
     * @return string
     */
    public function getCommentTest()
    {
        return $this->commentTest;
    }

----------------------------------------------------------------------
Core file:
vendor/shopware/shopware/engine/Shopware/Core/sOrder.php 
----------------------------------------------------------------------
62:
/**
 * User commentTest to save within this order
 *
 * @var string
 */
public $sCommentTest;

429:
$data = [
	'ordernumber' => '0',
	'userID' => $this->sUserData['additional']['user']['id'],
	'invoice_amount' => $this->sBasketData['AmountWithTaxNumeric'],
	'invoice_amount_net' => $this->sBasketData['AmountNetNumeric'],
	'invoice_shipping' => $this->sShippingcostsNumeric,
	'invoice_shipping_net' => $this->sShippingcostsNumericNet,
	'ordertime' => new Zend_Db_Expr('NOW()'),
	'status' => -1,
	'paymentID' => $this->getPaymentId(),
	'customercomment' => $this->sComment,
	'commenttest' => $this->sCommentTest,
	'net' => $net,
	'taxfree' => $taxfree,
	'partnerID' => (string) $this->getSession()->offsetGet('sPartner'),
	'temporaryID' => $this->getSession()->offsetGet('sessionId'),
	'referer' => (string) $this->getSession()->offsetGet('sReferer'),
	'language' => $shop->getId(),
	'dispatchID' => $dispatchId,
	'currency' => $this->sBasketData['sCurrencyName'],
	'currencyFactor' => $this->sBasketData['sCurrencyFactor'],
	'subshopID' => $mainShop->getId(),
	'deviceType' => $this->deviceType,
];

539:
$orderParams = [
	'ordernumber' => $orderNumber,
	'userID' => $this->sUserData['additional']['user']['id'],
	'invoice_amount' => $this->sBasketData['AmountWithTaxNumeric'],
	'invoice_amount_net' => $this->sBasketData['AmountNetNumeric'],
	'invoice_shipping' => (float) $this->sShippingcostsNumeric,
	'invoice_shipping_net' => (float) $this->sShippingcostsNumericNet,
	'invoice_shipping_tax_rate' => isset($this->sBasketData['sShippingcostsTaxProportional']) ? 0 : $this->sBasketData['sShippingcostsTax'],
	'ordertime' => new Zend_Db_Expr('NOW()'),
	'changed' => new Zend_Db_Expr('NOW()'),
	'status' => 0,
	'cleared' => 17,
	'paymentID' => $this->getPaymentId(),
	'transactionID' => (string) $this->bookingId,
	'customercomment' => $this->sComment,
	'commenttest' => $this->sCommentTest,
	'net' => $net,
	'taxfree' => $taxfree,
	'partnerID' => (string) $partner,
	'temporaryID' => (string) $this->uniqueID,
	'referer' => (string) $this->getSession()->offsetGet('sReferer'),
	'language' => $shop->getId(),
	'dispatchID' => $dispatchId,
	'currency' => $this->sBasketData['sCurrencyName'],
	'currencyFactor' => $this->sBasketData['sCurrencyFactor'],
	'subshopID' => $mainShop->getId(),
	'remote_addr' => $ip,
	'deviceType' => $this->deviceType,
	'is_proportional_calculation' => isset($this->sBasketData['sShippingcostsTaxProportional']) ? 1 : 0,
];

----------------------------------------------------------------------
themes/Frontend/customTheme/frontend/checkout/confirm.tpl
----------------------------------------------------------------------
{extends file='parent:frontend/checkout/confirm.tpl'}

{block name="frontend_checkout_confirm_information_addresses_billing_panel_actions_select_address"}{/block}
{block name='frontend_checkout_confirm_tos_panel'}
    {debug}
	<textarea class="is--hidden user-comment2--hidden" rows="1" cols="1" name="sCommentTest">{$sCommentTest|escape}</textarea>
    {$smarty.block.parent}
{/block}

{* Additional customer comment for the order *}
{block name='frontend_checkout_confirm_comment'}
	<div class="feature--user-comment block">
		<textarea class="user-comment--field" data-storage-field="true" maxlength="100" data-storageKeyName="sComment" rows="5" cols="20" placeholder="{s name="ConfirmPlaceholderComment" namespace="frontend/checkout/confirm"}{/s}" data-pseudo-text="true" data-selector=".user-comment--hidden">{$sComment|escape}</textarea>
		<textarea class="user-comment--field" data-storage-field="true" maxlength="100" data-storageKeyName="sCommentTest" rows="5" cols="20" placeholder="{s name="ConfirmPlaceholderCommentTest" namespace="frontend/checkout/confirm"}{/s}" data-pseudo-text="true" data-selector=".user-comment2--hidden">{$sCommentTest|escape}</textarea>
	</div>
{/block}

Hi Chef,

Never tamper with any core files, those changes will be lost on the next update. For adding additional fields, you have two options:

  • use the “free text field” plugin in the backend (easiest when you just need to add a field to a single shop instance) - select the desired table you plan to extend from the dropdown
  • use the attributes system (for developers)

Cheers, Phil