Exemple #1
0
 public function unassignProductAction()
 {
     $orderItemId = $this->getRequest()->getPost('order_item_id');
     /** @var $orderItem Ess_M2ePro_Model_Order_Item */
     $orderItem = Mage::getModel('M2ePro/Order_Item')->load($orderItemId);
     $this->getResponse()->setHeader('Content-type', 'application/json');
     if (!$orderItem->getId()) {
         $this->getResponse()->setBody(json_encode(array('error' => Mage::helper('M2ePro')->__('Please specify Required Options.'))));
         return;
     }
     $repairInput = $orderItem->getChildObject()->getRepairInput();
     if (!empty($repairInput)) {
         $hash = Ess_M2ePro_Model_Order_Repair::generateHash($repairInput);
         /** @var $connWrite Varien_Db_Adapter_Pdo_Mysql */
         $connWrite = Mage::getSingleton('core/resource')->getConnection('core_write');
         $connWrite->delete(Mage::getResourceModel('M2ePro/Order_Repair')->getMainTable(), array('product_id = ?' => $orderItem->getProductId(), 'hash = ?' => $hash));
     }
     $orderItem->unassignProduct();
     $orderItem->getOrder()->addSuccessLog('Item "%title%" was successfully Unmapped.', array('title' => $orderItem->getChildObject()->getTitle()));
     $this->getResponse()->setBody(json_encode(array('success' => Mage::helper('M2ePro')->__('Item was successfully Unmapped.'))));
 }
Exemple #2
0
 public function assignProduct($productId)
 {
     /** @var $magentoProduct Ess_M2ePro_Model_Magento_Product */
     $magentoProduct = Mage::getModel('M2ePro/Magento_Product');
     $magentoProduct->setProductId($productId);
     $associatedProducts = array();
     $associatedOptions = array();
     if (!$magentoProduct->exists()) {
         $this->setData('product_id', null);
         $this->setAssociatedProducts($associatedProducts);
         $this->setAssociatedOptions($associatedOptions);
         $this->save();
         throw new InvalidArgumentException('Product does not exist.');
     }
     $this->setData('product_id', (int) $productId);
     $repairInput = $this->getChildObject()->getRepairInput();
     if (!empty($repairInput)) {
         $orderRepairHash = Ess_M2ePro_Model_Order_Repair::generateHash($repairInput);
         /** @var $orderRepair Ess_M2ePro_Model_Order_Repair */
         $orderRepair = Mage::getModel('M2ePro/Order_Repair')->getCollection()->addFieldToFilter('type', Ess_M2ePro_Model_Order_Repair::TYPE_VARIATION)->addFieldToFilter('product_id', $productId)->addFieldToFilter('component', $this->getComponentMode())->addFieldToFilter('hash', $orderRepairHash)->getFirstItem();
         if ($orderRepair->getId()) {
             $productDetails = $orderRepair->getOutputData();
             $associatedOptions = $productDetails['associated_options'];
             $associatedProducts = $productDetails['associated_products'];
         }
     }
     $this->setAssociatedProducts($associatedProducts);
     $this->setAssociatedOptions($associatedOptions);
     $this->save();
 }