├── .gitignore ├── src └── Models │ ├── Alias.php │ ├── Stockstatus.php │ ├── AttributeDescription.php │ ├── Attribute.php │ ├── Store.php │ ├── ProductImage.php │ ├── ProductDescription.php │ ├── CategoryDescription.php │ ├── ManufacturerDescription.php │ ├── EloquentDbTree.php │ ├── Category.php │ ├── Manufacturer.php │ ├── Prefixable.php │ └── Product.php ├── composer.json └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | /vendor/ 2 | -------------------------------------------------------------------------------- /src/Models/Alias.php: -------------------------------------------------------------------------------- 1 | hasOne(AttributeDescription::class); 15 | } 16 | } -------------------------------------------------------------------------------- /src/Models/Store.php: -------------------------------------------------------------------------------- 1 | hasMany(Product::class, $this->prefix . 'product_to_category'); 15 | } 16 | } -------------------------------------------------------------------------------- /src/Models/ProductImage.php: -------------------------------------------------------------------------------- 1 | belongsTo(Product::class, 'product_id'); 15 | } 16 | } -------------------------------------------------------------------------------- /src/Models/ProductDescription.php: -------------------------------------------------------------------------------- 1 | belongsTo(Product::class, 'product_id'); 15 | } 16 | } -------------------------------------------------------------------------------- /src/Models/CategoryDescription.php: -------------------------------------------------------------------------------- 1 | belongsTo(Category::class, 'category_id'); 15 | } 16 | } -------------------------------------------------------------------------------- /src/Models/ManufacturerDescription.php: -------------------------------------------------------------------------------- 1 | belongsTo(Manufacturer::class); 15 | } 16 | } -------------------------------------------------------------------------------- /src/Models/EloquentDbTree.php: -------------------------------------------------------------------------------- 1 | find($this->parent_id); 9 | } 10 | 11 | public function scopeChildren($query) 12 | { 13 | return $query->where('parent_id', '=', $query->getModel()->getKey()); 14 | } 15 | 16 | public function scopeRoot($query) 17 | { 18 | return $query->where('parent_id', '=', 0); 19 | } 20 | } -------------------------------------------------------------------------------- /src/Models/Category.php: -------------------------------------------------------------------------------- 1 | hasOne(CategoryDescription::class, 'category_id'); 16 | } 17 | 18 | 19 | public function products() 20 | { 21 | return $this->belongsToMany(Product::class, $this->prefix . 'product_to_category'); 22 | } 23 | 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/Models/Manufacturer.php: -------------------------------------------------------------------------------- 1 | hasMany(Product::class); 15 | } 16 | 17 | public function description() 18 | { 19 | return $this->hasOne(ManufacturerDescription::class); 20 | } 21 | 22 | public function stores() 23 | { 24 | return $this->belongsToMany(Store::class, $this->prefix . 'product_to_store'); 25 | } 26 | 27 | } -------------------------------------------------------------------------------- /src/Models/Prefixable.php: -------------------------------------------------------------------------------- 1 | prefix = env('DB_PREFIX'); 16 | $this->table = $this->prefix . $this->table; 17 | 18 | if (!empty($attrs)) { 19 | parent::__construct($attrs); 20 | } else { 21 | parent::__construct(); 22 | } 23 | } 24 | 25 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Laracart 2 | 3 | This package provides a set of Eloquent ORM models for OpenCart entities. 4 | Using this package you can access your OpenCart database tables inside Laravel. 5 | 6 | ## Installation 7 | 8 | ``` 9 | composer require exfriend/laracart 10 | ``` 11 | 12 | Update your .env file (affects only Laracart): 13 | 14 | ``` 15 | DB_PREFIX=oc_ 16 | ``` 17 | 18 | ## Usage 19 | 20 | ``` 21 | use \Exfriend\Laracart\Models\Manufacturer; 22 | 23 | $manufacturer = Manufacturer::create([ 24 | 'name' => 'Canon', 25 | 'image' => 'catalog/demo/canon.jpg', 26 | 'sort_order' => 0 27 | ]); 28 | 29 | $manufacturer->description()->create([ 30 | 'name' => 'Canon', 31 | 'description' => 'Better than Nikon.' 32 | 'language_id' => 1 33 | ]); 34 | 35 | $manufacturer->stores()->attach(0); 36 | 37 | ``` 38 | 39 | ## Contributing 40 | 41 | This package is work in progress. Please submit your pull requests with new models. 42 | -------------------------------------------------------------------------------- /src/Models/Product.php: -------------------------------------------------------------------------------- 1 | hasOne(ProductDescription::class, 'product_id'); 20 | } 21 | 22 | public function images() 23 | { 24 | return $this->hasMany(ProductImage::class, 'product_id'); 25 | } 26 | 27 | public function manufacturer() 28 | { 29 | return $this->belongsTo(Manufacturer::class); 30 | } 31 | 32 | public function attributes() 33 | { 34 | return $this->belongsToMany(Attribute::class, $this->prefix . 'product_attribute'); 35 | } 36 | 37 | public function stores() 38 | { 39 | return $this->belongsToMany(Store::class, $this->prefix . 'product_to_store'); 40 | } 41 | 42 | public function categories() 43 | { 44 | return $this->belongsToMany(Category::class, $this->prefix . 'product_to_category', 'product_id', 45 | 'category_id'); 46 | } 47 | 48 | public function related() 49 | { 50 | return $this->belongsToMany(Product::class, $this->prefix . 'product_related', 51 | 'product_id', 'related_id'); 52 | } 53 | 54 | // ------------------------------------------------------------------- 55 | // --[ функции ]------------------------------------------------------ 56 | // ------------------------------------------------------------------- 57 | 58 | 59 | public function enable() 60 | { 61 | $this->status = 1; 62 | $this->save(); 63 | } 64 | 65 | public function disable() 66 | { 67 | $this->status = 0; 68 | $this->save(); 69 | } 70 | 71 | } 72 | --------------------------------------------------------------------------------