public function retrieveProductFromProductsForPurchaseDetails($db, $productID)
 {
     //Fetch product
     $productProfileQuery = $db->select();
     $productProfileQuery->from(array('p' => 'products'), '*')->where('product_id = ?', $productID);
     $productProfileQuery->join(array('u' => 'users'), 'u.userID=p.uploader_id', array('u.first_name', 'u.last_name'));
     $product = $db->fetchAll($productProfileQuery);
     if (count($product) == '1') {
         //Fetch description
         $productProfileQuery = $db->select();
         $productProfileQuery->from('product_profiles', '*')->where('Product_id = ?', $product[0]['product_id']);
         $product['profile'] = $db->fetchAll($productProfileQuery);
         //Fetch product images
         $productImageQuery = $db->select();
         $productImageQuery->from(array('images' => 'product_images'), '*')->where('images.Product_id = ?', $product[0]['product_id']);
         //echo $select2;
         $product['images'] = $db->fetchAll($productImageQuery);
         //Fetch general inventory information
         $inventorySelect = $db->select();
         $inventorySelect->from(array('i' => 'product_inventories'), '*')->where('i.product_id = ?', $productID);
         $product['inventory'] = $db->fetchAll($inventorySelect);
         foreach ($product['inventory'] as $k => $v) {
             //Fetch inventory profile details
             $inventoryProfileQuery = $db->select();
             $inventoryProfileQuery->from('product_inventory_profile', '*')->where('product_inventory_profile_id =?', $v['product_inventory_id']);
             $product['inventory'][$k]['profile'] = $db->fetchAll($inventoryProfileQuery);
             $product['inventory'][$k]['images'] = DatabaseObject_Helper_ImageUpload::loadImagesForItem($db, 'product_inventory_images', $v['product_inventory_id']);
         }
         $product['existingFabricSet'] = DatabaseObject_Helper_ManageAttribute::retrieveAttributeForProduct($db, 'fabric_set', $product[0]['product_id']);
         //Zend_Debug::dump($fp->existingFabricSet);
         $product['existingAttributeSet'] = DatabaseObject_Helper_ManageAttribute::retrieveAttributeForProduct($db, 'custom_attribute', $product[0]['product_id']);
         $product['systemColorAndShoesAttributes'] = DatabaseObject_Helper_ManageAttribute::retrieveProductColorAndShoeAttribute($db, $product[0]['inventory_attribute_table'], $product[0]['product_id']);
     }
     return $product;
 }
 public function addinventoryAction()
 {
     //for uploading information into product_inventory add 'sys_' infront of all the variables uploaded
     //
     $productID = $this->request->getParam('id');
     //$product = DatabaseObject_Helper_ProductDisplay::getBasicProductInfo($this->db, $productID);
     //Zend_Debug::dump($product);
     $allowedProduct = DatabaseObject_Helper_ProductListing::confirmproductforuploader($this->db, 'products', $this->signedInUserSessionInfoHolder->generalInfo->userID, $productID);
     //make sure that the product is not a Buy_now product
     if (count($allowedProduct) == 1 && $allowedProduct[0]['purchase_type'] == 'Customizable') {
         $allowedProduct['existingFabricSet'] = DatabaseObject_Helper_ManageAttribute::retrieveAttributeForProduct($this->db, 'fabric_set', $productID);
         //Zend_Debug::dump($fp->existingFabricSet);
         $allowedProduct['existingAttributeSet'] = DatabaseObject_Helper_ManageAttribute::retrieveAttributeForProduct($this->db, 'custom_attribute', $productID);
         $allowedProduct['systemColorAndShoesAttributes'] = DatabaseObject_Helper_ManageAttribute::retrieveProductColorAndShoeAttribute($this->db, $allowedProduct[0]['inventory_attribute_table'], $productID);
         //check to see if searchable criteria color is available. If not, redirect.
         $hasColor = false;
         foreach ($allowedProduct['systemColorAndShoesAttributes']['colors'][0] as $k => $v) {
             if ($v == '1' && $k != 'product_id') {
                 $hasColor = true;
                 break;
             }
         }
         if (!$hasColor) {
             $this->messenger->addMessage('Please select at least one major color categories this product belongs to.');
             $this->_redirect('/manageattribute/editproductattribute?id=' . $productID);
         }
         //if the item is shoes, then fill all the measurements.
         if ($allowedProduct[0]['inventory_attribute_table'] == 'shoes') {
             //if there are no shoe attributes, redirect
             if (count($allowedProduct['systemColorAndShoesAttributes']['shoes']) == 0) {
                 $this->messenger->addMessage('You must specify shoes attributes first!');
                 $this->_redirect('/manageattribute/editproductattribute?id=' . $productID);
             }
             $measurement = array();
             $i = $allowedProduct['systemColorAndShoesAttributes']['shoes'][0]['min_size'];
             while ($i < $allowedProduct['systemColorAndShoesAttributes']['shoes'][0]['max_size'] + 0.5) {
                 $measurement[] = $i;
                 $i = $i + 0.5;
             }
             $this->view->measurements = $measurement;
             $heels = array();
             foreach ($allowedProduct['systemColorAndShoesAttributes']['heels'][0] as $key => $value) {
                 if ($key != 'product_id') {
                     if ($value == 1) {
                         $heels[] = $this->productConfig['attribute_conversion_details']['heel_sizes'][$key];
                     }
                 }
             }
             Zend_Debug::dump($this->productConfig['attribute_conversion_details']['heel_sizes']);
             $this->view->heels = $heels;
         } elseif ($allowedProduct[0]['inventory_attribute_table'] != 'jewelry' && $allowedProduct[0]['inventory_attribute_table'] != 'accessories') {
             echo 'here at dancewear';
             $inventoryDancewearAttribute = array();
             foreach ($this->productConfig['attribute_categories_details'][$allowedProduct[0]['inventory_attribute_table']] as $k => $v) {
                 $inventoryDancewearAttribute[$k] = array();
                 $inventoryDancewearAttribute[$k][] = 'Flexible';
                 $temp = $v['min'];
                 while ($temp < $v['max']) {
                     $inventoryDancewearAttribute[$k][] = $temp;
                     $temp += $v['interval'];
                 }
             }
             $this->view->measurements = $inventoryDancewearAttribute;
             Zend_Debug::dump($inventoryDancewearAttribute);
         }
         //inventory_attribute_table is the defualt system attribute system.
         $this->view->attributePartial = '_' . $allowedProduct[0]['inventory_attribute_table'] . 'Attribute.tpl';
         $this->view->product = $allowedProduct;
         Zend_Debug::dump($allowedProduct);
         $fp = new FormProcessor_Inventory_AddInventory($this->db, $this->signedInUserSessionInfoHolder->generalInfo->userID);
         if ($this->request->isPost()) {
             if ($fp->process($this->request)) {
                 //process images
                 echo 'post is: ' . Zend_Debug::dump($this->request->getParams());
                 DatabaseObject_Helper_ImageUpload::uploadImage($_FILES['generalImages'], $this->db, 'product_inventory_images', 'inventory', $fp->inventoryProduct->getId(), $fp->sys_name);
                 $this->messenger->addMessage('Inventory product has been added');
                 $this->_redirect($_SERVER['HTTP_REFERER']);
             }
             //echo 'here at post<br />';
         }
         $inventories = DatabaseObject_Helper_ManageInventory::retrieveInventoryForProduct($this->db, 'product_inventories', $productID);
         if (count($inventories) != 0) {
             $tmpInventoryKey = array();
             foreach ($inventories as $k => $v) {
                 $tmpInventoryKey[] = $v['basic']['product_inventory_id'];
             }
             Zend_Debug::dump($tmpInventoryKey);
             $completeInventoryProfile = DatabaseObject_Helper_ManageInventory::retrieveUniqueProfileKeys($this->db, 'product_inventory_profile', $tmpInventoryKey);
             Zend_Debug::dump($completeInventoryProfile);
             $this->view->mostInventoryProfile = $completeInventoryProfile;
         } else {
             $this->view->mostInventoryProfile = array();
         }
         //Zend_Debug::dump($inventories[$k]['profile']);
         $this->view->inventories = $inventories;
         $this->view->inventoryPartial = '_' . $allowedProduct[0]['inventory_attribute_table'] . 'Inventory.tpl';
         $this->view->inventoryPartialTitle = '_' . $allowedProduct[0]['inventory_attribute_table'] . 'InventoryTitle.tpl';
         $this->view->addPartial = '_add' . $allowedProduct[0]['purchase_type'] . 'Inventory.tpl';
         echo 'add partial is: ' . '_add' . $allowedProduct[0]['purchase_type'] . 'Inventory.tpl';
         Zend_Debug::dump($inventories);
         //$this->sendJson($json);
         //Zend_Debug::dump($json);
         //Zend_Debug::dump($this->request->getParams());
     } else {
         $this->messenger->addMessage('sorry, an error has occured. You may not add an inventory product at this moment');
         $this->_redirect('/index/error');
     }
 }
 public function removeattributefromproductAction()
 {
     $removeAttributes = $this->request->getPost('removeProductAttributeSet');
     //Zend_Debug::dump($removeAttributes);
     $attributeType = $this->request->getPost('attributeType');
     $productID = $this->request->getPost('ID');
     //check to see if id is appropirate for the user
     if (in_array($attributeType, $this->productConfig['custom_attribute_detail_table']) && DatabaseObject_Helper_ProductListing::confirmproductforuploader($this->db, 'products', $this->signedInUserSessionInfoHolder->generalInfo->userID, $productID)) {
         foreach ($removeAttributes as $k => $v) {
             //check to see if product id and requeted deleted id match
             if (DatabaseObject_Helper_ManageAttribute::confirmproductattribute($this->db, $attributeType, $productID, $v)) {
                 //echo process delete
                 //echo "here at delete";
                 DatabaseObject_Helper_ManageAttribute::removeAttributeForProduct($this->db, $attributeType, $v);
             }
         }
     }
     $json = DatabaseObject_Helper_ManageAttribute::retrieveAttributeForProduct($this->db, $attributeType, $productID);
     //Zend_Debug::dump($productExistingAttribute);
     $this->sendJson($json);
 }