2012-08-16 4 views
0

고객이 자신의 제품을 만들고 해당 기능을 사용하도록 설정하기 전에 관리자가 승인 한 기능을 가진 모듈을 사용하여 frontend에서 magento 제품을 업데이트하는 데 문제가 있습니다 (이 부분이 작동 함).Magento 모듈에서 제품을 업데이트 할 수 없음

고객이 관리자 승인 제품을 업데이트하려고 시도하면 문제가 발생합니다 (승인 전과 같이 새로 생성 된 제품이 보류 중임을 나타내지 만 제품 작성 기능 중에 작성된 데이터/속성을 계속 업데이트 할 수 있음) 내가 승인/보류중인 고객 제품

public function editPostAction() { 

     $id = $this->getRequest()->getParam('productid'); 

     if ($id !== false) { 

      list($data, $errors) = $this->validatePost(); 
      if (!empty($errors)) { 
       foreach ($errors as $message) { 
        $this->_getSession()->addError($message); 
       } 
       $this->_redirect('customer/products/edit/', array(
         'id' => $id 
        )); 
      } else { 

       $customerId = $this->_getSession()->getCustomer()->getid(); 
       $product = Mage::getResourceModel('customerpartner/customerpartner_product_collection') 
          ->addAttributeToSelect('*') 
          ->addAttributeToFilter('customer_id', $customerId) 
          ->addAttributeToFilter('entity_id', $id) 
          ->load() 
          ->getFirstItem(); 

       $product->setName($this->getRequest()->getParam('name')); 
       $product->setSku($this->getRequest()->getParam('sku')); 
       $product->setDescription($this->getRequest()->getParam('description')); 
       $product->setShortDescription($this->getRequest()->getParam('short_description')); 
       $product->setPrice($this->getRequest()->getParam('price')); 
       $product->setWeight($this->getRequest()->getParam('weight')); 
       $product->setStock($this->getRequest()->getParam('stock')); 
       $product->save(); 

       if (isset($_FILES) && count($_FILES) > 0) { 
        foreach($_FILES as $image) { 
         if ($image['tmp_name'] != '') { 
          if (($error = $this->uploadImage($image, $id)) !== true) { 
           $errors[] = $error; 
          } 
         } 

        } 
       } 

       if (empty($errors)) { 
        $this->_getSession()->addSuccess($this->__('Your product was successfully updated')); 
       } else { 
        $this->_getSession()->addError('Product info was saved but was imposible to save the image'); 
        foreach ($errors as $message) { 
         $this->_getSession()->addError($message); 
        } 
       } 

       $this->_redirect('customer/products/'); 

      } 
     } 
} 

뿐만 아니라에 제출 양식을 업데이트 할 수있는 행동과 컨트롤러가 모든

먼저 컨트롤러)를 사용하여 업데이트되지 않은 것은을 업데이트 할 예정이다 제품 속성 및 이미지가 표시되지만 페이지가 제출시 다시로드되고 성공적으로 표시됩니다. 저장된 메시지가 있지만 속성이 업데이트되지 않고 해당 제품의 편집 양식 (각 제품에 대해 생성 된)으로 되돌아갑니다. 업데이트 양식의 값은 방금 제출 한 업데이트 값을 가지지 만 제품 속성은 카탈로그도 마찬가지입니다 (새 프로세스 작성시 입력 된 값과 동일하게 유지됩니다).

잘못된 작업을 계속 파악하거나 api 또는 direct SQL을 사용하여 작업을 완료하려면 이동하십시오.

답변

0

에서 찾을 수 있습니다 여전히 개선하고자 .. 는 사용 형태라고/frontendname/editApprovedPost/

public function editApprovedPostAction() { 

     $id = $this->getRequest()->getParam('productid'); 
     $idproduct = $this->getRequest()->getParam('product_id'); 

     if ($id !== false) { 

      list($data, $errors) = $this->validatePost(); 
      if (!empty($errors)) { 
       foreach ($errors as $message) { 
        $this->_getSession()->addError($message); 
       } 
       $this->_redirect('customer/products/edit/', array(
         'id' => $id 
        )); 
      } else { 

- 지금 후 (순서대로) 액션에 더 많은 PHP 코드를 추가} 다른 {...이

require_once 'app/Mage.php'; 

다음

$customerId = Mage::getSingleton('customer/session')->getCustomerId(); 

는 양식 제품을 사용 ...

Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID); 

다음 고객 ID를 얻을 ... 프론트 엔드 제품 업데이트에 대한 관리 저장소를 추가 이드는 업데이트 할 제품 ID를 얻으려고 ...

$product = Mage::getModel('catalog/product')->load("".$idproduct.""); 

다음 ...

$product->setName($this->getRequest()->getParam('name'));//use whatever attributes need (only text and text area tested so far) 

다음으로/업데이트 제품 데이터를 저장 .../업데이트 속성 값이 양식 입력 값으로부터 움켜 저장에서는 setName()를 사용

$product->save(); 

오류를 통해 실행 ...

if (empty($errors)) { 
        $this->_getSession()->addSuccess($this->__('Your product was successfully updated')); 

       } else { 

        $this->_getSession()->addError('Product info was saved but was imposible to save the image'); 
        foreach ($errors as $message) { 
         $this->_getSession()->addError($message); 
        } 
       } 

       $this->_redirect('customer/products/'); 

      } 
    } 
} 

다음 양식 설정 및 고객 그룹 로그인 고객과 프론트 엔드에서 고객 그룹 2 만 볼 수

  • 사용자 지정 양식을 제출

형태 (기본값 도매입니다) 아래 ....

죄송합니다 붙여 넣기 양식을 여기에 코드를 붙여 많은 작업을

Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID); 

일부 게시물에서 읽은 제품은 프론트 엔드에서 제품을 업데이트하는 것이므로 "관리"해야합니다.이 제품은 정상적으로 작동하는 것 같습니다. 전에 언급했듯이 스크립트는 업데이트되지 않았으며 업데이트 할 데이터가 실제 제품 (다른 모델 데이터를 사용하여 승인되고 생성 된 데이터) 일 때 다른 모델 데이터를 저장하려고했기 때문에 스크립트가 업데이트되지 않고 업데이트 중이었습니다

$product = Mage::getResourceModel('customerpartner/customerpartner_product_collection') 

을 사용하여 다른 사람의 의견이 빌드를 종료 할 시간을 생각했기 때문에이 사람을 도움이 희망을 여기까지 좋은 것입니다.

관련 문제