I have a hook that inserts an extra field in the Language Specific tab of Product and all seems to work as expected - Yay!
However, I would be very grateful if anyone can point out any fundamental error with my logic in the file.
Code: Select all
<?php
class hook_admin_catalog_productSpecification {
public function listen_productActionSave() {
if (isset($_GET['pID'])) {
$products_id = Text::input($_GET['pID']);
}
foreach (language::load_all() as $l) {
$sql_data = Text::prepare($_POST['products_specification'][$l['id']]);
$GLOBALS['db']->query("UPDATE products_description SET products_specification = '" . $GLOBALS['db']->escape($sql_data) . "' WHERE products_id = '" . (int)$products_id . "' AND language_id = '" . (int)$l['id'] . "'");
}
}
public function listen_updateProductAction() {
$this->listen_productActionSave();
}
public function listen_insertProductAction() {
$this->listen_productActionSave();
}
public function listen_injectLanguageForm() {
if (isset($_GET['pID']) && empty($_POST)) {
$product = product_by_id::administer($_GET['pID']);
$translations = $product->get('translations');
}
foreach (language::load_all() as $l) {
?>
<div class="card-body">
<div class="form-group row" id="zProductSpecification<?= $l['directory'] ?>">
<label for="pSpec" class="col-form-label col-sm-3 text-left text-sm-right"><?php echo 'PRODUCT_SPECIFICATIONS'; ?></label>
<div class="col-sm-9">
<?= (new Textarea("products_specification[{$l['id']}]", ['id' => 'pSpec', 'cols' => '70', 'rows' => '15']))->require()->set_text($translations[$l['id']]['specification']) ?>
</div>
</div>
</div>
<?php
}
}
}
?>