/**
  * Ajouter un movement de stock
  *
  */
 public function AddAction()
 {
     $response = false;
     $product_id = $this->getRequest()->getParam('sm_product_id');
     try {
         //Cree le movement
         mage::getModel('Purchase/StockMovement')->setsm_product_id($product_id)->setsm_qty($this->getRequest()->getParam('sm_qty'))->setsm_coef(mage::getModel('Purchase/StockMovement')->GetTypeCoef($this->getRequest()->getParam('sm_type')))->setsm_description($this->getRequest()->getParam('sm_description'))->setsm_type($this->getRequest()->getParam('sm_type'))->setsm_date($this->getRequest()->getParam('sm_date'))->save();
         Mage::GetModel('Purchase/StockMovement')->ComputeProductStock($product_id);
         //Confirme
         Mage::getSingleton('adminhtml/session')->addSuccess($this->__('Stock movement created'));
     } catch (Exception $ex) {
         Mage::getSingleton('adminhtml/session')->addError($this->__('Error'));
     }
     //redirect to purchase product sheet
     $this->_redirect('Purchase/Products/Edit', array('product_id' => $product_id, 'tab' => 'tab_stock_movements'));
 }
 /**
  * Retourne un combo avec les manufactures pas encore associés
  *
  */
 public function getOtherManufacturesAsCombo($name)
 {
     //cree un tableau avec les id des manufacturers déja géré
     $collection = Mage::GetModel('Purchase/ManufacturerSupplier')->getCollection()->addFieldToFilter('pms_supplier_id', $this->_supplier_id);
     $t_ids = array();
     $t_ids[] = '-1';
     foreach ($collection as $item) {
         $t_ids[] = $item->getpms_manufacturer_id();
     }
     //Charge les manufacturers pas gérés
     $collection = Mage::GetModel('Purchase/Manufacturer')->getCollection()->addFieldToFilter('man_id', array('nin' => $t_ids));
     $retour = '<select id="' . $name . '"  name="' . $name . '">';
     $retour .= '<option value=""></option>';
     foreach ($collection as $item) {
         $retour .= '<option value="' . $item->getman_id() . '">' . $item->getman_name() . '</option>';
     }
     $retour .= '</select>';
     return $retour;
 }
 /**
  * Enregistre les modifs faite
  *
  */
 public function SaveAction()
 {
     //Charge le manufacturer
     $Supplier = Mage::getModel('Purchase/Supplier')->load($this->getRequest()->getParam('sup_id'));
     //Enregistre les modifs
     $Supplier->setsup_name($this->getRequest()->getParam('sup_name'));
     $Supplier->setsup_contact($this->getRequest()->getParam('sup_contact'));
     $Supplier->setsup_address1($this->getRequest()->getParam('sup_address1'));
     $Supplier->setsup_address2($this->getRequest()->getParam('sup_address2'));
     $Supplier->setsup_zipcode($this->getRequest()->getParam('sup_zipcode'));
     $Supplier->setsup_city($this->getRequest()->getParam('sup_city'));
     $Supplier->setsup_country($this->getRequest()->getParam('sup_country'));
     $Supplier->setsup_tel($this->getRequest()->getParam('sup_tel'));
     $Supplier->setsup_fax($this->getRequest()->getParam('sup_fax'));
     $Supplier->setsup_mail($this->getRequest()->getParam('sup_mail'));
     $Supplier->setsup_website($this->getRequest()->getParam('sup_website'));
     $Supplier->setsup_comments($this->getRequest()->getParam('sup_comments'));
     if ($this->getRequest()->getParam('sup_sale_online')) {
         if ($this->getRequest()->getParam('sup_sale_online') == 1) {
             $Supplier->setsup_sale_online(1);
         } else {
             $Supplier->setsup_sale_online(0);
         }
     } else {
         $Supplier->setsup_sale_online(0);
     }
     $Supplier->setsup_account_login($this->getRequest()->getParam('sup_account_login'));
     $Supplier->setsup_account_password($this->getRequest()->getParam('sup_account_password'));
     $Supplier->setsup_order_mini($this->getRequest()->getParam('sup_order_mini'));
     $Supplier->setsup_supply_delay($this->getRequest()->getParam('sup_supply_delay'));
     $Supplier->setsup_supply_delay_max($this->getRequest()->getParam('sup_supply_delay_max'));
     $Supplier->setsup_carrier($this->getRequest()->getParam('sup_carrier'));
     $Supplier->setsup_rma_tel($this->getRequest()->getParam('sup_rma_tel'));
     $Supplier->setsup_rma_mail($this->getRequest()->getParam('sup_rma_mail'));
     $Supplier->setsup_rma_comments($this->getRequest()->getParam('sup_rma_comments'));
     $Supplier->save();
     //verifie si on doit en ajouter un
     $sup_id = $Supplier->getId();
     if ($this->getRequest()->getParam('add_pms_manufacturer_id') != '') {
         $NewManufacturer = mage::getModel('Purchase/ManufacturerSupplier');
         $NewManufacturer->setpms_supplier_id($sup_id);
         $NewManufacturer->setpms_manufacturer_id($this->getRequest()->getParam('add_pms_manufacturer_id'));
         $NewManufacturer->setpms_official($this->getRequest()->getParam('add_pms_official'));
         $NewManufacturer->setpms_price_position($this->getRequest()->getParam('add_pms_price_position'));
         $NewManufacturer->setpms_gamme($this->getRequest()->getParam('add_pms_gamme'));
         $NewManufacturer->save();
     }
     //Met a jour les autres
     $collection = Mage::GetModel('Purchase/ManufacturerSupplier')->getCollection()->addFieldToFilter('pms_supplier_id', $sup_id);
     foreach ($collection as $item) {
         if ($this->getRequest()->getParam('pms_official_' . $item->getpms_num()) == '1') {
             $item->setpms_official(1);
         } else {
             $item->setpms_official(0);
         }
         $item->setpms_price_position($this->getRequest()->getParam('pms_price_position_' . $item->getpms_num()));
         $item->setpms_gamme($this->getRequest()->getParam('pms_gamme_' . $item->getpms_num()));
         $item->save();
     }
     //confirme
     Mage::getSingleton('adminhtml/session')->addSuccess($this->__('Supplier Saved'));
     //Redirige vers la fiche créée
     $this->_redirect('Purchase/Suppliers/Edit/sup_id/' . $Supplier->getId());
 }
Example #4
0
 /**
  * this function takes a single item from the request and evaluates
  * the single item data to figure out the insert.
  *
  * @param $item
  * @param Mage_Checkout_Model_Cart $cartObj
  */
 public function insertItemToCartDirect($item, Mage_Checkout_Model_Cart $cartObj)
 {
     $quote = $cartObj->getQuote();
     $id = $item->get('secondaryId');
     if (is_numeric($id)) {
         $product = Mage::GetModel('catalog/product')->load($id);
         $this->addCatalogProductToQuote($quote, $product, (int) $item->get('quantity'));
     } else {
         try {
             $idData = Zend_Json::decode($id);
             $parentItem = null;
             $parentProductId = null;
             foreach ($idData as $id => $data) {
                 //                    echo $id;
                 $product = Mage::GetModel('catalog/product')->load($id);
                 $product->setIsInStock(1);
                 $product->setIsSalable(1);
                 //$product->setWebsiteIds
                 $product->setCartQty($item->get('quantity'));
                 $product->setQty($item->get('quantity'));
                 if ($parentProductId != null) {
                     $product->setParentProductId($parentProductId);
                     $product->setStickWithinParent($parentItem);
                 }
                 //                    print_r($product->debug());
                 $item = $this->addCatalogProductToQuote($quote, $product, $parentProductId == null ? (int) $item->get('quantity') : 1);
                 if ($parentItem == null) {
                     $parentItem = $item;
                     $parentProductId = $product->getId();
                     $item->addQty((int) $item->get('quantity'));
                 } else {
                     $item->setParentItem($parentItem);
                 }
             }
             //                exit;
         } catch (Exception $e) {
             // the data was invalid.
         }
     }
 }
Example #5
0
 /**
  * @depricated
  * @return object
  */
 public function getCategoryEntityAttributes()
 {
     $entity = $this->getEntityCatalog();
     $coll = Mage::GetModel('eav/eav_entity_attribute')->getCollection();
     $coll->setEntityTypeFilter($entity->getId());
     //$setId       = (int) $object->getAttributeSetId();
     //$groupId     = (int) $object->getAttributeGroupId();
     return $coll;
 }
Example #6
0
 public function UpdateProductStock($ProductId)
 {
     Mage::GetModel('Purchase/StockMovement')->ComputeProductStock($ProductId);
 }