1

私はあちこちで調査を行ってきましたが、Magentoの開発に慣れていないため、このタスクを実行する方法に頭を悩ませています。

当店は、独自のシンプルな商品として設定されたメンバーシップを持っています。メンバーシップアイテムは$5でリストされています。問題は、このメンバーシップを追加できるのは、カートに別のアイテム(帽子)を追加した場合のみであるということです。

したがって、メンバーシップを購入するには、カートにx、y、またはzカテゴリの帽子が必要です。

これをコーディングするための最良のアプローチについて何か考えはありますか?簡単な設定で可能ですか、それともコアコードのいくつかを掘り下げる必要がありますか?どんな助けでも非常に役に立ちます-特にコード例、私が見るべき特定のファイル名/パス。

それが役に立ったら、私はMagentoEnterpriseVを使用しています。1.12.0.2

4

1 に答える 1

1

のオブザーバーを作成してadd_to_cart_before、ユーザーがカートに入れている商品を確認できます。

 <add_to_cart_before>
      <observers>
          <add_to_cart_before>
               <class>dispatcher/observer</class>
              <method>hookToAddToCartBefore</method>
          </add_to_cart_before>
      </observers>
 </add_to_cart_before>

オブザーバー内(オブザーバーの作成方法を参照)

$cartHelper = Mage::helper('checkout/cart');
$items = $cartHelper->getCart()->getItems();
$category_in_cart_ids = array();
foreach ($items as $item) {
    array_push($category_in_cart_ids, $item->getProduct()->getCategoryIds());  // append category array to category_in_cart_ids
}

if(specific item id){
   if(in_array('your category ids', $category_in_cart_ids)){
     // product specific category in cart
   }
   else{
     //dont add this product to cart/ remove
   }
}

http://inchoo.net/ecommerce/magento/dispatching-before-and-after-events-to-magento-core-actions/を参照してください

于 2013-01-03T21:01:11.650 に答える