<commit_before><?php

/**
 * @package shop
 */
class VariationForm extends AddProductForm
{
    public static $include_json = true;

    public function __construct($controller, $name = "VariationForm")
    {
        parent::__construct($controller, $name);

        $product = $controller->data();
        $farray = array();
        $requiredfields = array();
        $attributes = $product->VariationAttributeTypes();

        foreach ($attributes as $attribute) {
            $attributeDropdown = $attribute->getDropDownField(
                _t(
                    'VariationForm.ChooseAttribute',
                    "Choose {attribute} …",
                    '',
                    array('attribute' => $attribute->Label)
                ),
                $product->possibleValuesForAttributeType($attribute)
            );

            if($attributeDropdown){
                $farray[] = $attributeDropdown;
                $requiredfields[] = "ProductAttributes[$attribute->ID]";
            }
        }

        $fields = FieldList::create($farray);

        if (self::$include_json) {
            $vararray = array();

            $query = $query2 = new SQLQuery();

            $query->setSelect('ID')
                ->setFrom('ProductVariation')
                ->addWhere(array('ProductID' => $product->ID));

            if (!Product::config()->allow_zero_price) {
                $query->addWhere('"Price" > 0');
            }

            foreach ($query->execute()->column('ID') as $variationID) {
                $query2->setSelect('ProductAttributeValueID')
                    ->setFrom('ProductVariation_AttributeValues')
                    ->setWhere(array('ProductVariationID' => $variationID));
                $vararray[$variationID] = $query2->execute()->keyedColumn();
            }

            $fields->push(
                HiddenField::create(
                    'VariationOptions',
                    'VariationOptions',
                    json_encode($vararray)
                )
            );
        }

        $fields->merge($this->Fields());

        $this->setFields($fields);
        $requiredfields[] = 'Quantity';

        $this->setValidator(
            VariationFormValidator::create(
                $requiredfields
            )
        );

        $this->extend('updateVariationForm');
    }

    /**
     * Adds a given product to the cart. If a hidden field is passed
     * (ValidateVariant) then simply a validation of the user including that<commit_msg>VariationForm fields had no form value set<commit_after><?php

/**
 * @package shop
 */
class VariationForm extends AddProductForm
{
    public static $include_json = true;

    public function __construct($controller, $name = "VariationForm")
    {
        parent::__construct($controller, $name);

        $product = $controller->data();
        $farray = array();
        $requiredfields = array();
        $attributes = $product->VariationAttributeTypes();

        foreach ($attributes as $attribute) {
            $attributeDropdown = $attribute->getDropDownField(
                _t(
                    'VariationForm.ChooseAttribute',
                    "Choose {attribute} …",
                    '',
                    array('attribute' => $attribute->Label)
                ),
                $product->possibleValuesForAttributeType($attribute)
            );

            if($attributeDropdown){
                $farray[] = $attributeDropdown;
                $requiredfields[] = "ProductAttributes[$attribute->ID]";
            }
        }

        $fields = FieldList::create($farray);

        if (self::$include_json) {
            $vararray = array();

            $query = $query2 = new SQLQuery();

            $query->setSelect('ID')
                ->setFrom('ProductVariation')
                ->addWhere(array('ProductID' => $product->ID));

            if (!Product::config()->allow_zero_price) {
                $query->addWhere('"Price" > 0');
            }

            foreach ($query->execute()->column('ID') as $variationID) {
                $query2->setSelect('ProductAttributeValueID')
                    ->setFrom('ProductVariation_AttributeValues')
                    ->setWhere(array('ProductVariationID' => $variationID));
                $vararray[$variationID] = $query2->execute()->keyedColumn();
            }

            $fields->push(
                HiddenField::create(
                    'VariationOptions',
                    'VariationOptions',
                    json_encode($vararray)
                )
            );
        }

        $fields->merge($this->Fields());

        $this->setFields($fields);
        $fields->setForm($this);
        $requiredfields[] = 'Quantity';

        $this->setValidator(
            VariationFormValidator::create(
                $requiredfields
            )
        );

        $this->extend('updateVariationForm');
    }

    /**
     * Adds a given product to the cart. If a hidden field is passed
     * (ValidateVariant) then simply a validation of the user including that
{'fraction_non_alphanumeric': 0.13138256087981146, 'fraction_numerical': 0.0015710919088766694, 'mean_word_length': 1.7220737573490112, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 62, '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': '4614071', 'n_tokens_mistral': 1299, 'n_tokens_neox': 1220, 'n_words': 224}