Example #1
0
 public function getSimilarProducts()
 {
     if ($this->similarProducts === null) {
         $this->similarProducts = Product::getAll(array('category_id' => $this->category_id, 'id!=' => $this->id));
     }
     return $this->similarProducts;
 }
Example #2
0
 public function indexAction()
 {
     $this->view->Title = "Quản lý sản phẩm";
     $this->view->headTitle($this->view->Title);
     $page = $this->getRequest()->getParam('page');
     $condition = array();
     list($this->view->Pager, $this->view->Product) = Product::getAll($condition, $page);
 }
 public function index()
 {
     $view = new View("product/index.php");
     $product = new Product();
     $productAll = $product->getAll();
     $view->set('productAll', $productAll);
     $view->output();
 }
 public function getProductoById($id)
 {
     $producto = new Product();
     $productos = $producto->getAll();
     foreach ($productos as $prod) {
         if ($prod->getId() == $id) {
             return $prod;
         }
     }
 }
 function testSave()
 {
     $product_sku = 123456789;
     $product_name = "deerhead";
     $product_img = "deer.jpg";
     $product_price = 99.98999999999999;
     $product_paypal = 11;
     $id = 1;
     $new_product = new Product($product_sku, $product_name, $product_img, $product_price, $product_paypal, $id = null);
     $new_product->save();
     $result = Product::getAll();
     $this->assertEquals($new_product, $result[0]);
 }
Example #6
0
 protected static function _getData()
 {
     if (count(self::$_dateRange) === 0) {
         $toDate = UDate::maxDate();
     } else {
         $toDate = self::$_dateRange['end'];
     }
     $return = array();
     $myobCodeType = ProductCodeType::get(ProductCodeType::ID_MYOB);
     foreach (Product::getAll(true) as $product) {
         $logs = ProductQtyLog::getAllByCriteria('productId = ? and created <= ?', array($product->getId(), trim($toDate)), true, 1, 1, array('id' => 'desc'));
         $log = count($logs) > 0 ? $logs[0] : null;
         $myobCodes = ProductCode::getCodes($product, $myobCodeType, true, 1, 1);
         $return[] = array('sku' => $product->getSku(), 'name' => $product->getName(), 'short description' => $product->getShortDescription(), 'category' => join(', ', array_map(create_function('$a', 'return $a->getCategory()->getName();'), $product->getCategories())), 'assetAccNo' => $product->getAssetAccNo(), 'revenueAccNo' => $product->getRevenueAccNo(), 'costAccNo' => $product->getCostAccNo(), 'Stock On PO' => $log instanceof ProductQtyLog ? $log->getStockOnPO() : $product->getStockOnPO(), 'Stock On Order' => $log instanceof ProductQtyLog ? $log->getStockOnOrder() : $product->getStockOnOrder(), 'Stock On Hand' => $log instanceof ProductQtyLog ? $log->getStockOnHand() : $product->getStockOnHand(), 'Total On Hand Value' => $log instanceof ProductQtyLog ? $log->getTotalOnHandValue() : $product->getTotalOnHandValue(), 'Stock In Parts' => $log instanceof ProductQtyLog ? $log->getStockInParts() : $product->getStockInParts(), 'Total In Parts Value' => $log instanceof ProductQtyLog ? $log->getTotalInPartsValue() : $product->getTotalInPartsValue(), 'Stock In RMA' => $log instanceof ProductQtyLog ? $log->getStockInRMA() : $product->getStockInRMA(), 'Total RMA Value' => $log instanceof ProductQtyLog ? $log->getTotalRMAValue() : $product->getTotalRMAValue(), 'active' => intval($product->getActive()) === 1 ? 'Y' : 'N', 'MYOB' => count($myobCodes) > 0 ? $myobCodes[0]->getCode() : '');
     }
     return $return;
 }
 /**
  *Test Bug with mass delete and multiple pages when using select all
  */
 public function testRegularMassDeletePagesProperlyAndRemovesAllSelected()
 {
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     $confused = User::getByUsername('confused');
     $nobody = User::getByUsername('nobody');
     //Load MassDelete view for the 6 products
     $products = Product::getAll();
     $this->assertEquals(9, count($products));
     //mass Delete pagination scenario
     //Run Mass Delete using progress save for page1
     $this->setGetArray(array('selectAll' => '1', 'Product_page' => 1));
     $this->setPostArray(array('selectedRecordCount' => 9));
     $pageSize = Yii::app()->pagination->getForCurrentUserByType('massDeleteProgressPageSize');
     $this->assertEquals(5, $pageSize);
     $content = $this->runControllerWithExitExceptionAndGetContent('products/default/massDelete');
     $products = Product::getAll();
     $this->assertEquals(4, count($products));
     //Run Mass Delete using progress save for page2
     $this->setGetArray(array('selectAll' => '1', 'Product_page' => 2));
     $this->setPostArray(array('selectedRecordCount' => 9));
     $pageSize = Yii::app()->pagination->getForCurrentUserByType('massDeleteProgressPageSize');
     $this->assertEquals(5, $pageSize);
     $content = $this->runControllerWithNoExceptionsAndGetContent('products/default/massDeleteProgress');
     $products = Product::getAll();
     $this->assertEquals(0, count($products));
 }
 /**
  * Walkthrough test for synchronous download
  */
 public function testAsynchronousDownloadDefaultControllerActions()
 {
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     $notificationsBeforeCount = Notification::getCount();
     $notificationMessagesBeforeCount = NotificationMessage::getCount();
     $products = Product::getAll();
     if (count($products)) {
         foreach ($products as $product) {
             $product->delete();
         }
     }
     $products = array();
     for ($i = 0; $i <= ExportModule::$asynchronousThreshold + 1; $i++) {
         $products[] = ProductTestHelper::createProductByNameForOwner('superProduct' . $i, $super);
     }
     $this->setGetArray(array('Product_page' => '1', 'export' => '', 'ajax' => '', 'selectAll' => '1', 'selectedIds' => ''));
     $this->runControllerWithRedirectExceptionAndGetUrl('products/default/export');
     // Start background job
     $job = new ExportJob();
     $this->assertTrue($job->run());
     $exportItems = ExportItem::getAll();
     $this->assertEquals(1, count($exportItems));
     $fileModel = $exportItems[0]->exportFileModel;
     $this->assertEquals(1, $exportItems[0]->isCompleted);
     $this->assertEquals('csv', $exportItems[0]->exportFileType);
     $this->assertEquals('products', $exportItems[0]->exportFileName);
     $this->assertTrue($fileModel instanceof ExportFileModel);
     $this->assertEquals($notificationsBeforeCount + 1, Notification::getCount());
     $this->assertEquals($notificationMessagesBeforeCount + 1, NotificationMessage::getCount());
     // Check export job, when many ids are selected.
     // This will probably never happen, but we need test for this case too.
     $notificationsBeforeCount = Notification::getCount();
     $notificationMessagesBeforeCount = NotificationMessage::getCount();
     // Now test case when multiple ids are selected
     $exportItems = ExportItem::getAll();
     if (count($exportItems)) {
         foreach ($exportItems as $exportItem) {
             $exportItem->delete();
         }
     }
     $selectedIds = "";
     foreach ($products as $product) {
         $selectedIds .= $product->id . ",";
         // Not Coding Standard
     }
     $this->setGetArray(array('ProductsSearchForm' => array('anyMixedAttributesScope' => array(0 => 'All'), 'anyMixedAttributes' => '', 'quantity' => ''), 'multiselect_ProductsSearchForm_anyMixedAttributesScope' => 'All', 'Product_page' => '1', 'export' => '', 'ajax' => '', 'selectAll' => '', 'selectedIds' => "{$selectedIds}"));
     $this->runControllerWithRedirectExceptionAndGetUrl('products/default/export');
     // Start background job
     $job = new ExportJob();
     $this->assertTrue($job->run());
     $exportItems = ExportItem::getAll();
     $this->assertEquals(1, count($exportItems));
     $fileModel = $exportItems[0]->exportFileModel;
     $this->assertEquals(1, $exportItems[0]->isCompleted);
     $this->assertEquals('csv', $exportItems[0]->exportFileType);
     $this->assertEquals('products', $exportItems[0]->exportFileName);
     $this->assertTrue($fileModel instanceof ExportFileModel);
     $this->assertEquals($notificationsBeforeCount + 1, Notification::getCount());
     $this->assertEquals($notificationMessagesBeforeCount + 1, NotificationMessage::getCount());
 }
Example #9
0
<?php

require_once 'model/Product.php';
require_once 'model/Shoppingcart.php';
require_once 'model/Purchase.php';
// Routes
// View HTML -> Index [Home]
$app->get('/', function ($request, $response, $args) {
    return $this->renderer->render($response, 'index.php', $args);
});
// REST
// Get Products
// Return array of products
$app->get('/products', function ($request, $response, $args) {
    return json_encode(Product::getAll());
});
// Get Product
// Return a specific product
$app->get('/product/{id}', function ($request, $response, $args) {
    return json_encode(Product::get($args['id']));
});
// Put Product
// Add product to the shopping cart
$app->put('/shoppingcart/{id}', function ($request, $response, $args) {
    Shoppingcart::addProduct($args['id']);
    return json_encode(Shoppingcart::countProducts());
});
// Get Shopping Cart
// Get detaills of the shopping cart
$app->get('/shoppingcart', function ($request, $response, $args) {
    return json_encode(Shoppingcart::getDetaills());
Example #10
0
<?php

include 'configs/configs.php';
$tmp = "images/productimg/";
$newProduct = Product::getAll();
//print_r($newProduct);
$smarty->assign('tmp', $tmp);
$smarty->assign('Product', $newProduct);
$smarty->display('managerproduct.tpl');
Example #11
0
     /** @var Category[] $parentCategories */
     $category = $c;
     // помимо текущей выбранной категории, нужно отображать товары из ее дочерних категорий
     $shownCategoryIds = array();
     if ($category) {
         $shownCategoryIds[] = $category->id;
         foreach ($category->getAllChildren() as $childCategory) {
             $shownCategoryIds[] = $childCategory->id;
         }
     }
     // определяем параметры выборки товаров
     $productCriteria = array();
     if (count($shownCategoryIds) > 0) {
         $productCriteria['category_id'] = $shownCategoryIds;
     }
     $products = Product::getAll($productCriteria, array('name' => true));
     if ($category === null) {
         $aprtData = array('pageType' => \Actionpay\APRT::PAGETYPE_MAIN);
     } else {
         $aprtData = array('pageType' => \Actionpay\APRT::PAGETYPE_CATALOG, 'currentCategory' => array('id' => $category->id, 'name' => $category->name), 'parentCategories' => array(), 'childCategories' => array());
         foreach ($category->getAllParents() as $parentCategory) {
             $aprtData['parentCategories'][] = array('id' => $parentCategory->id, 'name' => $parentCategory->name);
         }
         foreach ($category->getChildren() as $childCategory) {
             $aprtData['childCategories'][] = array('id' => $childCategory->id, 'name' => $childCategory->name);
         }
     }
     return $app->render('page_main', array('title' => $category ? $category->name : 'Главная', 'category' => $category, 'products' => $products, 'basket' => $app->session('basket') ?: array(), 'basketTotalItems' => $app->session('basketTotalItems') ?: 0, 'basketTotalPrice' => $app->session('basketTotalPrice') ?: 0, 'aprtData' => $aprtData));
 });
 /**
  * Запуск приложения, вывод ответа
 public function testSuperUserCreateFromRelationAction()
 {
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     $products = Product::getAll();
     $productsCount = count($products);
     $accountId = self::getModelIdByModelNameAndName('Account', 'superAccount');
     $contactId = self::getModelIdByModelNameAndName('Contact', 'superContact superContactson');
     $opportunityId = self::getModelIdByModelNameAndName('Opportunity', 'superOpportunity');
     //Create a new product from a related account.
     $this->setGetArray(array('relationAttributeName' => 'account', 'relationModelId' => $accountId, 'relationModuleId' => 'accounts', 'redirectUrl' => 'someRedirect'));
     $currency = new Currency();
     $currency->code = 'USD';
     $currency->rateToBase = 1;
     $currency->save();
     $currencyRec = Currency::getByCode('USD');
     $currencyValue1Array = array('currency' => array('id' => $currencyRec->id), 'value' => 500.54);
     $product['name'] = 'myUltraNewProduct';
     $product['quantity'] = 50;
     $product['priceFrequency'] = ProductTemplate::PRICE_FREQUENCY_ONE_TIME;
     $product['sellPrice'] = $currencyValue1Array;
     $product['type'] = ProductTemplate::TYPE_PRODUCT;
     $product['stage']['value'] = Product::OPEN_STAGE;
     $this->setPostArray(array('Product' => $product));
     $this->runControllerWithRedirectExceptionAndGetContent('products/default/createFromRelation');
     $products = Product::getByName('myUltraNewProduct');
     $this->assertEquals(1, count($products));
     $this->assertTrue($products[0]->id > 0);
     $this->assertTrue($products[0]->owner == $super);
     $this->assertEquals($accountId, $products[0]->account->id);
     $this->assertEquals('50', $products[0]->quantity);
     $this->assertEquals('500.54', $products[0]->sellPrice->value);
     $this->assertEquals(ProductTemplate::PRICE_FREQUENCY_ONE_TIME, $products[0]->priceFrequency);
     $this->assertEquals(ProductTemplate::TYPE_PRODUCT, $products[0]->type);
     $this->assertEquals(Product::OPEN_STAGE, $products[0]->stage->value);
     $products = Product::getAll();
     $this->assertEquals(++$productsCount, count($products));
     //Create a new product from a related contact.
     $this->setGetArray(array('relationAttributeName' => 'contact', 'relationModelId' => $contactId, 'relationModuleId' => 'contacts', 'redirectUrl' => 'someRedirect'));
     $product['name'] = 'myUltraNewProduct2';
     $product['quantity'] = 51;
     $product['priceFrequency'] = ProductTemplate::PRICE_FREQUENCY_ANNUALLY;
     $product['sellPrice'] = $currencyValue1Array;
     $product['type'] = ProductTemplate::TYPE_SERVICE;
     $product['stage']['value'] = Product::OPEN_STAGE;
     $this->setPostArray(array('Product' => $product));
     $this->runControllerWithRedirectExceptionAndGetContent('products/default/createFromRelation');
     $products = Product::getByName('myUltraNewProduct2');
     $this->assertEquals(1, count($products));
     $this->assertTrue($products[0]->id > 0);
     $this->assertTrue($products[0]->owner == $super);
     $this->assertEquals($accountId, $products[0]->account->id);
     $this->assertEquals($contactId, $products[0]->contact->id);
     $this->assertEquals('51', $products[0]->quantity);
     $this->assertEquals('500.54', $products[0]->sellPrice->value);
     $this->assertEquals(ProductTemplate::PRICE_FREQUENCY_ANNUALLY, $products[0]->priceFrequency);
     $this->assertEquals(ProductTemplate::TYPE_SERVICE, $products[0]->type);
     $this->assertEquals(Product::OPEN_STAGE, $products[0]->stage->value);
     $products = Product::getAll();
     $this->assertEquals(++$productsCount, count($products));
     //Create a new product from a related opportunity.
     $this->setGetArray(array('relationAttributeName' => 'opportunity', 'relationModelId' => $opportunityId, 'relationModuleId' => 'opportunities', 'redirectUrl' => 'someRedirect'));
     $product['name'] = 'myUltraNewProduct3';
     $product['quantity'] = 51;
     $product['priceFrequency'] = ProductTemplate::PRICE_FREQUENCY_ANNUALLY;
     $product['sellPrice'] = $currencyValue1Array;
     $product['type'] = ProductTemplate::TYPE_SERVICE;
     $product['stage']['value'] = Product::OPEN_STAGE;
     $this->setPostArray(array('Product' => $product));
     $this->runControllerWithRedirectExceptionAndGetContent('products/default/createFromRelation');
     $products = Product::getByName('myUltraNewProduct3');
     $this->assertEquals(1, count($products));
     $this->assertTrue($products[0]->id > 0);
     $this->assertTrue($products[0]->owner == $super);
     $this->assertEquals($accountId, $products[0]->account->id);
     $this->assertEquals($opportunityId, $products[0]->opportunity->id);
     $this->assertEquals('51', $products[0]->quantity);
     $this->assertEquals('500.54', $products[0]->sellPrice->value);
     $this->assertEquals(ProductTemplate::PRICE_FREQUENCY_ANNUALLY, $products[0]->priceFrequency);
     $this->assertEquals(ProductTemplate::TYPE_SERVICE, $products[0]->type);
     $this->assertEquals(Product::OPEN_STAGE, $products[0]->stage->value);
     $products = Product::getAll();
     $this->assertEquals(++$productsCount, count($products));
 }
Example #13
0
 /**
  * Return element of product as array associative
  *
  * @access public static
  * @param integer $id ID of the product
  * @return array | null
  */
 public static function get($id)
 {
     $products = Product::getAll();
     return isset($products[$id]) ? $products[$id] : null;
 }
Example #14
0
 public function testGetAllWhenThereAreNone()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     $products = Product::getAll();
     $this->assertEquals(1, count($products));
 }
 public function testCloningWithAnotherProduct()
 {
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     Yii::app()->user->userModel = $super;
     $product = ProductTestHelper::createProductByNameForOwner("My Product 1", $super);
     $id = $product->id;
     $this->setGetArray(array('id' => $id));
     $content = $this->runControllerWithNoExceptionsAndGetContent('products/default/copy');
     $this->assertContains('My Product 1', $content);
     $products = Product::getAll();
     $this->assertEquals(1, count($products));
 }
Example #16
0
 /**
  * Return a string containing the admin interface for the EComm Module
  *
  * @return string
  */
 public function getAdminInterface()
 {
     $this->smarty->assign('CurrencySign', SiteConfig::get("EComm::CurrencySign"));
     $section = @$_REQUEST['section'];
     switch ($section) {
         case 'ProductType':
         case 'Supplier':
         case 'Category':
         case 'TaxClass':
         case 'TaxRate':
             //$section will be the name of the class, the name of the PHP file, and the name of the .tpl file as well
             require_once "include/{$section}.php";
             $obj = new $section(@$_REQUEST[call_user_func(array($section, 'getQuickFormPrefix')) . 'id']);
             switch (@$_REQUEST['action']) {
                 case 'addedit':
                     $form = $obj->getAddEditForm("/admin/EComm");
                     if (!$form->isProcessed()) {
                         return $form->display();
                     }
                     break;
                 case 'delete':
                     $obj->delete();
                     return 1;
                     break;
             }
             $results = call_user_func(array($section, 'getAll'), false);
             //Get all the records
             $this->smarty->assign('results', $results);
             return $this->smarty->fetch("admin/{$section}.tpl");
             break;
         case 'Plugins':
             require_once 'plugins/products/ECommProduct.php';
             $ECommPlugins = new ECommProduct();
             $page = @$_REQUEST["page"];
             if ($page && $ECommPlugins->getPlugin($page) && $ECommPlugins->getPlugin($page)->hasAdminInterface()) {
                 $this->smarty->assign('ECommPlugins', $ECommPlugins);
                 $this->smarty->assign('plugin', $_REQUEST["page"]);
                 return $this->smarty->fetch("admin/ProductPluginAdminArea.tpl");
             } else {
                 $this->smarty->assign('ECommPlugins', $ECommPlugins);
                 $this->smarty->assign('plugins', $ECommPlugins->getActivePluginIDs());
                 return $this->smarty->fetch("admin/ProductPlugin.tpl");
             }
             break;
         case 'Product':
             require_once "include/Product.php";
             require_once 'plugins/products/ECommProduct.php';
             $this->addJS("/modules/EComm/js/ecomm.js");
             $this->addCSS("/modules/EComm/css/ecomm.css");
             $obj = new Product(@$_REQUEST['product_id']);
             switch (@$_REQUEST['action']) {
                 case 'addedit':
                     $form = $obj->getAddEditForm("/admin/EComm");
                     if (!$form->isProcessed()) {
                         return $form->display();
                     }
                     $hookResults = ECommProduct::adminPluginHooks("AfterSave", $obj, $form);
                     break;
                 case 'delete':
                     $hookResults = ECommProduct::adminPluginHooks("BeforeDelete", $obj);
                     $obj->delete();
                     $hookResults = ECommProduct::adminPluginHooks("AfterDelete", $obj);
                     break;
                 case 'autoComplete':
                     $array = Product::searchProducts(array('Name' => @$_REQUEST['productName']), false);
                     $str = '<ul>';
                     foreach ($array as $key => $product) {
                         $str .= '<li id="' . $product->getId() . '">' . $product->getName() . '</li>';
                     }
                     $str .= '</ul>';
                     return $str;
             }
             require_once 'Pager.php';
             $productsPerPage = 10;
             $ecommStatus = $this->getECommStatus();
             $pagerOptions = array('mode' => 'Sliding', 'delta' => 1, 'perPage' => $productsPerPage, 'append' => false, 'path' => '/', 'fileName' => "EComm&section=Product&pageID=%d", 'totalItems' => $ecommStatus['products']);
             $pager =& Pager::factory($pagerOptions);
             list($from, $to) = $pager->getOffsetByPageId();
             $this->smarty->assign('pager_links', $pager->links);
             $this->smarty->assign('page_numbers', array('current' => $pager->getCurrentPageID(), 'total' => $pager->numPages()));
             $results = Product::getAll(false, $from, $productsPerPage);
             $this->smarty->assign('msg', @$_REQUEST["msg"]);
             $this->smarty->assign('results', $results);
             return $this->smarty->fetch("admin/Product.tpl");
             break;
         case 'Shipping':
             require_once 'plugins/shipping/ECommShipping.php';
             $ECommShipping = new ECommShipping();
             if (@$_REQUEST["plugin"]) {
                 $plugin = $ECommShipping->getPlugin($_REQUEST["plugin"]);
                 if (!$plugin) {
                     return "Plugin not found";
                 }
                 return $this->smarty->fetch('admin/subnavi.tpl') . $plugin->getAdminInterface($this);
             } else {
                 $this->smarty->assign('ECommShipping', $ECommShipping);
                 $this->smarty->assign('plugins', $ECommShipping->getActivePluginIDs());
                 return $this->smarty->fetch("admin/ShippingNavi.tpl");
             }
             break;
         case 'Order':
             require_once "include/Order.php";
             $obj = new Order(@$_REQUEST['order_id']);
             switch (@$_REQUEST['action']) {
                 case 'View':
                     $orderItems = OrderDetail::getAll($obj->getId());
                     $orderComments = OrderComment::getAll($obj->getId());
                     $this->smarty->assign('order', $obj);
                     $this->smarty->assign('orderItems', $orderItems);
                     $this->smarty->assign('orderComments', $orderComments);
                     return $this->smarty->fetch("admin/OrderDetail.tpl");
                     break;
                 case 'Comment':
                     $orderComment = new OrderComment();
                     $orderComment->setStatus($obj->getStatus());
                     $orderComment->setOrderNb($obj->getId());
                     $form = $orderComment->getAddEditForm("/admin/EComm");
                     if (!$form->isProcessed()) {
                         return $form->display();
                     }
                     $obj->setStatus(@$_REQUEST["ordercomment_status"]);
                     $obj->save();
                     break;
             }
             $results = Order::getAll(@$_REQUEST["allOrders"]);
             $this->smarty->assign('results', $results);
             return $this->smarty->fetch("admin/Order.tpl");
         case 'Transaction':
             require_once "include/Transaction.php";
             $results = Transaction::getAll();
             $this->smarty->assign('results', $results);
             return $this->smarty->fetch("admin/Transaction.tpl");
             break;
         default:
             $this->smarty->assign('status', $this->getECommStatus());
             return $this->smarty->fetch('admin/dashBoard.tpl');
     }
 }
 public function getProductos()
 {
     $producto = new Product();
     return $producto->getAll();
 }
    header('location: index.php');
}
if (isset($_GET['id'])) {
    if ($_GET['id'] == 'ok') {
        echo notification('Productlijst succesvol verwijderd', 'ok');
    } else {
        echo notification('weet u zeker dat u de volgende produclijst wilt verwijderen?', 'warning');
        $productlijst = productlijst::get($_GET['id']);
        $naam = $productlijst->getProperty('Naam');
        echo '<b>' . $naam . ' verwijderen?</b>';
        echo '<br/>';
        echo '<br/>';
        echo '<form method="post"/>';
        echo '<input type="submit" name="ja" value="Ja" class="button"/>';
        echo '<input type="submit" name="nee" value="Nee" class="button"/>';
        echo '</form>';
        if (isset($_POST['ja'])) {
            $producten = Product::getAll();
            foreach ($producten as $product) {
                if ($product->getProperty('ProductlijstID') == $_GET['id']) {
                    $product->delete();
                }
            }
            $productlijst->delete();
            header("location: index.php?c=productlijst&p=delete&id=ok");
        }
        if (isset($_POST['nee'])) {
            header("location: index.php?c=productlijst&p=list");
        }
    }
}
Example #19
0
<?php 
if (!empty($_GET['delete'])) {
    $id = (int) $_GET['delete'];
    Product::delete($id);
}
$products = Product::getAll();
?>
<form method="post" action="?page=edit">
	<input type="submit" name="newpost" class="button" value="New Post" />
</form>
<table class="product-table">
	<thead>
		<tr>
			<th>Title</th>
			<th>Art. Number</th>
			<th>Delete</th>
		</tr>
	</thead>
	<tbody>
	
		<?php 
foreach ($products as $product) {
    ?>
			<tr>
				<td><a href="?page=edit&post=<?php 
    print $product['id'];
    ?>
"><?php 
    print $product['title'];
    ?>
Example #20
0
<h1><a href="<?php 
print getinfo('site_url');
?>
"><?php 
print getinfo('site_title');
?>
</a></h1>

<div id="products-container">
<?php 
foreach (Product::getAll() as $product) {
    ?>

	<div class="product">
	    <img src="<?php 
    print $product['image'];
    ?>
" width="200px"/>
	    <h2><?php 
    print $product['title'];
    ?>
</h2>
		<div class="content">
			<?php 
    print $product['content'];
    ?>
		</div>
	</div>


<?php 
 /**
  * @depends testSimpleUserImportWhereAllRowsSucceed
  */
 public function testSimpleUserImportWithRelationsWhereAllRowsSucceed()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     //Create account
     $sampleAccount = Account::getByName('sampleAccount');
     $accountId = $sampleAccount[0]->id;
     //Create Contact
     $contact = ContactTestHelper::createContactByNameForOwner("My Contact", Yii::app()->user->userModel);
     $import = new Import();
     $serializedData['importRulesType'] = 'Products';
     $serializedData['firstRowIsHeaderRow'] = true;
     $import->serializedData = serialize($serializedData);
     $this->assertTrue($import->save());
     ImportTestHelper::createTempTableByFileNameAndTableName('productsSampleWithRelations.csv', $import->getTempTableName(), true, Yii::getPathOfAlias('application.modules.products.tests.unit.files'));
     //update the ids of the account column to match the parent account.
     ZurmoRedBean::exec("update " . $import->getTempTableName() . " set column_9 = " . $contact->id . " where id != 1 limit 3");
     $this->assertEquals(3, ImportDatabaseUtil::getCount($import->getTempTableName()));
     // includes header rows.
     $currencies = Currency::getAll();
     $ownerColumnMappingData = array('attributeIndexOrDerivedType' => 'owner', 'type' => 'importColumn', 'mappingRulesData' => array('DefaultModelNameIdMappingRuleForm' => array('defaultModelId' => null), 'UserValueTypeModelAttributeMappingRuleForm' => array('type' => UserValueTypeModelAttributeMappingRuleForm::ZURMO_USERNAME)));
     $mappingData = array('column_0' => $ownerColumnMappingData, 'column_1' => ImportMappingUtil::makeStringColumnMappingData('name'), 'column_2' => ImportMappingUtil::makeTextAreaColumnMappingData('description'), 'column_3' => ImportMappingUtil::makeIntegerColumnMappingData('quantity'), 'column_4' => ImportMappingUtil::makeHasOneColumnMappingData('account', RelatedModelValueTypeMappingRuleForm::ZURMO_MODEL_NAME), 'column_5' => ImportMappingUtil::makeStringColumnMappingData('stage'), 'column_6' => ImportMappingUtil::makeCurrencyColumnMappingData('sellPrice', $currencies[0]), 'column_7' => ImportMappingUtil::makeIntegerColumnMappingData('priceFrequency'), 'column_8' => ImportMappingUtil::makeIntegerColumnMappingData('type'));
     $importRules = ImportRulesUtil::makeImportRulesByType('Products');
     $page = 0;
     $config = array('pagination' => array('pageSize' => 50));
     //This way all rows are processed.
     $dataProvider = new ImportDataProvider($import->getTempTableName(), true, $config);
     $dataProvider->getPagination()->setCurrentPage($page);
     $importResultsUtil = new ImportResultsUtil($import);
     $messageLogger = new ImportMessageLogger();
     ImportUtil::importByDataProvider($dataProvider, $importRules, $mappingData, $importResultsUtil, new ExplicitReadWriteModelPermissions(), $messageLogger);
     $importResultsUtil->processStatusAndMessagesForEachRow();
     //Confirm that 3 models where created.
     $products = Product::getAll();
     $this->assertEquals(2, count($products));
     $products = Product::getByName('A Bend in the River November Issue import');
     $this->assertEquals(1, count($products));
     $this->assertEquals('super', $products[0]->owner->username);
     $this->assertEquals('A Bend in the River November Issue import', $products[0]->name);
     $this->assertEquals(6, $products[0]->quantity);
     $this->assertEquals('sampleAccount', $products[0]->account->name);
     $this->assertEquals('Open', $products[0]->stage->value);
     $this->assertEquals('Test Desc', $products[0]->description);
     $this->assertEquals(210, $products[0]->sellPrice->value);
     $this->assertEquals(2, $products[0]->priceFrequency);
     $this->assertEquals(2, $products[0]->type);
     //$this->assertEquals('My Contact',              $products[0]->contact->firstName);
     $products = Product::getByName('A Bend in the River November Issue import copy');
     $this->assertEquals(1, count($products));
     $this->assertEquals('super', $products[0]->owner->username);
     $this->assertEquals('A Bend in the River November Issue import copy', $products[0]->name);
     $this->assertEquals(6, $products[0]->quantity);
     $this->assertEquals('sampleAccount', $products[0]->account->name);
     $this->assertEquals('Open', $products[0]->stage->value);
     $this->assertEquals('Test Desc 1', $products[0]->description);
     $this->assertEquals(210, $products[0]->sellPrice->value);
     $this->assertEquals(2, $products[0]->priceFrequency);
     $this->assertEquals(2, $products[0]->type);
     //$this->assertEquals('My Contact',              $products[0]->contact->firstName);
     //Confirm that 2 rows were processed as 'updated'.
     $this->assertEquals(0, ImportDatabaseUtil::getCount($import->getTempTableName(), "status = " . ImportRowDataResultsUtil::UPDATED));
     //Confirm 2 rows were processed as 'errors'.
     $this->assertEquals(0, ImportDatabaseUtil::getCount($import->getTempTableName(), "status = " . ImportRowDataResultsUtil::ERROR));
     $beansWithErrors = ImportDatabaseUtil::getSubset($import->getTempTableName(), "status = " . ImportRowDataResultsUtil::ERROR);
     $this->assertEquals(0, count($beansWithErrors));
 }
 public function testSuperUserCreateProductFromProductTemplateControllerAction()
 {
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     $products = Product::getAll();
     $this->assertEquals(1, count($products));
     $superProductTemplateId = self::getModelIdByModelNameAndName('ProductTemplate', 'My Product Template');
     $productTemplate = ProductTemplate::getById($superProductTemplateId);
     $productCategory = ProductCategoryTestHelper::createProductCategoryByName("Test Category");
     $productCategoryII = ProductCategoryTestHelper::createProductCategoryByName("Test CategoryII");
     $productTemplate->productCategories->add($productCategory);
     $productTemplate->productCategories->add($productCategoryII);
     $productTemplate->save();
     $superProductTemplateId = $productTemplate->id;
     $productTemplate->forget();
     unset($productTemplate);
     $accountId = self::getModelIdByModelNameAndName('Account', 'superAccount');
     $this->setGetArray(array('relationModuleId' => 'accounts', 'portletId' => '1', 'uniqueLayoutId' => 'AccountDetailsAndRelationsView_1', 'id' => $superProductTemplateId, 'relationModelId' => $accountId, 'relationAttributeName' => 'account', 'relationModelClassName' => 'Account', 'redirect' => '0'));
     $this->runControllerWithNoExceptionsAndGetContent('products/default/createProductFromProductTemplate', true);
     $products = Product::getAll();
     $this->assertEquals(2, count($products));
     $latestProduct = $products[1];
     $productSavedCategory = $latestProduct->productCategories[0];
     $productSavedCategoryII = $latestProduct->productCategories[1];
     $this->assertEquals('Test Category', $productSavedCategory->name);
     $this->assertEquals('Test CategoryII', $productSavedCategoryII->name);
     $this->assertEquals('My Product Template', $latestProduct->name);
     $this->assertEquals(500.54, $latestProduct->sellPrice->value);
 }