문제

교차 판매 항목을 취급하는 답변을 신중하게 따랐습니다 ( 장바구니에서 크로스 셀 항목의 수를 늘리는 방법 ) 모든 것이 잘 작동하는 것처럼 보입니다 ...

Protected $ _maxitemcount= mage :: getStoreConfig ( 'mycompany_section / mycompany_group / mycompany_group');

은 오류를 생성합니다.

구문 분석 오류 : 구문 오류, 예기치 않은 '(', ','또는 ','또는 '', '또는'; '또는'; ','또는 ';'또는 ';'....

이 마젠타 / PHP 초보자에게 도움이되는 모든 도움이 크게 감사 할 것입니다 :)

마젠토 버전.1.9.2.1

편집 :

@simonthesorcerer 수정안으로 Crosssell.php를 사용하여 출력을 다음과 같이 사용합니다.

class Abc_Checkout_Block_Cart_Crosssell extends Mage_Catalog_Block_Product_Abstract
{
/**
 * Items quantity will be capped to this value
 *
 * @var int
 */

      protected $_maxItemCount;

      protected function _construct() { 
$this->__maxItemCount = Mage::getStoreConfig('abc_section/abc_group/abc_input');
return parent::_construct(); }

/**
 * Get crosssell items
 *
 * @return array
 */
public function getItems()
{
    $items = $this->getData('items');
    if (is_null($items)) {
        $items = array();
        $ninProductIds = $this->_getCartProductIds();
        if ($ninProductIds) {
            $lastAdded = (int) $this->_getLastAddedProductId();
            if ($lastAdded) {
                $collection = $this->_getCollection()
                    ->addProductFilter($lastAdded);
                if (!empty($ninProductIds)) {
                    $collection->addExcludeProductFilter($ninProductIds);
                }
                $collection->setPositionOrder()->load();

                foreach ($collection as $item) {
                    $ninProductIds[] = $item->getId();
                    $items[] = $item;
                }
            }

            if (count($items) < $this->_maxItemCount) {
                $filterProductIds = array_merge($this->_getCartProductIds(), $this->_getCartProductIdsRel());
                $collection = $this->_getCollection()
                    ->addProductFilter($filterProductIds)
                    ->addExcludeProductFilter($ninProductIds)
                    ->setPageSize($this->_maxItemCount-count($items))
                    ->setGroupBy()
                    ->setPositionOrder()
                    ->load();
                foreach ($collection as $item) {
                    $items[] = $item;
                }
            }

        }

        $this->setData('items', $items);
    }
    return $items;
}

/**
 * Count items
 *
 * @return int
 */
public function getItemCount()
{
    return count($this->getItems());
}

/**
 * Get ids of products that are in cart
 *
 * @return array
 */
protected function _getCartProductIds()
{
    $ids = $this->getData('_cart_product_ids');
    if (is_null($ids)) {
        $ids = array();
        foreach ($this->getQuote()->getAllItems() as $item) {
            if ($product = $item->getProduct()) {
                $ids[] = $product->getId();
            }
        }
        $this->setData('_cart_product_ids', $ids);
    }
    return $ids;
}

/**
 * Retrieve Array of product ids which have special relation with products in Cart
 * For example simple product as part of Grouped product
 *
 * @return array
 */
protected function _getCartProductIdsRel()
{
    $productIds = array();
    foreach ($this->getQuote()->getAllItems() as $quoteItem) {
        $productTypeOpt = $quoteItem->getOptionByCode('product_type');
        if ($productTypeOpt instanceof Mage_Sales_Model_Quote_Item_Option
            && $productTypeOpt->getValue() == Mage_Catalog_Model_Product_Type_Grouped::TYPE_CODE
            && $productTypeOpt->getProductId()
        ) {
            $productIds[] = $productTypeOpt->getProductId();
        }
    }

    return $productIds;
}

/**
 * Get last product ID that was added to cart and remove this information from session
 *
 * @return int
 */
protected function _getLastAddedProductId()
{
    return Mage::getSingleton('checkout/session')->getLastAddedProductId(true);
}

/**
 * Get quote instance
 *
 * @return Mage_Sales_Model_Quote
 */
public function getQuote()
{
    return Mage::getSingleton('checkout/session')->getQuote();
}

/**
 * Get crosssell products collection
 *
 * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Link_Product_Collection
 */
protected function _getCollection()
{
    $collection = Mage::getModel('catalog/product_link')->useCrossSellLinks()
        ->getProductCollection()
        ->setStoreId(Mage::app()->getStore()->getId())
        ->addStoreFilter()
        ->setPageSize($this->_maxItemCount);
    $this->_addProductAttributesAndPrices($collection);

    Mage::getSingleton('catalog/product_status')->addSaleableFilterToCollection($collection);
    Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($collection);
    Mage::getSingleton('cataloginventory/stock')->addInStockFilterToCollection($collection);

    return $collection;
}
}
.

도움이 되었습니까?

해결책

클래스 속성을 선언하지만이 작업을 수행 할 때 함수를 호출 할 수는 없습니다.

대신 다음과 같이 선언을 변경하십시오.

protected $_myPropertyName;
.

블록이 mage_core_block_abstract를 확장하도록 가정합니다.그런 다음 _Construct () 함수를 무시하고 다음과 같은 속성을 채워야합니다.

protected function _construct() { 
$this->_myPropertyName = Mage::getStoreConfig('configname');
return parent::_construct(); }
.

포맷을해서 죄송합니다. 모바일에 있습니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 magento.stackexchange
scroll top