Created
February 18, 2017 21:14
-
-
Save bummzack/a9bb2dd8949a38cf0299bbbb7b7ad666 to your computer and use it in GitHub Desktop.
silvershop – User customisable OrderItem field
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Extension to add custom field to AddProductForm and VariationForm | |
*/ | |
class AddProductFormExtension extends Extension | |
{ | |
public function updateAddProductForm() | |
{ | |
// Add a new Textfield to the form-fields | |
$this->owner->Fields()->add(TextField::create('Inscription')); | |
// tell the form that there's extra savable data that should be put into the OrderItem | |
$this->owner->setSaveableFields([ | |
'Inscription' | |
]); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Product_OrderItem: | |
required_fields: | |
- Inscription # This tells the cart, that this field is also needed to determine uniqueness of an OrderItem | |
extensions: | |
- InscriptionExtension # Add the extension | |
AddProductForm: | |
extensions: | |
- AddProductFormExtension |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Extension meant to be applied to Product_OrderItem | |
*/ | |
class InscriptionExtension extends DataExtension | |
{ | |
// Add a custom field | |
private static $db = [ | |
'Inscription' => 'Varchar(255)' | |
]; | |
// Optional update title hook that will just add the Inscription text to the title. | |
public function updateTableTitle(&$title) { | |
if ($this->owner->Inscription) { | |
$title = "$title, with Inscription: " . $this->owner->Inscription; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Life saver :) cheers