3
votes

I'm working on a magento product page. On this page I show a block of HTML that references a separate product that can be added to cart. This is somewhat 'faking' a related item. On the product being viewed, I've added a new attributed called crosssell_item. This contains a value for my external product ID, not the magento ID.

How do I add an add to cart button that looks at this crosssell_item attribute value, finds the magento product that has the same value in it's SKU attribute, and then returns that items's magento ID so I can add it to cart?

Example:

  • SKU attribute value = 104704; has magento ID of 12345
  • Cross sell attribute value = 105846
  • SKU of cross sell value = 105846; has magento ID of 45678

I want to display an add to cart button so the fake cross sell item can be purchased from the product page of the SKU.

Thanks!

1

1 Answers

1
votes

Not sure if that what you meant and also not sure if code below will work (as I can't reproduce your conditions) but here we go:

$crossell_product_sku = $_product->getData('crosssell_item');
$model = Mage::getModel('catalog/product');
$crossell_product_id = $model->getIdBySku($crossell_product_sku);
$add_to_cart_url = Mage::getUrl('checkout/cart/add', array('product' => $crossell_product_id));