<commit_before><?php
class Kwc_Shop_Cart_Checkout_Form_FrontendForm extends Kwf_Form
{
    protected $_modelName = 'Kwc_Shop_Cart_Orders';
    private $_payments;

    protected function _initFields()
    {
        parent::_initFields();
        $this->add(new Kwf_Form_Field_Panel('intro_text'))
            ->setHtml('<h1>'.trlKwf('Please enter your address').'</h1>')
            ->setHideFieldInBackend(true);
        $this->add(new Kwf_Form_Field_Radio('sex', trlcKwf('sex', 'Title')))
            ->setValues(array(
                'male'   => trlKwf('Mr.'),
                'female' => trlKwf('Ms.')
            ))
            ->setAllowBlank(false);
        $this->add(new Kwf_Form_Field_TextField('title', trlKwf('Title')));
        $this->add(new Kwf_Form_Field_TextField('firstname', trlKwf('First name')))
            ->setAllowBlank(false);
        $this->add(new Kwf_Form_Field_TextField('lastname', trlKwf('Last name')))
            ->setAllowBlank(false);
        $this->add(new Kwf_Form_Field_TextField('street', trlKwf('Street')))
            ->setAllowBlank(false);
        $this->add(new Kwf_Form_Field_TextField('zip', trlKwf('ZIP')))
            ->setAllowBlank(false);
        $this->add(new Kwf_Form_Field_TextField('city', trlKwf('City')))
            ->setAllowBlank(false);
        $this->add(new Kwf_Form_Field_SelectCountry('country', trlKwf('Country')))
            ->setDefaultValue('AT')
            ->setAllowBlank(false);
        $this->add(new Kwf_Form_Field_TextField('email', trlKwf('E-Mail')))
            ->setVtype('email')
            ->setAllowBlank(false);
        $this->add(new Kwf_Form_Field_TextField('phone', trlKwf('Phone')));

        $this->add(new Kwf_Form_Field_Panel('payment_text'))
            ->setHtml('<p class="formText">'.trlKwf('What type of payment do you wish?').'</p>')
            ->setHideFieldWhenOnePayment(true)
            ->setHideFieldInBackend(true);
        $this->add(new Kwf_Form_Field_Radio('payment', trlKwf('Payment')))
            ->setHideFieldInBackend(true)
            ->setHideFieldWhenOnePayment(true)
            ->setAllowBlank(false);

        $this->add(new Kwf_Form_Field_TextArea('comment', trlKwf('Other comments, questions or suggestions')))
            ->setHeight(80)
            ->setWidth(200);
    }

    public function setPayments($payments)
    {
        $this->_payments = $payments;
        $this->fields['payment']->setValues($payments);
        if (count($payments) == 1) {
            foreach ($this->fields as $f) {
                if ($f->getHideFieldWhenOnePayment()) {
                    $this->fields->remove($f);
                }
            }
        }
        return $this;
    }


    protected function _beforeSave(Kwf_Model_Row_Interface $row)
    {
        parent::_beforeSave($row);
        if (count($this->_payments) == 1) {
            $payments = array_keys($this->_payments);
            $row->payment = $payments[0];
        }
    }
}
<commit_msg>don't allow sending orders with empty cart<commit_after><?php
class Kwc_Shop_Cart_Checkout_Form_FrontendForm extends Kwf_Form
{
    protected $_modelName = 'Kwc_Shop_Cart_Orders';
    private $_payments;

    protected function _initFields()
    {
        parent::_initFields();

        $this->setCartEmptyMessage(trlKwfStatic("Can't submit order because the cart is empty."));

        $this->add(new Kwf_Form_Field_Panel('intro_text'))
            ->setHtml('<h1>'.trlKwf('Please enter your address').'</h1>')
            ->setHideFieldInBackend(true);
        $this->add(new Kwf_Form_Field_Radio('sex', trlcKwf('sex', 'Title')))
            ->setValues(array(
                'male'   => trlKwf('Mr.'),
                'female' => trlKwf('Ms.')
            ))
            ->setAllowBlank(false);
        $this->add(new Kwf_Form_Field_TextField('title', trlKwf('Title')));
        $this->add(new Kwf_Form_Field_TextField('firstname', trlKwf('First name')))
            ->setAllowBlank(false);
        $this->add(new Kwf_Form_Field_TextField('lastname', trlKwf('Last name')))
            ->setAllowBlank(false);
        $this->add(new Kwf_Form_Field_TextField('street', trlKwf('Street')))
            ->setAllowBlank(false);
        $this->add(new Kwf_Form_Field_TextField('zip', trlKwf('ZIP')))
            ->setAllowBlank(false);
        $this->add(new Kwf_Form_Field_TextField('city', trlKwf('City')))
            ->setAllowBlank(false);
        $this->add(new Kwf_Form_Field_SelectCountry('country', trlKwf('Country')))
            ->setDefaultValue('AT')
            ->setAllowBlank(false);
        $this->add(new Kwf_Form_Field_TextField('email', trlKwf('E-Mail')))
            ->setVtype('email')
            ->setAllowBlank(false);
        $this->add(new Kwf_Form_Field_TextField('phone', trlKwf('Phone')));

        $this->add(new Kwf_Form_Field_Panel('payment_text'))
            ->setHtml('<p class="formText">'.trlKwf('What type of payment do you wish?').'</p>')
            ->setHideFieldWhenOnePayment(true)
            ->setHideFieldInBackend(true);
        $this->add(new Kwf_Form_Field_Radio('payment', trlKwf('Payment')))
            ->setHideFieldInBackend(true)
            ->setHideFieldWhenOnePayment(true)
            ->setAllowBlank(false);

        $this->add(new Kwf_Form_Field_TextArea('comment', trlKwf('Other comments, questions or suggestions')))
            ->setHeight(80)
            ->setWidth(200);
    }

    protected function _getTrlProperties()
    {
        $ret = parent::_getTrlProperties();
        $ret[] = 'cartEmptyMessage';
        return $ret;
    }

    public function setPayments($payments)
    {
        $this->_payments = $payments;
        $this->fields['payment']->setValues($payments);
        if (count($payments) == 1) {
            foreach ($this->fields as $f) {
                if ($f->getHideFieldWhenOnePayment()) {
                    $this->fields->remove($f);
                }
            }
        }
        return $this;
    }


    protected function _beforeSave(Kwf_Model_Row_Interface $row)
    {
        parent::_beforeSave($row);
        if (count($this->_payments) == 1) {
            $payments = array_keys($this->_payments);
            $row->payment = $payments[0];
        }
    }


    public function validate($parentRow, array $postData = array())
    {
        $ret = parent::validate($parentRow, $postData);
        $row = $this->getRow($parentRow);
        if (!count($row->getChildRows('Products'))) {
            $ret[] = array(
                'field' => null,
                'messages' => array(
                    $this->getCartEmptyMessage()
                )
            );
        }
        return $ret;
    }
}

{'fraction_non_alphanumeric': 0.15572176514584893, 'fraction_numerical': 0.0029917726252804786, 'mean_word_length': 2.457083764219235, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 111, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7310385', 'n_tokens_mistral': 2181, 'n_tokens_neox': 2072, 'n_words': 297}