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>
감사 의견에 대해 많이해야 내 구성의 크기는 구성 옵션을 가지고 있다는 것입니다 내가 그것을 선택하고 수량을 선택하고 장바구니에 추가를 누르면이 오류가 발생합니다. 구성 옵션을 확인한 후 제품을 검사하면 모든 것이 올바르게 보입니다. –
나는 모든 문제를 여기서 해결하고 phtml 파일의 모든 코드를 확인합니다. 업데이트와 내가 준 대답을 확인하십시오. –