Example #1
0
 public function setProduct($value)
 {
     $product = Product::findById($value);
     if ($product) {
         $this->_orm->product_id = $product->id;
         return true;
     }
     return false;
 }
Example #2
0
 public function as_array()
 {
     $model = $this->_orm->as_array();
     $model['new_product'] = Product::findById($this->new_product_id)->name;
     $model['old_product'] = Product::findById($this->old_product_id)->name;
     $model['order'] = OrderItem::findById($this->item_id)->order->id;
     $model['user'] = OrderItem::findById($this->item_id)->order->user->profile->fullname;
     return $model;
 }
Example #3
0
 public function setProduct($value)
 {
     if ($value instanceof Product) {
         $this->_orm->product_id = $value->id;
         return true;
     }
     $product = Product::findById($value);
     if ($product) {
         $this->_orm->product_id = $product->id;
         return true;
     }
     throw new Exception("Product does not exist");
 }
Example #4
0
 public static function alternative()
 {
     return function ($request, $response) {
         $product_id = $request->id;
         $prod = Product::findById($product_id);
         if ($prod) {
             $brand = $prod->brand;
             $prods = $brand->products;
             $response->json($prods->as_array());
         } else {
             $response->code(404);
         }
     };
 }
Example #5
0
<div id="item_info">
	<fieldset>
		<legend>Items Bought</legend>
		
		<div id="items">
			<table>
				<tr>
					<th>Product</th>
					<th>Quantity</th>
					<th>Price</th>
				</tr>
				<?php 
if ($variants) {
    foreach ($variants as $variant) {
        $product = Product::findById($variant['product_id']);
        ?>
						<tr>
							<td><?php 
        echo $product->title . ' (' . $variant['title'] . ')';
        ?>
</td>
							<td align="center"><?php 
        echo $variant['quantity'];
        ?>
</td>
							<td align="center">$<?php 
        echo $variant['price'];
        ?>
</td>
						</tr><?php 
Example #6
0
    $data = $req->data();
    $model = Profile::create($data);
    $res->json($model->as_array());
});
respond('/brand/[i:id].json', BrandCtrl::get());
respond('GET', '/brand/all.json', BrandCtrl::index());
respond('POST', '/brand/new.json', BrandCtrl::add());
respond('/category/[i:id].json', CategoryCtrl::get());
respond('GET', '/category/all.json', CategoryCtrl::index());
respond('POST', '/category/new.json', CategoryCtrl::add());
respond('/company/[i:id].json', CompanyCtrl::get());
respond('POST', '/company/new.json', CompanyCtrl::add());
respond('GET', '/company/all.json', CompanyCtrl::index());
respond('/product/[i:id].json', function ($req, $res) {
    //$res->header('Content-Type', 'application/json');
    $model = Product::findById($req->id);
    if ($model) {
        if ($req->method('post')) {
            $data = $req->data();
            $model->update($data);
            $model->save();
            $res->json($model->as_array());
        } elseif ($req->method('delete')) {
            $model->delete();
            $res->code(200);
        } else {
            $res->json($model->as_array());
        }
    } else {
        $res->code(404);
    }
Example #7
0
<?php

include 'layout/_header.php';
if (!empty($_GET['productId'])) {
    include_once 'tools.php';
    $prodObj = new Product();
    $product = $prodObj->findById($connect, $_GET['productId']);
    if (!empty($product)) {
        ?>
        <h4> Are you sure want to delete this product?</h4>
        <form action='' method=post>
            <input type="hidden" name="id" id="id" value="<?php 
        echo empty($product) ? '' : $product->id;
        ?>
"/>
            <input class="button button-yes" type=submit name='btnYes' value='Yes'>
            <input class="button button-no" type=submit name='btnNo' value='No'>

        </form>
        <?php 
    }
    if ($_SERVER['REQUEST_METHOD'] === 'POST') {
        if (isset($_POST['btnYes'])) {
            $prodObj->delete($_POST['id'], $connect);
        }
        header("Location: /");
        return;
    }
    $connect->close();
} else {
    echo '<h4>Error: No product to delete</h4>';
 public function product_update($id = null)
 {
     if (is_null($id)) {
         redirect(get_url('plugin/ecommerce'));
     }
     if (!($product = Product::findById($id))) {
         Flash::set('error', __('Product not found!'));
         redirect(get_url('plugin/ecommerce'));
     }
     if (get_request_method() == 'POST') {
         //get new type id if a new one was created
         if ($_POST['product_type']['title']) {
             //save type
             $type_id = $this->_product_save(null, 'product_type', 'ProductType');
             $_POST['product']['type_id'] = $type_id;
             //add new type page
             $page_data = array("is_protected" => 1, "parent_id" => 87, "title" => $_POST['product_type']['title'], "slug" => $_POST['product_type']['slug'], "breadcrumb" => $_POST['product_type']['title']);
             $page = new Page($page_data);
             $page->save();
         }
         //get new vendor id if a new one was created
         if ($_POST['product_vendor']['title']) {
             //save vendor
             $vendor_id = $this->_product_save(null, 'product_vendor', 'ProductVendor');
             $_POST['product']['vendor_id'] = $vendor_id;
             //add new vendor page
             $page_data = array("is_protected" => 1, "parent_id" => 86, "title" => $_POST['product_vendor']['title'], "slug" => $_POST['product_vendor']['slug'], "breadcrumb" => $_POST['product_vendor']['title']);
             $page = new Page($page_data);
             $page->save();
         }
         //save product
         $product_id = $this->_product_save($id, 'product', 'Product');
         //insert log
         $this->_insert_log('Product <a href="' . get_url('plugin/ecommerce/product_update/' . $product_id) . '">' . $_POST['product']['title'] . '</a> was updated.');
         //save images
         if (isset($_SESSION['product_images'])) {
             $this->_images_save($product_id, $_SESSION['product_images']);
         }
         //save product page
         $product = Product::findById($id);
         if ($product) {
             $page = Record::findByIdFrom('Page', $product->page_id);
             $page_data = array("is_protected" => 1, "title" => $_POST['product']['title'], "slug" => $_POST['product']['slug'], "breadcrumb" => $_POST['product']['title'], "created_on_time" => null, "published_on_time" => null);
             $page->setFromData($page_data);
             $page->save();
         }
         redirect(get_url('plugin/ecommerce/product'));
     }
     $types = ProductType::findAll();
     $vendors = ProductVendor::findAll();
     $images = Record::findAllFrom('ProductImage', 'product_id=? order by position', array($id));
     $variants = Record::findAllFrom('ProductVariant', 'product_id=? order by position', array($id));
     $files = Record::findAllFrom('ProductFile', 'product_id=? order by position', array($id));
     $videos = Record::findAllFrom('ProductVideo', 'product_id=? order by position', array($id));
     $this->display('ecommerce/views/products/update', array('action' => 'update', 'product' => $product, 'types' => $types, 'vendors' => $vendors, 'images' => $images, 'variants' => $variants, 'files' => $files, 'videos' => $videos));
 }