itemdata = $binstack->get('items', ['itemid', 'catid', 'name', 'text1', 'qty', 'want', 'cost', 'price'], ['itemid' => $itemid]); $this->itemid = $itemid; $this->itemimages = $binstack->select('images', ['imagename', 'primary', 'imageid'], ['itemid' => $itemid, 'ORDER' => ['primary' => 'DESC']]); } function getId() { return $this->itemid; } function getPrice($customer = null) { global $database; $binprice = $this->itemdata['price']; if (!is_null($customer)) { if ($database->has('customer_pricing', ['AND' => ['itemid' => $this->itemid, 'customerid' => $customer]])) { return $database->get('customer_pricing', 'price', ['AND' => ['itemid' => $this->itemid, 'customerid' => $customer]]); } } return $binprice; } function getName() { return $this->itemdata['name']; } function getDescription() { return $this->itemdata['text1']; } function getQty() { return $this->itemdata['qty']; } function getWant() { return $this->itemdata['want']; } function getCategoryName() { global $binstack; return $binstack->get('items', ['[>]categories' => 'catid'], 'catname', ['itemid' => $this->itemid]); } function getCategoryId() { return $this->itemdata['catid']; } function getImageCount() { return count($this->itemimages); } function getPrimaryImage(): ItemImage { if (count($this->itemimages) > 0) { foreach ($this->itemimages as $i) { if ($i['primary'] == true) { return new ItemImage($i['imagename'], $i['imageid'], $i['primary'] == true, $this->itemid); } } $i = $this->itemimages[0]; return new ItemImage($i['imagename'], $i['imageid'], $i['primary'] == true, $this->itemid); } return null; } function getImages(): array { $images = []; foreach ($this->itemimages as $i) { $images[] = new ItemImage($i['imagename'], $i['imageid'], $i['primary'] == true, $this->itemid); } return $images; } } class ItemImage { private $url = ""; private $primary = false; private $imageid = 0; private $itemid = 0; function __construct(string $url, int $imageid, bool $primary, int $itemid) { $this->url = $url; $this->imageid = $imageid; $this->primary = $primary; $this->itemid = $itemid; } function getName(): string { return $this->url; } function getAbsoluteUrl(): string { global $SETTINGS; return $SETTINGS['binstack_image.php'] . "?i=" . $this->url; } function isPrimary(): bool { return $this->primary == true; } function getID(): int { return $this->imageid; } function getItemID(): int { return $this->itemid; } } class RenderItem { static function card(Item $item) { $id = $item->getId(); $name = $item->getName(); $catid = $item->getCategoryId(); $catname = $item->getCategoryName(); $price = $item->getPrice(); $image = ""; if ($item->getImageCount() > 0) { $image = '' . $name . ''; } /* $html = <<
$image
$name
$$price
END; */ $html = << $image
$name
$$price
END; return $html; } static function line(Item $item) { $id = $item->getId(); $name = $item->getName(); $catid = $item->getCategoryId(); $catname = $item->getCategoryName(); $price = $item->getPrice(); $image = ""; if ($item->getImageCount() > 0) { $image = '' . $name . ''; } $html = << $image

$name

$$price
END; return $html; } static function cart(Item $item, int $qty) { $id = $item->getId(); $name = $item->getName(); $catid = $item->getCategoryId(); $catname = $item->getCategoryName(); $price = $item->getPrice(); $linetotal = number_format($price * $qty, 2); $image = ""; if ($item->getImageCount() > 0) { $image = '' . $name . ''; } $html = << $image

$name

$$price
$$linetotal
END; return $html; } }