简体   繁体   中英

TYPO3 Extbase: Extend tx_cart

I would like to extend the extension cart with a new field to put in the IBAN in the checkout. So I created a new extension and added a database field with the following code in ext_tables.sql

#
# Table structure for table 'tx_cart_domain_model_order_item'
#
CREATE TABLE tx_cart_domain_model_order_item (
    iban varchar(255) DEFAULT '' NOT NULL
);

Now I need to extend the class Item in

ext/cart/Classes/Domain/Model/Order/item.php

I tried to create a file in my extension

ext/cartextend/Classes/Domain/Model/Order/item.php 

and tried to extend the class with:

namespace Extcode\Cart\Domain\Model\Order;
use Extcode\Cart\Property\Exception\ResetPropertyException;
class Item extends \Extcode\Cart\Domain\Model\Order
{
    /**
     * Iban
     *
     * @var string
     */
    protected $iban;

    /**
     * @return string
     */
    public function getIban()
    {
        return $this->iban;
    }

    /**
     * @param string $iban
     */
    public function setIban($iban)
    {
        $this->iban = $iban;
    }
}

I also added an input field that is implemented correctly.

But the IBAN is not saved at all - i guess the extending of the class is wrong. I really appreciate any hint. Many thanks! Urs

Maybe you have to extend item.php like this (the rest looks fine):

namespace Extcode\YourExtension\Domain\Model\Order;

class Item extends \Extcode\Cart\Domain\Model\Order\Item

and do not forget to make it known to extbase for you to use iban in the front-end trough typoscript: (I have it to extend cart_products, you'll have to adept it)

config.tx_extbase {
    persistence {
        classes {
            Extcode\CartExtendedProduct\Domain\Model\Product\Product {
                mapping {
                    tableName = tx_cartproducts_domain_model_product_product
                    recordType =
                }
            }
        }
    }
    objects {
      Extcode\CartProducts\Domain\Model\Product\Product.className   = Extcode\CartExtendedProduct\Domain\Model\Product\Product
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM