2017-04-16 9 views
1

Magento 1.9 서버를 사용 중이며 제품이 켜져 있습니다. 단순한 제품을 장바구니에 추가하면 원활하고 잘 작동하지만 시도 할 때 구성 가능한 제품을이 메시지 리턴으로 추가하십시오.Magento 1.9.2에서 제품 옵션을 지정하십시오.

제품의 옵션을 지정하십시오.

이제 코드를 추적하여 작업 할 때까지 여기에 도달합니다. 제품을 추가하는 코드가 존재하는이 파일의

응용 프로그램/코드/코어/마법사/체크 아웃/컨트롤러/CartController

:

/** 
* Add product to shopping cart action 
* 
* @return Mage_Core_Controller_Varien_Action 
* @throws Exception 
*/ 
public function addAction() 
{ 
    if (!$this->_validateFormKey()) { 
     $this->_goBack(); 
     return; 
    } 
    $cart = $this->_getCart(); 
    $params = $this->getRequest()->getParams(); 

    try { 
     if (isset($params['qty'])) { 
      $filter = new Zend_Filter_LocalizedToNormalized(
       array('locale' => Mage::app()->getLocale()->getLocaleCode()) 
      ); 
      $params['qty'] = $filter->filter($params['qty']); 


     } 

     $product = $this->_initProduct(); 
     $related = $this->getRequest()->getParam('related_product'); 


     /** 
     * Check product availability 
     */ 
     if (!$product) { 
      $this->_goBack(); 
      return; 
     } 
     echo 'here'; 
     ?> 
      <pre> 
       <?php print_r($params); ?> 
      </pre> 
     <?php 
      exit; 
     ?> 
     <?php 

     $cart->addProduct($product, $params); 
     if (!empty($related)) { 
      $cart->addProductsByIds(explode(',', $related)); 
     } 

     $cart->save(); 

     $this->_getSession()->setCartWasUpdated(true); 

     /** 
     * @todo remove wishlist observer processAddToCart 
     */ 
     Mage::dispatchEvent('checkout_cart_add_product_complete', 
      array('product' => $product, 'request' => $this->getRequest(), 'response' => $this->getResponse()) 
     ); 

     if (!$this->_getSession()->getNoCartRedirect(true)) { 
      if (!$cart->getQuote()->getHasError()) { 
       $message = $this->__('%s was added to your shopping cart.', Mage::helper('core')->escapeHtml($product->getName())); 
       $this->_getSession()->addSuccess($message); 
      } 
      $this->_goBack(); 
     } 
    } catch (Mage_Core_Exception $e) { 
     if ($this->_getSession()->getUseNotice(true)) { 
      $this->_getSession()->addNotice(Mage::helper('core')->escapeHtml($e->getMessage())); 
     } else { 
      $messages = array_unique(explode("\n", $e->getMessage())); 
      foreach ($messages as $message) { 
       $this->_getSession()->addError(Mage::helper('core')->escapeHtml($message)); 
      } 
     } 

     $url = $this->_getSession()->getRedirectUrl(true); 
     if ($url) { 
      $this->getResponse()->setRedirect($url); 
     } else { 
      $this->_redirectReferer(Mage::helper('checkout/cart')->getCartUrl()); 
     } 
    } catch (Exception $e) { 
     $this->_getSession()->addException($e, $this->__('Cannot add the item to shopping cart.')); 
     Mage::logException($e); 
     $this->_goBack(); 
    } 
} 

이 코드에서 나는이 간단한 사용 내가있는 곳과 내가 가지고있는 데이터를 얻기위한 코드.

echo 'here'; 
?> 
    <pre> 
     <?php print_r($params); ?> 
    </pre> 
<?php 
    exit; 
?> 
<?php 

이 간단한 코드는 구성 가능한 제품에 대한 인수를 반환합니다. 모든 속성을 의미

Array 
(
    [uenc] => aHR0cDovL3N0YWdpbmcudmF0dHJlbmEuY29tL2luZGV4LnBocC9nZW5lcmFsLWplYW5zMTMuaHRtbA,, 
    [product] => 65 
    [form_key] => qIGyp6YDp7kQjibA 
    [related_product] => 
    [super_attribute] => Array 
     (
      [168] => M 
     ) 

    [qty] => 1 
) 

이 선택되어 있지만,이 간단한 코드 뒤에 내가 도달 할 때

$cart->addProduct($product, $params); 

는이 파일에 갈 생각

응용 프로그램/코드/코어/마법사 /Checkout/Model/Cart.php

On this function

/** 
* Add product to shopping cart (quote) 
* 
* @param int|Mage_Catalog_Model_Product $productInfo 
* @param mixed $requestInfo 
* @return Mage_Checkout_Model_Cart 
*/ 
public function addProduct($productInfo, $requestInfo=null) 
{ 
    $product = $this->_getProduct($productInfo); 
    $request = $this->_getProductRequest($requestInfo); 

    $productId = $product->getId(); 

    if ($product->getStockItem()) { 
     $minimumQty = $product->getStockItem()->getMinSaleQty(); 
     //If product was not found in cart and there is set minimal qty for it 
     if ($minimumQty && $minimumQty > 0 && $request->getQty() < $minimumQty 
      && !$this->getQuote()->hasProductId($productId) 
     ){ 
      $request->setQty($minimumQty); 
     } 
    } 

    if ($productId) { 
     try { 
      $result = $this->getQuote()->addProduct($product, $request); 
     } catch (Mage_Core_Exception $e) { 
      $this->getCheckoutSession()->setUseNotice(false); 
      $result = $e->getMessage(); 
     } 
     /** 
     * String we can get if prepare process has error 
     */ 
     if (is_string($result)) { 
      $redirectUrl = ($product->hasOptionsValidationFail()) 
       ? $product->getUrlModel()->getUrl(
        $product, 
        array('_query' => array('startcustomization' => 1)) 
       ) 
       : $product->getProductUrl(); 
      $this->getCheckoutSession()->setRedirectUrl($redirectUrl); 
      if ($this->getCheckoutSession()->getUseNotice() === null) { 
       $this->getCheckoutSession()->setUseNotice(true); 
      } 
      Mage::throwException($result); 
     } 
    } else { 
     Mage::throwException(Mage::helper('checkout')->__('The product does not exist.')); 
    } 

    Mage::dispatchEvent('checkout_cart_product_add_after', array('quote_item' => $result, 'product' => $product)); 
    $this->getCheckoutSession()->setLastAddedProductId($productId); 
    return $this; 
} 

하지만이 기능에 echo 무엇이든하려고 할 때, 그것은 표시하고이 메시지와 함께 구성 가능한 제품 페이지로 이동하지 않습니다

제품의 옵션 (들)을 지정하십시오.

UPDATE 1 :

$_helper = $this->helper('catalog/product'); 
$_product = $this->getProduct(); 
$_attributes = Mage::helper('core')->decorateArray($this->getAllowAttributes()); 
<?php if (count($_attributes) > 0):?> 
    <dl> 
    <?php foreach($_attributes as $_attribute):?> 
    <div class="row"> 
     <h2 class="gws_p_title" style="border-top: none;"><?php echo $this->__($_attribute->getLabel()) ?><em>*</em></h2> 
     <dd class="last"> 
      <div class="input-box"> 
       <select name="super_attribute[<?php echo $_attribute->getAttributeId() ?>]" id="attribute<?php echo $_attribute->getAttributeId() ?>" class="required-entry super-attribute-select js-example-basic-single"> 
        <option><?php echo $this->__('Choose an Option...') ?></option> 
        </select> 
       </div> 
     </dd> 
     </div> 
    <?php endforeach; ?> 
    </dl> 

답변

0

Magento를 처음 접한 이래로 이것은 나에게 많은 문제가되었으며 많은 시간을 보냈습니다.

파일의 앞에이 줄을 추가

응용 프로그램/디자인/프론트 엔드/yourtheme/기본/템플릿/카탈로그/제품 /보기/형/옵션/cofigurable.phtml

$attValConfig = $_product->getTypeInstance(true)->getConfigurableAttributesAsArray($_product); 

검색 후 모든 코드를 확인한 후에이 줄에서 오류를 발견했습니다.

<select name="super_attribute[<?php echo $_attribute->getAttributeId() ?>]" id="attribute<?php echo $_attribute->getAttributeId() ?>" class="required-entry super-attribute-select js-example-basic-single"> 
    <option><?php echo $this->__('Choose an Option...') ?></option> 
</select> 

매우 FINE 본

<select name="super_attribute[<?php echo $_attribute->getAttributeId() ?>]" id="attribute<?php echo $_attribute->getAttributeId() ?>" class="required-entry super-attribute-select js-example-basic-single"> 
<option><?php echo $this->__('Choose an Option...') ?></option> 
<?php 
foreach ($attValConfig as $values) { 
    foreach ($values['values'] as $value) { 
     ?> 
     <option value="<?php echo $value['value_index']; ?>"><?php echo $this->__($value['label']); ?></option> 
     <?php 

    } 
} 
?> 
</select> 

이제 모든 것을 WORK LIKE 여기 일이 무엇

1

제품의 옵션 (들)을 지정하십시오.

이 오류는 장바구니에 추가 할 때 필요하지 않지만 선택 가능한 제품 옵션 (예 : 색상 또는 크기)이 카트에 추가 될 때 선택되지 않은 경우에 발생합니다. 구성 가능한 옵션을 올바르게 작성했는지 확인하십시오.

magento 가져 오기 프로필에서 구성 가능한 옵션을 가져 오지 않았으므로 가져 오기로 제품을 만들었습니까? 당신은 admin-> catalog-> product에서 작동하지 않는 제품을 열어 이것을 확인해야합니다. 해당 제품에 구성 가능한 옵션이 있는지 확인해야합니다.

제품에 옵션이있는 경우 해당 옵션에 할당 된 제품을 사용 가능으로 설정하고 해당 상점에 재고가 있는지 확인해야합니다.

구성 가능한 제품에 대한 사용자 정의가없는 경우이 많은 작업으로 문제에 대한 해결책을 찾을 수 있습니다.

+0

감사 의견에 대해 많이해야 내 구성의 크기는 구성 옵션을 가지고 있다는 것입니다 내가 그것을 선택하고 수량을 선택하고 장바구니에 추가를 누르면이 오류가 발생합니다. 구성 옵션을 확인한 후 제품을 검사하면 모든 것이 올바르게 보입니다. –

+0

나는 모든 문제를 여기서 해결하고 phtml 파일의 모든 코드를 확인합니다. 업데이트와 내가 준 대답을 확인하십시오. –