예제 #1
0
    /**
     * Delete an option and everything related to it
     *
     * @param	void
     * @return	void
     */
    public function delete()
    {
        // Delete the option record
        $sql = 'DELETE FROM `#__storefront_options` WHERE `oId` = ' . $this->db->quote($this->getId());
        $this->db->setQuery($sql);
        //print_r($this->db->replacePrefix($this->db->getQuery()));
        $this->db->query();
        // Find all SKUs that use this option before removing all references
        $sql = 'SELECT o.`sId` FROM `#__storefront_sku_options` o
				LEFT JOIN `#__storefront_skus` s ON o.`sId` = s.`sId`
				WHERE o.`oId` = ' . $this->db->quote($this->getId());
        $sql .= ' AND s.`sActive` = 1';
        $this->db->setQuery($sql);
        $sIds = $this->db->loadColumn();
        // Delete the SKU-option relation
        $sql = 'DELETE FROM `#__storefront_sku_options` WHERE `oId` = ' . $this->db->quote($this->getId());
        $this->db->setQuery($sql);
        //print_r($this->db->replacePrefix($this->db->getQuery()));
        $this->db->query();
        // Update dependencies, disable SKUs that became invalid
        $skusDisabled = false;
        foreach ($sIds as $sId) {
            $sku = new Sku($sId);
            if ($sku->getActiveStatus()) {
                try {
                    $sku->verify();
                } catch (\Exception $e) {
                    $sku->unpublish();
                    $skusDisabled = true;
                }
            }
        }
        if ($skusDisabled) {
            $this->addMessage('Some SKUs were unpublished because of the recent update. Check each SKU to fix the issues.');
        }
    }