<commit_before><?php

class ColoredProductVariations extends DataExtension{

	private static $many_many = array(
		"Images" => "Image"
	);

	private static $many_many_extraFields = array(
		'Images' => array(
			'ColorID' => "Int"
		)
	);

	function updateCMSFields(FieldList $fields){
		$fields->insertAfter(
			$gf = GridField::create("Images","Images",$this->owner->Images(),
				GridFieldConfig_RelationEditor::create()
					->removeComponentsByType("GridFieldAddNewButton")
					->removeComponentsByType("GridFieldEditButton")
					->removeComponentsByType("GridFieldDataColumns")
					->removeComponentsByType("GridFieldDeleteAction")
					->addComponent(
						$cols = new GridFieldEditableColumns()
					)
					->addComponent(new GridFieldDeleteAction(true))
			),
			"Image"
		);
		$displayfields = array(
			'Title' => array(
				'title' => 'Title',
				'field' => new ReadonlyField("Name")
			)				 
		);
		//add drop-down color selection
		$colors = $this->owner->getColors();
		if($colors->exists()){
			$displayfields['ColorID'] = function($record, $col, $grid) use ($colors){
				return new DropdownField($col,"Color",
					$colors->map('ID','Value')->toArray()
				);
			};
		}
		$cols->setDisplayFields($displayfields);
	}

	/**
	 * Get all the colors for this product
	 * @return DataList colored attribute values
	 */
	function getColors(){
		return ColoredProductAttributeValue::get()
			->innerJoin(
				"ProductVariation_AttributeValues",
				"ProductVariation_AttributeValues.ProductAttributeValueID = ".
					"ColoredProductAttributeValue.ID"
			)
			->innerJoin(
				"ProductVariation",
				"ProductVariation_AttributeValues.ProductVariationID = ".
					"ProductVariation.ID"
			)
			->filter("ProductID",$this->owner->ID);
	}
<commit_msg>FIX: allow leaving drop down blank when choosing colour for product image<commit_after><?php

class ColoredProductVariations extends DataExtension{

	private static $many_many = array(
		"Images" => "Image"
	);

	private static $many_many_extraFields = array(
		'Images' => array(
			'ColorID' => "Int"
		)
	);

	function updateCMSFields(FieldList $fields){
		$fields->insertAfter(
			$gf = GridField::create("Images","Images",$this->owner->Images(),
				GridFieldConfig_RelationEditor::create()
					->removeComponentsByType("GridFieldAddNewButton")
					->removeComponentsByType("GridFieldEditButton")
					->removeComponentsByType("GridFieldDataColumns")
					->removeComponentsByType("GridFieldDeleteAction")
					->addComponent(
						$cols = new GridFieldEditableColumns()
					)
					->addComponent(new GridFieldDeleteAction(true))
			),
			"Image"
		);
		$displayfields = array(
			'Title' => array(
				'title' => 'Title',
				'field' => new ReadonlyField("Name")
			)				 
		);
		//add drop-down color selection
		$colors = $this->owner->getColors();
		if($colors->exists()){
			$displayfields['ColorID'] = function($record, $col, $grid) use ($colors){
				return DropdownField::create($col,"Color",
					$colors->map('ID','Value')->toArray()
				)->setHasEmptyDefault(true);
			};
		}
		$cols->setDisplayFields($displayfields);
	}

	/**
	 * Get all the colors for this product
	 * @return DataList colored attribute values
	 */
	function getColors(){
		return ColoredProductAttributeValue::get()
			->innerJoin(
				"ProductVariation_AttributeValues",
				"ProductVariation_AttributeValues.ProductAttributeValueID = ".
					"ColoredProductAttributeValue.ID"
			)
			->innerJoin(
				"ProductVariation",
				"ProductVariation_AttributeValues.ProductVariationID = ".
					"ProductVariation.ID"
			)
			->filter("ProductID",$this->owner->ID);
	}

{'fraction_non_alphanumeric': 0.148424543946932, 'fraction_numerical': 0.0, 'mean_word_length': 4.2601744186046515, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 56, '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': '2742508', 'n_tokens_mistral': 1329, 'n_tokens_neox': 1086, 'n_words': 189}