Esempio n. 1
0
 public function getSearchMenu($param)
 {
     //displaySearchForm means to display the search form at the right side of the website.
     switch ($param) {
         case 'Suppliers':
             require_once 'include/CartManufacturer.php';
             $this->smarty->assign('selSupplier', @$_REQUEST["selSupplier"]);
             return CartManufacturer::getAllCartManufacturers();
             break;
         case 'Categories':
             //Display the categories
             require_once 'include/CartCategory.php';
             $this->smarty->assign('selCategory', @$_REQUEST["selCategory"]);
             return CartCategory::getCartCategorys();
             break;
         case 'ProductTypes':
             require_once 'include/CartProductType.php';
             $this->smarty->assign('selProductType', @$_REQUEST["selProductType"]);
             return CartProductType::getAllCartProductTypes();
             break;
     }
 }
Esempio n. 2
0
    /**
     * Get an Add/Edit form for the object.
     *
     * @param string $target Post target for form submission
     */
    public function getAddEditForm($target = '/admin/Cart')
    {
        $form = new Form('CartProduct_addedit', 'post', $target, '', array('class' => 'admin'));
        $form->setConstants(array('section' => 'products'));
        $form->addElement('hidden', 'section');
        $form->setConstants(array('action' => 'addedit'));
        $form->addElement('hidden', 'action');
        if (!is_null($this->getId())) {
            $form->setConstants(array('cartproduct_products_id' => $this->getId()));
            $form->addElement('hidden', 'cartproduct_products_id');
            $defaultValues['cartproduct_type'] = $this->getType()->getId();
            $defaultValues['cartproduct_quantity'] = $this->getQuantity();
            $defaultValues['cartproduct_pallet_count'] = $this->getPalletCount();
            //$defaultValues ['cartproduct_model'] = $this->getModel();
            $defaultValues['cartproduct_image'] = $this->getImage()->getId();
            $defaultValues['cartproduct_price'] = $this->getPrice();
            //$defaultValues ['cartproduct_virtual'] = $this->getVirtual();
            $defaultValues['cartproduct_date_added'] = $this->getDate_added();
            $defaultValues['cartproduct_lastModified'] = $this->getLastModified();
            $defaultValues['cartproduct_dateAvailable'] = $this->getDateAvailable();
            $defaultValues['cartproduct_weight'] = $this->getWeight();
            $defaultValues['cartproduct_weight_unit'] = $this->getWeightUnit();
            $defaultValues['cartproduct_status'] = $this->getStatus();
            $defaultValues['cartproduct_taxClass'] = $this->getTaxClass()->getId();
            $defaultValues['cartproduct_manufacturer'] = $this->getManufacturer()->getId();
            $defaultValues['cartproduct_ordered'] = $this->getOrdered();
            $defaultValues['cartproduct_orderMin'] = $this->getOrderMin();
            $defaultValues['cartproduct_orderUnits'] = $this->getOrderUnits();
            $defaultValues['cartproduct_pricedByAttribute'] = $this->getPricedByAttribute();
            $defaultValues['cartproduct_isFree'] = $this->getIsFree();
            $defaultValues['cartproduct_isCall'] = $this->getIsCall();
            $defaultValues['cartproduct_quantityMixed'] = $this->getQuantityMixed();
            $defaultValues['cartproduct_isAlwaysFreeShipping'] = $this->getIsAlwaysFreeShipping();
            $defaultValues['cartproduct_qtyBoxStatus'] = $this->getQtyBoxStatus();
            $defaultValues['cartproduct_qtyOrderMax'] = $this->getQtyOrderMax();
            $defaultValues['cartproduct_sortOrder'] = $this->getSortOrder();
            $defaultValues['cartproduct_discountType'] = $this->getDiscountType();
            $defaultValues['cartproduct_discountTypeFrom'] = $this->getDiscountTypeFrom();
            $defaultValues['cartproduct_priceSorter'] = $this->getPriceSorter();
            $defaultValues['cartproduct_category'] = $this->getCategory()->getId();
            $defaultValues['cartproduct_mixedDiscountQty'] = $this->getMixedDiscountQty();
            $defaultValues['cartproduct_titleStatus'] = $this->getTitleStatus();
            $defaultValues['cartproduct_nameStatus'] = $this->getNameStatus();
            $defaultValues['cartproduct_modelStatus'] = $this->getModelStatus();
            $defaultValues['cartproduct_priceStatus'] = $this->getPriceStatus();
            $defaultValues['cartproduct_taglineStatus'] = $this->getTaglineStatus();
            $defaultValues['cartproduct_name'] = $this->getName();
            $defaultValues['cartproduct_description'] = $this->getDescription();
            //$defaultValues ['cartproduct_url'] = $this->getUrl();
            //$defaultValues ['cartproduct_accessoryof'] = $this->getAccessoryOf()->getId();
        } else {
            /*******************************************************/
            //The following few lines assign the default values to the elements.
            //It is very important especially for adjusting the layout
            $defaultValues['cartproduct_date_added'] = " ";
            $defaultValues['cartproduct_lastModified'] = " ";
            //$defaultValues ['cartproduct_virtual'] = 0;
            /*******************************************************/
        }
        $form->setDefaults($defaultValues);
        $form->addElement('header', 'product_details', 'Product Details');
        $form->addElement('text', 'cartproduct_name', 'Name');
        $desc = $form->addElement('tinymce', 'cartproduct_description', 'Description');
        //$form->addElement('text', 'cartproduct_url', 'Link URL');
        /*
        $products = CartProduct::toArray();
        $products[0] = "Not an Accessory";
        $acc = $form->addElement('select', 'cartproduct_accessoryof', 'Accessory Of', $products);
        $acc->setMultiple(true);
        
        $accs = array();
        
        foreach ($this->getAccessoryOf() as $p) {
        	$accs[] = $p->getId();
        }
        
        $acc->setSelected($accs);
        */
        $form->addElement('select', 'cartproduct_manufacturer', 'Supplier', CartManufacturer::toArray());
        $form->addElement('select', 'cartproduct_category', 'Category', CartCategory::toArray());
        require_once 'CartProductType.php';
        $form->addElement('select', 'cartproduct_type', 'Product Type', @CartProductType::toArray());
        $form->addElement('text', 'cartproduct_quantity', 'Stock Qty');
        $form->addElement('text', 'cartproduct_pallet_count', 'Pallet Count');
        //$form->addElement('text', 'cartproduct_model', 'Model #');
        $newImage = $form->addElement('file', 'cartproduct_image_upload', 'Product Image');
        if ($this->getImage()) {
            $curImage = $form->addElement('dbimage', 'cartproduct_image', $this->getImage()->getId());
        }
        $form->addElement('text', 'cartproduct_price', 'Price ($)');
        //$form->addElement('select', 'cartproduct_virtual', 'Virtual Product', Form::booleanArray());
        $form->addElement('static', 'cartproduct_date_added', 'Date Added');
        $form->addElement('static', 'cartproduct_lastModified', 'Last Modified');
        $form->addElement('text', 'cartproduct_dateAvailable', 'Date Availible');
        $form->addElement('text', 'cartproduct_weight', 'Weight per bag');
        $form->addElement('select', 'cartproduct_weight_unit', 'Weight Unit', CartProduct::getAvailableWeightUnits());
        $form->addElement('select', 'cartproduct_taxClass', 'Tax Class', CartTaxClass::toArray());
        //$form->addElement('text', 'cartproduct_ordered', 'ordered');
        $form->addElement('text', 'cartproduct_orderMin', 'Minimum Order Quantity');
        $form->addElement('select', 'cartproduct_status', 'Status', Form::statusArray());
        $form->addElement('header', 'alt_images', 'Alternate Product Images');
        foreach ($this->getAltImages() as $image) {
            $form->addElement('html', '
				<div style="float: right;" id="delete_altimage_div_' . $image['id'] . '">
					<input type="image" src="/images/admin/cross.gif" name="delete_altimage" onclick="return !deleteAltImage(' . $image['id'] . ');" />
				</div>
			');
            $form->addElement('dbimage', 'cartproduct_altimage_' . $image['id'], $image['image_id']);
        }
        $newAltImage = $form->addElement('file', 'cartproduct_altimage_upload', 'New Alternate Product Image');
        $options = $this->getOptions();
        foreach ($options as $option) {
            $form->addElement('header', 'product_options_' . $option->getId(), 'Product Options: ' . $option->getOptionsId()->getName());
            $form->addElement('static', 'value_' . $option->getId(), $option->getOptionsId()->getName(), $option->getValue()->getName());
            $form->addElement('text', 'attprice[' . $option->getId() . ']', 'Additional Price');
            $form->addElement('text', 'inventory[' . $option->getId() . ']', 'Inventory');
            $form->addElement('html', '
				<div style="float: right;">
					<input type="image" src="/images/admin/cross.gif" name="delete_att" onclick="return !deleteAtt(' . $option->getId() . ');" />
				</div>
			');
            $defaultValues['attprice[' . $option->getId() . ']'] = $option->getValuesPrice();
            $defaultValues['inventory[' . $option->getId() . ']'] = $option->getInventory();
        }
        $form->addElement('header', 'new_product_options', 'New Product Option');
        $form->addElement('select', 'newoption', 'Option', CartProductOption::toArray(), array('onclick' => 'getValues(this);'));
        $form->addElement('select', 'newvalue', 'Value', array());
        $form->addElement('text', 'newattprice', 'Additional Price');
        $form->addElement('text', 'newinventory', 'Inventory');
        $form->setDefaults($defaultValues);
        if (isset($_REQUEST['cartproduct_submit']) && $form->validate() && $form->isSubmitted()) {
            $this->setName($form->exportValue('cartproduct_name'));
            $this->setDescription($form->exportValue('cartproduct_description'));
            //$this->setUrl($form->exportValue('cartproduct_url'));
            $this->setType($form->exportValue('cartproduct_type'));
            $this->setQuantity($form->exportValue('cartproduct_quantity'));
            $this->setPalletCount($form->exportValue('cartproduct_pallet_count'));
            //$this->setModel($form->exportValue('cartproduct_model'));
            $this->setImage($form->exportValue('cartproduct_image_upload'));
            $this->setPrice($form->exportValue('cartproduct_price'));
            //$this->setVirtual($form->exportValue('cartproduct_virtual'));
            $this->setDate_added($form->exportValue('cartproduct_date_added'));
            $this->setLastModified(date('Y-m-d H:i:s'));
            $this->setDateAvailable($form->exportValue('cartproduct_dateAvailable'));
            $this->setWeight($form->exportValue('cartproduct_weight'));
            $this->setWeightUnit($form->exportValue('cartproduct_weight_unit'));
            $this->setStatus($form->exportValue('cartproduct_status'));
            $this->setTaxClass($form->exportValue('cartproduct_taxClass'));
            $this->setManufacturer($form->exportValue('cartproduct_manufacturer'));
            //$this->setAccessoryOf($form->exportValue('cartproduct_accessoryof'));
            //$this->setOrdered($form->exportValue('cartproduct_ordered'));
            if ($form->exportValue('cartproduct_orderMin') <= 0) {
                $this->setOrderMin(1);
            } else {
                $this->setOrderMin($form->exportValue('cartproduct_orderMin'));
            }
            $this->setCategory($form->exportValue('cartproduct_category'));
            /*
            $this->setOrderUnits($form->exportValue('cartproduct_orderUnits'));
            $this->setPricedByAttribute($form->exportValue('cartproduct_pricedByAttribute'));
            $this->setIsFree($form->exportValue('cartproduct_isFree'));
            $this->setIsCall($form->exportValue('cartproduct_isCall'));
            $this->setQuantityMixed($form->exportValue('cartproduct_quantityMixed'));
            $this->setIsAlwaysFreeShipping($form->exportValue('cartproduct_isAlwaysFreeShipping'));
            $this->setQtyBoxStatus($form->exportValue('cartproduct_qtyBoxStatus'));
            $this->setQtyOrderMax($form->exportValue('cartproduct_qtyOrderMax'));
            $this->setSortOrder($form->exportValue('cartproduct_sortOrder'));
            $this->setDiscountType($form->exportValue('cartproduct_discountType'));
            $this->setDiscountTypeFrom($form->exportValue('cartproduct_discountTypeFrom'));
            $this->setPriceSorter($form->exportValue('cartproduct_priceSorter'));
            $this->setMixedDiscountQty($form->exportValue('cartproduct_mixedDiscountQty'));
            $this->setTitleStatus($form->exportValue('cartproduct_titleStatus'));
            $this->setNameStatus($form->exportValue('cartproduct_nameStatus'));
            $this->setModelStatus($form->exportValue('cartproduct_modelStatus'));
            $this->setPriceStatus($form->exportValue('cartproduct_priceStatus'));
            $this->setTaglineStatus($form->exportValue('cartproduct_taglineStatus'));
            */
            if ($newImage->isUploadedFile()) {
                $im = new Image();
                $id = $im->insert($newImage->getValue());
                $this->setImage($id);
                //$curImage->setSource($this->getImage()->getId());
            }
            $this->save();
            if ($newAltImage->isUploadedFile()) {
                $im = new Image();
                $id = $im->insert($newAltImage->getValue());
                $sql = 'insert into cart_products_images set product_id=' . $this->getId() . ', image_id=' . $id;
                Database::singleton()->query($sql);
            }
            if (is_array(@$_REQUEST['attprice'])) {
                foreach (@$_REQUEST['attprice'] as $key => $value) {
                    $att = new CartProductAttribute($key);
                    $att->setValuesPrice($value);
                    $att->setInventory($_REQUEST['inventory'][$key]);
                    $att->save();
                }
            }
            if (isset($_REQUEST['newvalue']) && isset($_REQUEST['newoption']) && isset($_REQUEST['newattprice'])) {
                $a = new CartProductAttribute();
                $a->setProductid($this->getId());
                $a->setOptionsId($_REQUEST['newoption']);
                $a->setValue($_REQUEST['newvalue']);
                $a->setValuesPrice($_REQUEST['newattprice']);
                $a->setInventory($_REQUEST['newinventory']);
                $a->save();
            }
        }
        $form->addElement('header', 'product_submit', 'Save Product');
        $form->addElement('submit', 'cartproduct_submit', 'Submit');
        return $form;
    }