Exemplo n.º 1
0
 /**
  * GET /products[/:id]
  * @return \Nohex\Eix\Core\Responses\Http\Html
  */
 public function httpGetForHtml()
 {
     $response = new HtmlResponse($this->getRequest());
     $id = $this->getRequest()->getParameter('id');
     $groupId = $this->getRequest()->getParameter('groupId');
     switch ($id) {
         case NULL:
             if ($groupId) {
                 $group = ProductGroups::getInstance()->findEntity($groupId);
                 $response->setData('group', $group->name);
             }
             $productList = $this->getProductList($groupId);
             if (empty($productList)) {
                 $response->setTemplateId('products/empty');
             } else {
                 $response->setTemplateId('products/index');
                 $response->setData('products', $productList);
             }
             $response->appendToTitle(_('Productes'));
             break;
         default:
             $response->setTemplateId('products/view');
             $product = $this->getForDisplay($id);
             if ($product['enabled']) {
                 $response->setData('product', $product);
                 $response->appendToTitle(_($product['name']));
             } else {
                 throw new NotFoundException('Product not found');
             }
             break;
     }
     return $response;
 }
Exemplo n.º 2
0
 public function update(array $data, $isAtomic = true)
 {
     parent::update($data, $isAtomic);
     // Set the groups.
     if (!empty($data['groups'])) {
         $this->groups = array();
         foreach ($data['groups'] as $key => $group) {
             if (!$group instanceof ProductGroup) {
                 $productGroup = ProductGroups::getInstance()->getEntity($group['id']);
                 if (!$productGroup) {
                     $productGroup = new ProductGroup(array('id' => $group['id'], 'name' => $group['name']));
                 }
                 $group = $productGroup;
             }
             // Keep the new entity.
             $this->groups[$group->id] = $group;
         }
     }
     // Invalidate calculated fields.
     $this->pricePerKg = null;
 }
Exemplo n.º 3
0
 /**
  * Returns a list of all available product groups.
  */
 private function getGroups()
 {
     $productGroups = ProductGroups::getInstance()->getAll();
     return array_map(function ($group) {
         return $group->getFieldsData();
     }, $productGroups);
 }
Exemplo n.º 4
0
 protected function getFactory()
 {
     return ProductGroups::getInstance();
 }