Last active
December 17, 2015 22:09
-
-
Save KB1RMA/5679614 to your computer and use it in GitHub Desktop.
This file contains 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 | |
public function subscribeEvents() { | |
Backend::$events->addEvent('shop:onExtendProductModel', $this, 'extend_product_model'); | |
Backend::$events->addEvent('shop:onExtendProductForm', $this, 'extend_product_form'); | |
Backend::$events->addEvent('shop:onOverrideProductCsvExportColumns', $this, 'set_product_csv_export_columns'); | |
Backend::$events->addEvent('shop:onOverrideProductCsvImportData', $this, 'set_product_csv_import_data'); | |
} | |
public function extend_product_model($product) { | |
$product->add_relation('belongs_to', 'artist', array( | |
'class_name' => 'StaveArtists_Artist', | |
'foreign_key' => 'x_artist' | |
)); | |
$product->define_relation_column('artist', 'artist', 'Artist', db_varchar, "concat(@last_name, ', ', @first_name)"); | |
} | |
public function extend_product_form($product) { | |
$product->add_form_field('artist', 'left')->tab('Puzzles')->emptyOption('<no artist selected>'); | |
} | |
public function set_product_csv_export_columns($row_data) { | |
$result = array('artist'=>null); | |
if (!isset($row_data['x_artist'])) | |
return $result; | |
if (!strlen($row_data['x_artist'])) | |
return $result; | |
$result['artist'] = $row_data['x_artist']; | |
return $result; | |
} | |
public function set_product_csv_import_data($row_data) { | |
$result = array( | |
'warnings' => array(), | |
'data' => array('x_artist' => null) | |
); | |
if (!isset($row_data['artist'])) | |
return $result; | |
if (!strlen($row_data['artist'])) | |
return $result; | |
$artist = StaveArtists_Artist::create()->find($row_data['artist']); | |
if (!$artist) { | |
$result['warnings'][] = sprintf('Artist "%s" is not found.', $row_data['artist']); | |
return $result; | |
} | |
$result['data']['x_artist'] = $row_data['artist']; | |
return $result; | |
} | |
?> |
This file contains 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
CREATE TABLE staveartists_artists ( | |
id int(11) NOT NULL auto_increment, | |
created_at datetime default NULL, | |
updated_at datetime default NULL, | |
created_user_id int(11) default NULL, | |
updated_user_id int(11) default NULL, | |
last_name varchar(50) NOT NULL default '', | |
first_name varchar(50) NOT NULL default '', | |
featured tinyint(1) NOT NULL default 0, | |
PRIMARY KEY (id) | |
); | |
ALTER TABLE shop_products ADD column x_artist int; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment