class Product
{
/**
* The remote URL used to fetch products
*/
const REMOTE = "https://vinspirard.be";
// const REMOTE = "http://localhost/pirard";
const AJAX_MULTIPLE = "pirard_get_products";
const BASEPATH = "produit";
public function __construct($product_name, $type = "basic")
{
// Get props from api/cache
switch ($type) {
case "full":
$single = json_decode((new Request(static::REMOTE . "/produit/{$product_name}/?json"))->get()->responseBody);
if (!empty($single->error)) return false;
$this->labels = $single->labels;
$this->carac = static::filterCarac(static::replaceUrlInCaracs($single->carac));
$this->avis = $single->avis;
$this->grower = $single->grower;
$this->related_title = $single->related_title;
$this->related = static::replaceUrlInProducts($single->related_products);
$product = $single->post;
break;
case "basic":
default:
$product = (new Cache("products/basic/{$product_name}"))->get(function () use ($product_name) {
return json_decode((new Request(static::REMOTE . "/api/getProduct/{$product_name}"))->get()->responseBody);
});
break;
}
if (!$product) return false;
// Spread props
foreach ($product as $prop=>$value) {
Arguments
"Trying to get property 'labels' of non-object"
class Product
{
/**
* The remote URL used to fetch products
*/
const REMOTE = "https://vinspirard.be";
// const REMOTE = "http://localhost/pirard";
const AJAX_MULTIPLE = "pirard_get_products";
const BASEPATH = "produit";
public function __construct($product_name, $type = "basic")
{
// Get props from api/cache
switch ($type) {
case "full":
$single = json_decode((new Request(static::REMOTE . "/produit/{$product_name}/?json"))->get()->responseBody);
if (!empty($single->error)) return false;
$this->labels = $single->labels;
$this->carac = static::filterCarac(static::replaceUrlInCaracs($single->carac));
$this->avis = $single->avis;
$this->grower = $single->grower;
$this->related_title = $single->related_title;
$this->related = static::replaceUrlInProducts($single->related_products);
$product = $single->post;
break;
case "basic":
default:
$product = (new Cache("products/basic/{$product_name}"))->get(function () use ($product_name) {
return json_decode((new Request(static::REMOTE . "/api/getProduct/{$product_name}"))->get()->responseBody);
});
break;
}
if (!$product) return false;
// Spread props
foreach ($product as $prop=>$value) {
Arguments
8
"Trying to get property 'labels' of non-object"
"/var/www/vhosts/vinspirard.hungryminds.host/espaces/wp-content/themes/syltaen/Models/API/Product.php"
24
array:3 [
"product_name" => "2019-rose-de-touraine-domaine-des-chezelles"
"type" => "full"
"single" => null
]
// On add-to-cart
if (isset($_POST["add-to-cart"])) {
$this->addToCart();
}
$this->data["product"] = $this->product;
$this->addBodyClass("single-product");
$this->setPageTitle(get_bloginfo("name") . " - " . $this->data["product"]->post_title);
}
/**
* Get the product from the remote API
*
* @param array $args
* @return void
*/
public function getProduct($args)
{
return new Product($args["product_name"], "full");
}
/**
* Add the product to the cart
*
* @return void
*/
public function addToCart()
{
$quantity = $_POST["quantity"] ?? 1;
// Add to cart
Cart::add($this->product->ID, $quantity);
// Success message
$success = $quantity > 1
? sprintf("%s × «%s» ont été ajoutés à votre panier.", $quantity, $this->product->post_title)
: sprintf("«%s» a été ajouté à votre panier.", $this->product->post_title);
Arguments
"2019-rose-de-touraine-domaine-des-chezelles"
"full"
<?php
namespace Syltaen;
class SingleProductController extends BaseController
{
public $view = "single-product";
/**
* Populate $this->data
*/
public function __construct($args = [])
{
parent::__construct($args);
$this->product = $this->getProduct($args);
$this->product->tags = $this->product->getTags();
// Product not found : error 404
if (empty($this->product->url)) {
(new PageController)->error404(); exit;
}
// Auto-empty grower if not completely filled
if (empty($this->product->grower->description) || empty($this->product->grower->img)) {
$this->product->grower = false;
}
// On add-to-cart
if (isset($_POST["add-to-cart"])) {
$this->addToCart();
}
$this->data["product"] = $this->product;
$this->addBodyClass("single-product");
$this->setPageTitle(get_bloginfo("name") . " - " . $this->data["product"]->post_title);
}
Arguments
array:1 [
"product_name" => "2019-rose-de-touraine-domaine-des-chezelles"
]
// Clear obsolete flash data
if (!$same_session_page) {
Data::goToNextSessionPage();
}
// Class method call
if (is_string($resp)) {
// Extracts method
$method = false;
if (preg_match('/(.*)::(.*)/', $resp, $keys)) {
$resp = $keys[1];
$method = $keys[2];
}
// Add namespace to class
$classname = "Syltaen\\$resp";
// Instanciate the class with the arguments
$class = new $classname($args);
// Lauch mehtod if any
if ($method) {
$class->$method();
}
}
// Closure function call
if (is_callable($resp)) {
$resp($args);
}
exit;
}
// ==================================================
// > RULES
// ==================================================
public static function any($resp, $args = [])
{
Arguments
array:1 [
"product_name" => "2019-rose-de-touraine-domaine-des-chezelles"
]
<?php
namespace Syltaen;
// ==================================================
// > SINGLES
// ==================================================
if (!empty(Route::qvar("product_name"))) {
Route::respond("SingleProductController::render", [
"product_name" => Route::qvar("product_name")
]);
}
if (!empty(Route::qvar("earlywine_name"))) {
Route::respond("SingleEarlyWineController::render", [
"earlywine_name" => Route::qvar("earlywine_name")
]);
}
Route::is("single", "SingleController::render");
// ==================================================
// > SEARCH
// ==================================================
Route::is("search", "PageController::search", ["search" => get_search_query(false)]);
// ==================================================
// > API
// ==================================================
Route::custom("api", "ApiController", ["method", "target", "mode"]);
// ==================================================
// > NINJA FORM PREVIEW
// ==================================================
Route::query("nf_preview_form", "PageController::ninjaFormPreview");
// ==================================================
// > PAGES
// ==================================================
Arguments
"SingleProductController"
array:1 [
"product_name" => "2019-rose-de-touraine-domaine-des-chezelles"
]
}
break;
}
}
if ( ! $template ) {
$template = get_index_template();
}
/**
* Filters the path of the current template before including it.
*
* @since 3.0.0
*
* @param string $template The path of the template to include.
*/
$template = apply_filters( 'template_include', $template );
if ( $template ) {
include $template;
} elseif ( current_user_can( 'switch_themes' ) ) {
$theme = wp_get_theme();
if ( $theme->errors() ) {
wp_die( $theme->errors() );
}
}
return;
}
Arguments
"/var/www/vhosts/vinspirard.hungryminds.host/espaces/wp-content/themes/syltaen/index.php"
<?php
/**
* Loads the WordPress environment and template.
*
* @package WordPress
*/
if ( ! isset( $wp_did_header ) ) {
$wp_did_header = true;
// Load the WordPress library.
require_once __DIR__ . '/wp-load.php';
// Set up the WordPress query.
wp();
// Load the theme template.
require_once ABSPATH . WPINC . '/template-loader.php';
}
Arguments
"/var/www/vhosts/vinspirard.hungryminds.host/espaces/wp-includes/template-loader.php"
<?php
/**
* Front to the WordPress application. This file doesn't do anything, but loads
* wp-blog-header.php which does and tells WordPress to load the theme.
*
* @package WordPress
*/
/**
* Tells WordPress to load the WordPress theme and output it.
*
* @var bool
*/
define( 'WP_USE_THEMES', true );
/** Loads the WordPress Environment and Template */
require __DIR__ . '/wp-blog-header.php';
Arguments
"/var/www/vhosts/vinspirard.hungryminds.host/espaces/wp-blog-header.php"