Пример #1
0
	public function afterDelete()
	{
		// Delete options
		foreach($this->options as $o)
			$o->delete();

		// Delete relations used in product type.
		EavTypeAttribute::model()->deleteAllByAttributes(array('attribute_id'=>$this->id));

		// Delete attributes assigned to products
		$conn = $this->getDbConnection();
		$command = $conn->createCommand("DELETE FROM eav_variants WHERE attribute_name='{$this->name}'");
		$command->execute();

		return parent::afterDelete();
	}
Пример #2
0
    /**
     * @param $attributes
     * @return bool
     */
    public function storeTypeAttributes(array $attributes)
    {
        $transaction = Yii::app()->getDb()->beginTransaction();

        try {

            EavTypeAttribute::model()->deleteAllByAttributes(['type_id' => $this->id]);

            foreach ($attributes as $attributeId) {
                $typeAttribute = new EavTypeAttribute();
                $typeAttribute->type_id = $this->id;
                $typeAttribute->attribute_id = (int)$attributeId;
                $typeAttribute->save();
            }

            $transaction->commit();

            return true;
        } catch (Exception $e) {
            $transaction->rollback();

            return false;
        }
    }