I'm working on plugin that make extension for Ideas Shop. My problem is that I've had added some new fields to Product model in my extension plugin but this fields is not working with operations like update or creating some new product because the structure is that data from products controller are sending to Ideas\Shop\Facades\Product method saveProductData() and then they are saving in Ideas\Shop\Models\Products model. My question is how can I override the saveProductData() in my plugin extension.
namespace Ideas\Shop\Controllers;
//class Products extends IdeasShopController
/**
* Override create_onSave()
*/
public function create_onSave()
{
$post = post();
$rs = ProductFacades::saveProduct($post);
if ($rs['rs'] != IdeasShop::SUCCESS) {
Flash::error($rs['msg'][0]);//save flash in next refresh
} else {
$url = $this->handleSaveResult($rs, $post, 'create');
return redirect($url);
}
}
/**
* Override update_onSave()
*/
public function update_onSave()
{
$post = post();
$rs = ProductFacades::saveProduct($post);
if ($rs['rs'] != IdeasShop::SUCCESS) {
Flash::error($rs['msg'][0]);//save flash in next refresh
} else {
$url = $this->handleSaveResult($rs, $post, 'update');
return redirect($url);
}
}
In this model is method that I want override in my plugin extensions...
namespace Ideas\Shop\Facades;
//class Product extends Model
public static function saveProductData($post)
{
$id = $post['id'];
$model = new Products();
if ($id != 0) {//create
$model = Products::find($id);
}
$product = $post['Products'];
$model->name = $product['name'];
$model->slug = $product['slug'];
$model->sku = $product['sku'];
$model->price = $product['price'];
$model->price_promotion = $product['price_promotion'];
$model->qty = $product['qty'];
if ($id == 0) {
$model->qty_order = 0;
}
$model->featured_image = $product['featured_image'];
$model->product_order = $product['product_order'];
if ($id == 0) {//create
$model->product_type = $product['product_type'];
$model->attribute_group_id = $product['attribute_group_id'];
}
$model->tax_class_id = $product['tax_class_id'];
$model->weight = $product['weight'];
$model->weight_id = $product['weight_id'];
$model->status = $product['status'];
$model->is_virtual_product = $product['is_virtual_product'];
$model->save();
return $model;
}
And this is model that is used for saving data from product to database
namespace Ideas\Shop\Models;
class Products extends Model
{
...
}