PHP code example of genaker / laragento

1. Go to this page and download the library: Download genaker/laragento library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

genaker / laragento example snippets


class ProductSimple extends CatalogProductEntity
{
   public static function boot()
    {
        parent::boot();

        static::addGlobalScope(function ($query) {
            $query->where('type_id', 'simple');
        });
    }
    
   public function getBySku(string $sku) {
        $this->where('sku', $sku);
   }
}



$params = array(
    'database'  => 'database_name',
    'username'  => 'username',
    'password'  => 'pa$$word',
    'prefix'    => '' 
);
Laragento\DB::connect($params);

	$conf = conf["db"]["connection"]["default"]; 
	$host = $db["host"];
	$user = $db["username"];
	$password = $db["password"];
	$dbname = $db["dbname"];

	$params = array(
		'host' => $db["host"],
		'database' => $dbname,
		'username' => $user,
		'password' => $password,
		'prefix' => '' 
	);
   
   Laragento\DB::connect($params);

php -r '$x = 



$orders = Laragento\Models\SalesOrder::whereNull('sync_status')->with('sales_order_items', 'sales_invoices', 'sales_order_payments', 'sales_creditmemos', 'sales_order_addresses', 'sales_shipments', 'customer_entity', 'sales_payment_transactions')->get();
 
foreach ($oreders as $order) {
    $response = $erp->orderAPI($order->toJson());
    if ($response->responseCode === 200) {
        $order->sync_status = 'sent_to_erp';
        $order->save();
    } else {
        echo "Error";
    }
}


public function __construct(User $user)
{
    $this->user = $user;
}

$user = $this->user->find(1);
var_dump($user->name);

# After This
s



namespace App\Providers;

use Illuminate\Support\Facades\DB;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        DB::listen(function ($query) {
           var_dump(
                $query->sql,
                $query->bindings,
                $query->time
            );
        });
    }

    /**
     * Register the service provider.
     *
     * @return void
     */
    public function register()
    {
        //
    }
}