Bany Posted May 25, 2017 Share Posted May 25, 2017 Hola, buscando alguna forma de eliminar las imágenes de productos eliminados, encontré que alguien ofrecía este archivo: <?php // include(dirname(__FILE__).'/../config/config.inc.php'); if (!defined('_PS_VERSION_')) exit; class ImgCheck extends Module { public function __construct() { $this->name = 'imgcheck'; $this->tab = 'others'; $this->version = '1.0'; $this->author = 'Rob O\'Donnell'; $this->need_instance = 0; // $this->ps_versions_compliancy = array('min' => '1.5', 'max' => '1.5'); $this->dependencies = array('blockcart'); parent::__construct(); $this->displayName = $this->l('Image Check'); $this->description = $this->l('Helps Rob delete thumbnail sized first images.'); $this->confirmUninstall = $this->l('Are you sure you want to uninstall?'); // if (!Configuration::get('MYMODULE_NAME')) // $this->warning = $this->l('No name provided'); } // this also works, and is more future-proof public function install() { if (parent::install() == false) return false; return true; } public function uninstall() { if (!parent::uninstall() || !Configuration::deleteByName('MYMODULE_NAME')) return false; return true; } public function getContent() { $go = Tools::getValue('go'); $sql = 'SELECT i.`id_image` as id1, i2.`id_image` as id2, p.`id_product` as id_product FROM `ps_image` i ' . Shop::addSqlAssociation('image', 'i').' LEFT JOIN `ps_image` i2 on i2.id_image = i.id_image + 1 left outer join ps_product p on p.id_product = i.id_product WHERE i.id_product = i2.id_product AND i.cover = 1 AND i.position = 1 AND p.id_shop_default = 1 '; $results = Db::getInstance()->ExecuteS($sql); $form = ''; if (empty($go)) { $form .= '<form method="POST" action="#">'; $form .= '<input type="hidden" name="go" value="go">'; $form .= '<table>'; foreach ($results as $key => $row) { $form .= '<tr>'; $form .= '<td>' . $row['id_product'] . '</td>'; $image1 = new Image($row['id1']); $image2 = new Image($row['id2']); $image1link = self::_getPictureLink($row['id_product'], $row['id1'], null, 'large'); $image2link = self::_getPictureLink($row['id_product'], $row['id2'], null, 'large'); $form .= '<td><img src="' . $image1link . '" width="150"><br>' . '</td>'; $form .= '<td><img src="' . $image2link . '" width="150"><br>' . '</td>'; $form .= '<td><input type="checkbox" name="im' . $row['id1'] . '" checked>'; $form .= '<input type="hidden" name="pr' . $row['id1'] . '" value="' . $row['id_product'] . '">'; $form .= '</td>'; $form .= '</tr>'; } $form .= '</table>'; $form .= '<input type="submit">'; } else { foreach ($results as $key => $row) { if (Tools::getValue('im' . $row['id1'])) { $form .= "<br/>Deleting image " . $row['id1'] . ' for product ' . $row['id_product'] ; $image = new Image($row['id1']); $image->delete(); $image2 = new Image($row['id2']); $image2->cover = 1; if (!$image2->update()) $form .= ' - FAILED'; } } } return $form; } private function _getPictureLink($id_product, $id_image, $context_link, $size, $id_shop = null) { // Fix for payment modules validating orders out of context, $link will not generate fatal error. $link = is_object($context_link) ? $context_link : new Link(); $prefix = (substr(_PS_VERSION_, 0, 3) == '1.3' ? Tools::getShopDomain(true, false, $id_shop) . '/' : ''); } } ?> Perdonad mi ignorancia, pero, ¿eso sirve realmente para eliminar las imágenes de los productos ya eliminados? Un saludo imgcheck.zip Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now